demarches-normaliennes/app/components/procedure/procedure_administrateurs/administrateur_component.rb
2023-12-04 14:07:33 +01:00

42 lines
1.1 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class Procedure::ProcedureAdministrateurs::AdministrateurComponent < ApplicationComponent
include ApplicationHelper
def initialize(procedure:, administrateur:)
@procedure = procedure
@administrateur = administrateur
end
def email
if @administrateur == current_administrateur
"#{@administrateur.email} (Cest 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: 'fr-btn fr-btn--tertiary fr-btn--sm',
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