diff --git a/app/components/autosave_notice_component.rb b/app/components/autosave_notice_component.rb new file mode 100644 index 000000000..7d78c119d --- /dev/null +++ b/app/components/autosave_notice_component.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +class AutosaveNoticeComponent < ApplicationComponent + attr_reader :label_scope + + def initialize(success:, label_scope:) + @success = success + @label_scope = label_scope + end + + def success? = @success + + def label + success? ? t(".#{label_scope}.saved") : t(".#{label_scope}.error") + end +end diff --git a/app/components/autosave_notice_component/autosave_notice_component.en.yml b/app/components/autosave_notice_component/autosave_notice_component.en.yml new file mode 100644 index 000000000..ec721bd1a --- /dev/null +++ b/app/components/autosave_notice_component/autosave_notice_component.en.yml @@ -0,0 +1,8 @@ +--- +en: + form: + saved: 'Form saved' + error: 'Form in error' + attestation: + saved: 'Attestation saved' + error: 'Attestation in error' diff --git a/app/components/autosave_notice_component/autosave_notice_component.fr.yml b/app/components/autosave_notice_component/autosave_notice_component.fr.yml new file mode 100644 index 000000000..9f56b2f82 --- /dev/null +++ b/app/components/autosave_notice_component/autosave_notice_component.fr.yml @@ -0,0 +1,8 @@ +--- +fr: + form: + saved: 'Formulaire enregistré' + error: 'Formulaire en erreur' + attestation: + saved: 'Attestation enregistrée' + error: 'Attestation en erreur' diff --git a/app/components/autosave_notice_component/autosave_notice_component.html.haml b/app/components/autosave_notice_component/autosave_notice_component.html.haml new file mode 100644 index 000000000..2c59662fa --- /dev/null +++ b/app/components/autosave_notice_component/autosave_notice_component.html.haml @@ -0,0 +1,2 @@ +#autosave-notice.fr-badge.fr-badge--sm{ class: class_names("fr-badge--success" => success?, "fr-badge--error" => !success?) } + = label diff --git a/app/views/administrateurs/_autosave_notice.html.haml b/app/views/administrateurs/_autosave_notice.html.haml deleted file mode 100644 index 989e3970d..000000000 --- a/app/views/administrateurs/_autosave_notice.html.haml +++ /dev/null @@ -1,2 +0,0 @@ -- success = local_assigns.fetch(:success, true) -#autosave-notice.fr-badge.fr-badge--sm{ class: class_names("fr-badge--success" => success, "fr-badge--error" => !success) }= success ? t(".form_saved") : t(".form_error") diff --git a/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml b/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml index 4941218fb..ce033ac46 100644 --- a/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml +++ b/app/views/administrateurs/attestation_template_v2s/update.turbo_stream.haml @@ -2,7 +2,7 @@ = turbo_stream.update "sticky-header", render(partial: "sticky_header") = turbo_stream.show 'autosave-notice' -= turbo_stream.replace 'autosave-notice', render(partial: 'administrateurs/autosave_notice', locals: { success: !@attestation_template.changed? }) += turbo_stream.replace('autosave-notice', render(AutosaveNoticeComponent.new(success: !@attestation_template.changed?, label_scope: :attestation))) = turbo_stream.hide 'autosave-notice', delay: 15000 - if @attestation_template.logo_blob&.previously_new_record? diff --git a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml index ad121dedd..7d66a8851 100644 --- a/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml +++ b/app/views/administrateurs/types_de_champ/_insert.turbo_stream.haml @@ -18,7 +18,7 @@ - unless flash.alert = turbo_stream.show 'autosave-notice' - = turbo_stream.replace 'autosave-notice', render(partial: 'administrateurs/autosave_notice') + = turbo_stream.replace 'autosave-notice', render(AutosaveNoticeComponent.new(success: true, label_scope: :form)) = turbo_stream.hide 'autosave-notice', delay: 30000 - if @destroyed.present? diff --git a/config/locales/views/administrateurs/procedures/en.yml b/config/locales/views/administrateurs/procedures/en.yml index db0bf6b5a..bcbf8daac 100644 --- a/config/locales/views/administrateurs/procedures/en.yml +++ b/config/locales/views/administrateurs/procedures/en.yml @@ -71,6 +71,3 @@ en: path_not_available: owner: This URL is identical to another of your published procedures. If you publish this procedure, the old one will be unpublished and will no longer be accessible to the public. not_owner: This URL is identical to another procedure, you must modify it. - autosave_notice: - form_saved: "Form saved" - form_error: "Form in error" diff --git a/config/locales/views/administrateurs/procedures/fr.yml b/config/locales/views/administrateurs/procedures/fr.yml index 0fcc5ad96..90fb3f4f7 100644 --- a/config/locales/views/administrateurs/procedures/fr.yml +++ b/config/locales/views/administrateurs/procedures/fr.yml @@ -71,6 +71,3 @@ fr: path_not_available: owner: Cette url est identique à celle d’une autre de vos démarches publiées. Si vous publiez cette démarche, l’ancienne sera dépubliée et ne sera plus accessible au public. not_owner: Cette url est identique à celle d’une autre démarche, vous devez la modifier afin de pouvoir publier votre démarche. - autosave_notice: - form_saved: "Formulaire enregistré" - form_error: "Formulaire en erreur" diff --git a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb index 2d081212b..0b2edcca3 100644 --- a/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb +++ b/spec/controllers/administrateurs/attestation_template_v2s_controller_spec.rb @@ -192,7 +192,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do expect(attestation_template.activated).to eq(true) expect(attestation_template.tiptap_body).to eq(update_params[:tiptap_body]) - expect(response.body).to include("Formulaire enregistré") + expect(response.body).to include("Attestation enregistrée") end context "with files" do @@ -234,7 +234,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do expect(attestation_template.activated).to eq(true) expect(attestation_template.tiptap_body).to eq(update_params[:tiptap_body]) - expect(response.body).to include("Formulaire enregistré") + expect(response.body).to include("Attestation enregistrée") expect(response.body).to include("Publier") end @@ -258,7 +258,7 @@ describe Administrateurs::AttestationTemplateV2sController, type: :controller do it "renders error" do subject - expect(response.body).to include("Formulaire en erreur") + expect(response.body).to include("Attestation en erreur") expect(response.body).to include('Supprimer la balise') end end diff --git a/spec/system/administrateurs/procedure_attestation_template_spec.rb b/spec/system/administrateurs/procedure_attestation_template_spec.rb index 2834e9900..2eac577b7 100644 --- a/spec/system/administrateurs/procedure_attestation_template_spec.rb +++ b/spec/system/administrateurs/procedure_attestation_template_spec.rb @@ -106,9 +106,9 @@ describe 'As an administrateur, I want to manage the procedure’s attestation', attestation = procedure.reload.attestation_templates.v2.draft.first attestation.present? } + expect(page).to have_content("Attestation enregistrée") expect(attestation.label_logo).to eq("System Test") expect(attestation.activated?).to be_truthy - expect(page).to have_content("Formulaire enregistré") click_on "date de décision" @@ -172,14 +172,14 @@ describe 'As an administrateur, I want to manage the procedure’s attestation', click_on "date de décision" - expect(page).to have_content("Formulaire en erreur") + expect(page).to have_content("Attestation en erreur") expect(page).to have_content("Le champ « Contenu de l’attestation » contient la balise \"age\"") page.execute_script("document.getElementById('attestation_template_tiptap_body').type = 'text'") fill_in "attestation_template[tiptap_body]", with: AttestationTemplate::TIPTAP_BODY_DEFAULT.to_json - expect(page).to have_content("Formulaire enregistré") - expect(page).not_to have_content("Formulaire en erreur") + expect(page).to have_content("Attestation enregistrée") + expect(page).not_to have_content("Attestation en erreur") expect(page).not_to have_content("Le champ « Contenu de l’attestation » contient la balise \"age\"") end end