refactor: account dropdown as component
This commit is contained in:
parent
c65fcf0a29
commit
e459f68ddb
12 changed files with 142 additions and 59 deletions
24
app/components/account_dropdown_component.rb
Normal file
24
app/components/account_dropdown_component.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AccountDropdownComponent < ViewComponent::Base
|
||||
attr_reader :dossier
|
||||
attr_reader :nav_bar_profile
|
||||
|
||||
delegate :current_email, :color_by_role, :multiple_devise_profile_connect?,
|
||||
:user_signed_in?, :instructeur_signed_in?, :expert_signed_in?,
|
||||
:administrateur_signed_in?, :gestionnaire_signed_in?, :super_admin_signed_in?,
|
||||
to: :helpers
|
||||
|
||||
def initialize(dossier:, nav_bar_profile:)
|
||||
@dossier = dossier
|
||||
@nav_bar_profile = nav_bar_profile
|
||||
end
|
||||
|
||||
def france_connected?
|
||||
dossier&.france_connected_with_one_identity?
|
||||
end
|
||||
|
||||
def show_profile_badge?
|
||||
nav_bar_profile != :guest
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
en:
|
||||
go_superadmin: 'Switch to super-admin'
|
||||
go_user: 'Switch to user'
|
||||
go_instructor: 'Switch to instructor'
|
||||
go_expert: 'Switch to expert'
|
||||
go_admin: 'Switch to administrator'
|
||||
go_gestionnaire: 'Switch to admins group manager'
|
||||
profile: 'See my profile'
|
||||
logout: 'Log out'
|
||||
my_account: 'My profile'
|
||||
connected_as: 'connected as %{profile}'
|
|
@ -0,0 +1,11 @@
|
|||
fr:
|
||||
go_superadmin: 'Passer en super-admin'
|
||||
go_user: 'Passer en usager'
|
||||
go_instructor: 'Passer en instructeur'
|
||||
go_expert: 'Passer en expert'
|
||||
go_admin: 'Passer en administrateur'
|
||||
go_gestionnaire: 'Passer en gestionnaire'
|
||||
profile: 'Voir mon profil'
|
||||
logout: 'Se déconnecter'
|
||||
my_account: 'Mon profil'
|
||||
connected_as: 'connecté en tant qu’%{profile}'
|
|
@ -0,0 +1,58 @@
|
|||
%nav.fr-translate.fr-nav{ role: "navigation", "aria-label" => t('.my_account') }
|
||||
.fr-nav__item
|
||||
%button.account-btn.fr-translate__btn.fr-btn{ "aria-controls" => "account", "aria-expanded" => "false", title: t('.my_account') }
|
||||
%span.fr-mr-1w= current_email
|
||||
- if france_connected?
|
||||
%span via FranceConnect
|
||||
|
||||
- if show_profile_badge?
|
||||
%span{ class: "fr-badge fr-badge--sm #{color_by_role(nav_bar_profile)}" }
|
||||
= t(nav_bar_profile, scope: :layouts)
|
||||
|
||||
#account.fr-collapse.fr-menu
|
||||
%ul.fr-menu__list.max-content
|
||||
- if multiple_devise_profile_connect?
|
||||
%li
|
||||
= link_to "#", class: "fr-nav__link", "aria-current" => "true" do
|
||||
= t('.connected_as', profile: t(nav_bar_profile, scope: :layouts))
|
||||
|
||||
- if user_signed_in? && nav_bar_profile != :user
|
||||
%li
|
||||
= link_to dossiers_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('.go_user')
|
||||
- if instructeur_signed_in? && nav_bar_profile != :instructeur
|
||||
%li
|
||||
= link_to instructeur_procedures_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('.go_instructor')
|
||||
- if expert_signed_in? && nav_bar_profile != :expert
|
||||
%li
|
||||
= link_to expert_all_avis_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('.go_expert')
|
||||
- if administrateur_signed_in? && nav_bar_profile != :administrateur
|
||||
%li
|
||||
= link_to admin_procedures_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('.go_admin')
|
||||
- if gestionnaire_signed_in? && nav_bar_profile != :gestionnaire
|
||||
%li
|
||||
= link_to gestionnaire_groupe_gestionnaires_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-refresh-line.fr-icon--sm
|
||||
= t('.go_gestionnaire')
|
||||
|
||||
- if super_admin_signed_in? && nav_bar_profile != :superadmin
|
||||
%li
|
||||
= link_to manager_root_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-shield-line.fr-icon--sm
|
||||
= t('.go_superadmin')
|
||||
|
||||
%li
|
||||
= link_to profil_path, class: "fr-nav__link" do
|
||||
%span.fr-icon-user-line.fr-icon--sm
|
||||
= t('.profile')
|
||||
%li
|
||||
= link_to destroy_user_session_path, method: :delete, class: "fr-nav__link" do
|
||||
%span.fr-icon-logout-box-r-line.fr-icon--sm
|
||||
= t('.logout')
|
Loading…
Add table
Add a link
Reference in a new issue