From bc9e0604f5ecbc7b771f25102067b52aa759a1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Delmaire=20Lo=C3=AFc?= Date: Wed, 22 Jan 2025 14:40:35 +0100 Subject: [PATCH] Make modalities form block generic Introduce a shared view _modalities_with_france_connect: API Impot Particulier make a symlink for his modalities block. Moreover rename the stimulus controller, to make it more generic. --- ...odalite_with_france_connect_controller.js} | 0 .../_modalities.html.erb | 1 + .../_modalities.html.erb | 1 + .../blocks/default/_modalities.html.erb | 37 +++------------- .../_modalities_with_france_connect.html.erb | 44 +++++++++++++++++++ .../new/api_impot_particulier.html.erb | 16 +++---- 6 files changed, 60 insertions(+), 39 deletions(-) rename app/javascript/controllers/{choose_modalite_impot_particulier_controller.js => choose_modalite_with_france_connect_controller.js} (100%) create mode 120000 app/views/authorization_request_forms/blocks/api_impot_particulier/_modalities.html.erb create mode 120000 app/views/authorization_request_forms/blocks/api_impot_particulier_sandbox/_modalities.html.erb create mode 100644 app/views/authorization_request_forms/blocks/default/_modalities_with_france_connect.html.erb diff --git a/app/javascript/controllers/choose_modalite_impot_particulier_controller.js b/app/javascript/controllers/choose_modalite_with_france_connect_controller.js similarity index 100% rename from app/javascript/controllers/choose_modalite_impot_particulier_controller.js rename to app/javascript/controllers/choose_modalite_with_france_connect_controller.js diff --git a/app/views/authorization_request_forms/blocks/api_impot_particulier/_modalities.html.erb b/app/views/authorization_request_forms/blocks/api_impot_particulier/_modalities.html.erb new file mode 120000 index 000000000..d3b13627e --- /dev/null +++ b/app/views/authorization_request_forms/blocks/api_impot_particulier/_modalities.html.erb @@ -0,0 +1 @@ +../default/_modalities_with_france_connect.html.erb \ No newline at end of file diff --git a/app/views/authorization_request_forms/blocks/api_impot_particulier_sandbox/_modalities.html.erb b/app/views/authorization_request_forms/blocks/api_impot_particulier_sandbox/_modalities.html.erb new file mode 120000 index 000000000..d3b13627e --- /dev/null +++ b/app/views/authorization_request_forms/blocks/api_impot_particulier_sandbox/_modalities.html.erb @@ -0,0 +1 @@ +../default/_modalities_with_france_connect.html.erb \ No newline at end of file diff --git a/app/views/authorization_request_forms/blocks/default/_modalities.html.erb b/app/views/authorization_request_forms/blocks/default/_modalities.html.erb index 970e644c9..2ed7da5b0 100644 --- a/app/views/authorization_request_forms/blocks/default/_modalities.html.erb +++ b/app/views/authorization_request_forms/blocks/default/_modalities.html.erb @@ -4,41 +4,16 @@ <%= f.info_for(:modalities) %> -
+
- <%= - f.dsfr_radio_buttons :modalities, - @authorization_request.available_modalities, + <%= + f.dsfr_radio_buttons :modalities, + @authorization_request.available_modalities, required: true, multiple: true, - radio_group_class: "fr-radio-rich", + radio_group_class: "fr-radio-rich", fieldset_element_class: "small", - checked: ->(value) { @authorization_request.modalities.include?(value) }, - input_options: { - "data-action": "click->choose-modalite-impot-particulier#trigger", - "data-choose-modalite-impot-particulier-target": "modality" - } + checked: ->(value) { @authorization_request.modalities.include?(value) } %>
- -
- <% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %> - - <% if france_connect_authorizations.empty? %> -
-

- <%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.title") %> -

-

- <%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.content") %> -

