Skip to content

Commit

Permalink
Make modalities form block generic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
skelz0r committed Jan 22, 2025
1 parent dc0a123 commit bc9e060
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,16 @@

<%= f.info_for(:modalities) %>

<div data-controller="choose-modalite-impot-particulier">
<div>
<div class="fr-col-lg-9">
<%=
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) }
%>
</div>

<div class="fr-col-lg-9 fr-mb-5w <%= 'fr-hidden' unless @authorization_request.with_france_connect? %>" data-choose-modalite-impot-particulier-target="franceConnectContainer">
<% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %>

<% if france_connect_authorizations.empty? %>
<div class="fr-callout red-callout">
<h3 class="fr-callout__title">
<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.title") %>
</h3>
<p class="fr-callout__text fr-my-3w">
<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.content") %>
</p>
<%= 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" %>
</div>

<% 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 %>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -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) %>

<div data-controller="choose-modalite-with-france-connect">
<div class="fr-col-lg-9">
<%=
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"
}
%>
</div>

<div class="fr-col-lg-9 fr-mb-5w <%= 'fr-hidden' unless @authorization_request.with_france_connect? %>" data-choose-modalite-with-france-connect-target="franceConnectContainer">
<% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %>

<% if france_connect_authorizations.empty? %>
<div class="fr-callout red-callout">
<h3 class="fr-callout__title">
<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.title") %>
</h3>
<p class="fr-callout__text fr-my-3w">
<%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.callout.content") %>
</p>
<%= 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" %>
</div>

<% 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 %>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<h2 class="fr-h4"><%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.title") %></h2>

<div data-controller="choose-modalite-impot-particulier">
<div data-controller="choose-modalite-with-france-connect">
<div class="fr-col-lg-9 fr-mb-5w">
<p class=""><%= t("authorization_request_forms.api_impot_particulier_sandbox.modalities.subtitle").html_safe %></p>

Expand All @@ -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"
>
<label class="fr-label" for="modalite_<%= value %>">
<%= options[:label] %>
Expand All @@ -37,7 +37,7 @@
</fieldset>
</div>

<div class="fr-col-lg-9 fr-mb-5w fr-hidden" data-choose-modalite-impot-particulier-target="franceConnectContainer">
<div class="fr-col-lg-9 fr-mb-5w fr-hidden" data-choose-modalite-with-france-connect-target="franceConnectContainer">
<% france_connect_authorizations = current_organization.valid_authorizations_of(AuthorizationRequest::FranceConnect).map(&:decorate) %>

<% if france_connect_authorizations.empty? %>
Expand All @@ -56,15 +56,15 @@
<label class="fr-h4 fr-label" for="france_connect_authorization_id">
<%= t("authorization_request_forms.api_impot_particulier_sandbox.france_connect_authorization_id.label") %>
</label>
<select class="fr-select" id="france_connect_authorization_id" name="france_connect_authorization_id" data-choose-modalite-impot-particulier-target="franceConnectSelector" data-action="click->choose-modalite-impot-particulier#trigger">
<select class="fr-select" id="france_connect_authorization_id" name="france_connect_authorization_id" data-choose-modalite-with-france-connect-target="franceConnectSelector" data-action="click->choose-modalite-with-france-connect#trigger">
<% options = france_connect_authorizations.map{ |authorization| [authorization.name_for_select, authorization.id] } %>
<%= options_for_select options, selected: options.first[1] %>
</select>
</div>
<% end %>
</div>

<div data-controller="choose-stage" data-choose-modalite-impot-particulier-target="nextStage" class="fr-hidden">
<div data-controller="choose-stage" data-choose-modalite-with-france-connect-target="nextStage" class="fr-hidden">
<h2 class="fr-h4"><%= t("authorization_requests.new.api_impot_particulier.editor_with_sandbox.title") %></h2>

<div class="fr-col-lg-9">
Expand Down Expand Up @@ -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" }
} %>
</div>
<% end %>
Expand Down Expand Up @@ -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" }
} %>
</div>
<% end %>
Expand Down

0 comments on commit bc9e060

Please sign in to comment.