diff --git a/app/controllers/instructeurs/contact_informations_controller.rb b/app/controllers/instructeurs/contact_informations_controller.rb index 797627894..5dbe97892 100644 --- a/app/controllers/instructeurs/contact_informations_controller.rb +++ b/app/controllers/instructeurs/contact_informations_controller.rb @@ -16,6 +16,22 @@ module Instructeurs end end + def edit + assign_procedure_and_groupe_instructeur + @contact_information = @groupe_instructeur.contact_information + end + + def update + assign_procedure_and_groupe_instructeur + @contact_information = @groupe_instructeur.contact_information + if @contact_information.update(contact_information_params) + redirect_to instructeur_groupe_path(@groupe_instructeur, procedure_id: @procedure.id), notice: "Les informations de contact ont bien été modifiées" + else + flash[:alert] = @contact_information.errors.full_messages + render :edit + end + end + private def assign_procedure_and_groupe_instructeur diff --git a/app/views/instructeurs/contact_informations/edit.html.haml b/app/views/instructeurs/contact_informations/edit.html.haml new file mode 100644 index 000000000..607acfa12 --- /dev/null +++ b/app/views/instructeurs/contact_informations/edit.html.haml @@ -0,0 +1,10 @@ += render partial: 'administrateurs/breadcrumbs', + locals: { steps: [[@procedure.libelle.truncate_words(10), instructeur_procedure_path(@procedure)], + ['Groupes d’instructeurs', instructeur_groupes_path(@procedure)], + [@groupe_instructeur.label, instructeur_groupe_path(@groupe_instructeur, procedure_id: @procedure.id) ], + ['Service']]} +.container + %h1 Modifier les informations de contact + + = render partial: 'form', + locals: { contact_information: @contact_information, procedure_id: @procedure.id } diff --git a/app/views/instructeurs/groupe_instructeurs/show.html.haml b/app/views/instructeurs/groupe_instructeurs/show.html.haml index dd6ec4118..1cabdabf3 100644 --- a/app/views/instructeurs/groupe_instructeurs/show.html.haml +++ b/app/views/instructeurs/groupe_instructeurs/show.html.haml @@ -50,7 +50,18 @@ = paginate @instructeurs, views_prefix: 'shared' .card.mt-2 .card-title Informations de contact - - if @groupe_instructeur.contact_information.nil? + - service = @groupe_instructeur.contact_information + - if service.nil? = "Le groupe #{@groupe_instructeur.label} n'a pas d'informations de contact. Les informations de contact affichées à l'usager seront celles du service de la procédure" %p.mt-3 = link_to "+ Ajouter des informations de contact", new_instructeur_groupe_contact_information_path(procedure_id: @procedure.id, groupe_id: @groupe_instructeur.id), class: "fr-btn" + - else + %p.mt-3 + = link_to "Modifier les informations de contact", edit_instructeur_groupe_contact_information_path(procedure_id: @procedure.id, groupe_id: @groupe_instructeur.id), class: "fr-btn" + %p.mt-3= service.nom + = render SimpleFormatComponent.new(service.adresse, class_names_map: {paragraph: 'fr-footer__content-desc'}) + = service.email + - if service.telephone.present? + %p= service.telephone + - if service.horaires.present? + %p= service.horaires diff --git a/spec/controllers/instructeurs/contact_informations_controller_spec.rb b/spec/controllers/instructeurs/contact_informations_controller_spec.rb index 986bcc046..14e5ec394 100644 --- a/spec/controllers/instructeurs/contact_informations_controller_spec.rb +++ b/spec/controllers/instructeurs/contact_informations_controller_spec.rb @@ -56,4 +56,39 @@ describe Instructeurs::ContactInformationsController, type: :controller do it { expect(assigns(:contact_information).nom).to eq('super service') } end end + + describe '#update' do + let(:contact_information) { create(:contact_information, groupe_instructeur: gi) } + let(:contact_information_params) { + { + nom: 'nom' + } + } + let(:params) { + { + id: contact_information.id, + contact_information: contact_information_params, + procedure_id: procedure.id, + groupe_id: gi.id + } + } + + before do + patch :update, params: params + end + + context 'when updating a contact_information' do + it { expect(flash.alert).to be_nil } + it { expect(flash.notice).to eq('Les informations de contact ont bien été modifiées') } + it { expect(ContactInformation.last.nom).to eq('nom') } + it { expect(response).to redirect_to(instructeur_groupe_path(gi, procedure_id: procedure.id)) } + end + + context 'when updating a contact_information with invalid data' do + let(:contact_information_params) { { nom: '' } } + + it { expect(flash.alert).not_to be_nil } + it { expect(response).to render_template(:edit) } + end + end end diff --git a/spec/factories/contact_information.rb b/spec/factories/contact_information.rb new file mode 100644 index 000000000..7b89daca8 --- /dev/null +++ b/spec/factories/contact_information.rb @@ -0,0 +1,11 @@ +FactoryBot.define do + factory :contact_information do + sequence(:nom) { |n| "Service #{n}" } + email { 'email@toto.com' } + telephone { '1234' } + horaires { 'de 9 h à 18 h' } + adresse { 'adresse' } + + association :groupe_instructeur + end +end