refactor(procedure_adminis): extract component
This commit is contained in:
parent
30b53ec927
commit
924d2ae15d
2 changed files with 47 additions and 0 deletions
|
@ -0,0 +1,42 @@
|
|||
class Procedure::ProcedureAdministrateurs::AdministrateurComponent < ApplicationComponent
|
||||
include ApplicationHelper
|
||||
|
||||
def initialize(procedure:, administrateur:)
|
||||
@procedure = procedure
|
||||
@administrateur = administrateur
|
||||
end
|
||||
|
||||
def email
|
||||
if @administrateur == current_administrateur
|
||||
"#{@administrateur.email} (C’est vous !)"
|
||||
else
|
||||
@administrateur.email
|
||||
end
|
||||
end
|
||||
|
||||
def created_at
|
||||
try_format_datetime(@administrateur.created_at)
|
||||
end
|
||||
|
||||
def registration_state
|
||||
@administrateur.registration_state
|
||||
end
|
||||
|
||||
def remove_button
|
||||
if is_there_at_least_another_active_admin?
|
||||
button_to 'Retirer',
|
||||
admin_procedure_administrateur_path(@procedure, @administrateur),
|
||||
method: :delete,
|
||||
class: 'button',
|
||||
form: { data: { turbo: true, turbo_confirm: "Retirer « #{@administrateur.email} » des administrateurs de « #{@procedure.libelle} » ?" } }
|
||||
end
|
||||
end
|
||||
|
||||
def is_there_at_least_another_active_admin?
|
||||
if @administrateur.active?
|
||||
@procedure.administrateurs.count(&:active?) > 1
|
||||
else
|
||||
@procedure.administrateurs.count(&:active?) >= 1
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
%tr{ id: dom_id(@administrateur) }
|
||||
%td= email
|
||||
%td= created_at
|
||||
%td= registration_state
|
||||
%td= remove_button
|
Loading…
Reference in a new issue