- <%= link_to t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.link"), new_authorization_request_form_path("france-connect"), class: "fr-link fr-btn--icon-right fr-icon-arrow-right-line" %> -
- - <% else %> - <% options = france_connect_authorizations.map{ |authorization| [authorization.name_for_select, authorization.id] } %> - <% selected_option = @authorization_request.france_connect_authorization_id || france_connect_authorizations.first.id %> - <%= f.dsfr_select :france_connect_authorization_id, options_for_select(options, selected_option), class: %w[fr-select], include_blank: "Sélectionner une option", required: true, input_options: { "data-choose-modalite-impot-particulier-target": "franceConnectSelector" } %> - <% end %> -
diff --git a/app/views/authorization_request_forms/blocks/default/_modalities_with_france_connect.html.erb b/app/views/authorization_request_forms/blocks/default/_modalities_with_france_connect.html.erb new file mode 100644 index 000000000..277ce7b03 --- /dev/null +++ b/app/views/authorization_request_forms/blocks/default/_modalities_with_france_connect.html.erb @@ -0,0 +1,44 @@ +<% if @authorization_request.display_prefilled_banner_for_each_block? && @authorization_request.prefilled_data?(%i[modalities france_connect_authorization_id]) %> + <%= render partial: "authorization_request_forms/shared/prefilled_banner" %> +<% end %> + +<%= f.info_for(:modalities) %> + +
+
+ <%= + f.dsfr_radio_buttons :modalities, + @authorization_request.available_modalities, + required: true, + multiple: true, + radio_group_class: "fr-radio-rich", + fieldset_element_class: "small", + checked: ->(value) { @authorization_request.modalities.include?(value) }, + input_options: { + "data-action": "click->choose-modalite-with-france-connect#trigger", + "data-choose-modalite-with-france-connect-target": "modality" + } + %> +
+ +
+ <% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %> + + <% if france_connect_authorizations.empty? %> +
+

+ <%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.title") %> +

+

+ <%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.content") %> +

+ <%= link_to t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.link"), new_authorization_request_form_path("france-connect"), class: "fr-link fr-btn--icon-right fr-icon-arrow-right-line" %> +
+ + <% else %> + <% options = france_connect_authorizations.map{ |authorization| [authorization.name_for_select, authorization.id] } %> + <% selected_option = @authorization_request.france_connect_authorization_id || france_connect_authorizations.first.id %> + <%= f.dsfr_select :france_connect_authorization_id, options_for_select(options, selected_option), class: %w[fr-select], include_blank: "Sélectionner une option", required: true, input_options: { "data-choose-modalite-with-france-connect-target": "franceConnectSelector" } %> + <% end %> +
+
diff --git a/app/views/authorization_requests/new/api_impot_particulier.html.erb b/app/views/authorization_requests/new/api_impot_particulier.html.erb index ebfa20251..20176d276 100644 --- a/app/views/authorization_requests/new/api_impot_particulier.html.erb +++ b/app/views/authorization_requests/new/api_impot_particulier.html.erb @@ -10,7 +10,7 @@

<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.title") %>

-
+

<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.subtitle").html_safe %>

@@ -22,8 +22,8 @@ type="radio" id="modalite_<%= value %>" name="modalite" - data-action="click->choose-modalite-impot-particulier#trigger" - data-choose-modalite-impot-particulier-target="modality" + data-action="click->choose-modalite-with-france-connect#trigger" + data-choose-modalite-with-france-connect-target="modality" >
-
+
<% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %> <% if france_connect_authorizations.empty? %> @@ -56,7 +56,7 @@ - <% options = france_connect_authorizations.map{ |authorization| [authorization.name_for_select, authorization.id] } %> <%= options_for_select options, selected: options.first[1] %> @@ -64,7 +64,7 @@ <% end %>
-
+

<%= t("authorization_requests.new.api_impot_particulier.editor_with_sandbox.title") %>

@@ -121,7 +121,7 @@ <%= render partial: "authorization_request_forms/authorization_request_form_card", locals: { authorization_request_form:, - additional_link_attributes: { "data-choose-modalite-impot-particulier-target": "links" } + additional_link_attributes: { "data-choose-modalite-with-france-connect-target": "links" } } %>
<% end %> @@ -158,7 +158,7 @@ <%= render partial: "authorization_request_forms/authorization_request_form_card", locals: { authorization_request_form:, - additional_link_attributes: { "data-choose-modalite-impot-particulier-target": "links" } + additional_link_attributes: { "data-choose-modalite-with-france-connect-target": "links" } } %>
<% end %>