From 9d7017c7698247131b4745c334f2f8a4d6786a57 Mon Sep 17 00:00:00 2001 From: Daniela Baron Date: Sun, 22 Sep 2024 08:10:11 -0400 Subject: [PATCH] [#4504] implement logic to determine next open partial based on currently submitted partial --- .../partners/profiles_controller.rb | 18 +++++++++++++++--- .../step/_agency_information_form.html.erb | 4 +--- .../step/_media_information_form.html.erb | 2 +- .../step/_partner_settings_form.html.erb | 1 + .../_program_delivery_address_form.html.erb | 2 +- app/views/partners/profiles/step/edit.html.erb | 6 +----- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/controllers/partners/profiles_controller.rb b/app/controllers/partners/profiles_controller.rb index 213c6238d2..d1376bf559 100644 --- a/app/controllers/partners/profiles_controller.rb +++ b/app/controllers/partners/profiles_controller.rb @@ -41,8 +41,8 @@ def update # Make use of partner.partials_to_show for dynamic sections # | Partial | Converted to Step | Type | Default | Next | # | ------------------------------- | ----------------- | ------- | --------- | ------------------------------- | - # | agency_information_form | true | static | expanded | program_delivery_address_form | - # | program_delivery_address_form | true | static | collapsed | media_information | + # | agency_information | true | static | expanded | program_delivery_address | + # | program_delivery_address | true | static | collapsed | media_information | # | media_information | true | dynamic | collapsed | agency_stability | # | agency_stability | true | dynamic | collapsed | organizational_capacity | # | organizational_capacity | true | dynamic | collapsed | sources_of_funding | @@ -59,7 +59,9 @@ def next_step(submitted_partial) when "agency_information" "program_delivery_address" when "program_delivery_address" - "media_information" + current_partner.partials_to_show.first + when current_partner.partials_to_show.include?(submitted_partial) + next_partner_partial(submitted_partial) when "partner_settings" "NA" else @@ -67,6 +69,16 @@ def next_step(submitted_partial) end end + # TODO: 4504 move this to somewhere easier to test like a service + def next_partner_partial(submitted_partial) + index = current_partner.partials_to_show.index(submitted_partial) + if index + current_partner.partials_to_show[index + 1] + else + "agency_information" + end + end + def partner_params params.require(:partner).permit(:name) end diff --git a/app/views/partners/profiles/step/_agency_information_form.html.erb b/app/views/partners/profiles/step/_agency_information_form.html.erb index a24da4a4ca..7c66619e34 100644 --- a/app/views/partners/profiles/step/_agency_information_form.html.erb +++ b/app/views/partners/profiles/step/_agency_information_form.html.erb @@ -51,10 +51,8 @@ <% end %> - <%# FIXME: 4504 need separate actions for these %> - <%# TODO: 4504 hidden field may not be the best way to populate open_section %> + <%# FIXME: 4504 Implement Submit for Approval, that's different logic than Save and Next %>
- <%= hidden_field_tag :open_section, 'program_delivery_address' %> <%= f.button :submit, 'Save and Next', class: 'btn btn-primary mr-2' %> <%= f.button :submit, 'Submit for Approval', class: 'btn btn-success' %>
diff --git a/app/views/partners/profiles/step/_media_information_form.html.erb b/app/views/partners/profiles/step/_media_information_form.html.erb index 8981693aff..fe030d1824 100644 --- a/app/views/partners/profiles/step/_media_information_form.html.erb +++ b/app/views/partners/profiles/step/_media_information_form.html.erb @@ -1,4 +1,4 @@ -<%= simple_form_for partner, url: partners_profile_path do |f| %> +<%= simple_form_for partner, url: partners_profile_path(submitted_partial: "media_information") do |f| %> <%= f.fields_for :profile, profile do |pf| %>
<%= pf.input :website, label: "Website", class: "form-control" %> diff --git a/app/views/partners/profiles/step/_partner_settings_form.html.erb b/app/views/partners/profiles/step/_partner_settings_form.html.erb index 49d21e1613..dc3712ec81 100644 --- a/app/views/partners/profiles/step/_partner_settings_form.html.erb +++ b/app/views/partners/profiles/step/_partner_settings_form.html.erb @@ -24,6 +24,7 @@ <% end %> + <%# TODO: 4504 remove Save and Next button because this is the last section %>
<%= f.button :submit, 'Save and Next', class: 'btn btn-primary mr-2' %> <%= f.button :submit, 'Submit for Approval', class: 'btn btn-success' %> diff --git a/app/views/partners/profiles/step/_program_delivery_address_form.html.erb b/app/views/partners/profiles/step/_program_delivery_address_form.html.erb index 1c638e65fd..cc0cd3c94e 100644 --- a/app/views/partners/profiles/step/_program_delivery_address_form.html.erb +++ b/app/views/partners/profiles/step/_program_delivery_address_form.html.erb @@ -1,4 +1,4 @@ -<%= simple_form_for partner, url: partners_profile_path do |f| %> +<%= simple_form_for partner, url: partners_profile_path(submitted_partial: "program_delivery_address") do |f| %> <%= f.fields_for :profile, profile do |pf| %>
<%= pf.input :program_address1, label: "Address (line 1)", class: "form-control" %> diff --git a/app/views/partners/profiles/step/edit.html.erb b/app/views/partners/profiles/step/edit.html.erb index fa391bd5b9..dbcc51be87 100644 --- a/app/views/partners/profiles/step/edit.html.erb +++ b/app/views/partners/profiles/step/edit.html.erb @@ -21,6 +21,7 @@ <%# TODO: 4504 more descriptive id than accordionExample %> +<%# TODO: 4504 make use of open_section instance var to target accordion sections for which should be open and the rest should be collapsed %>
<%# Agency Information: By default, this section is expanded and is always rendered %> @@ -56,11 +57,6 @@
- <%# TODO: 4504 loop through `current_partner.partials_to_show.each do |partial|` rendering accordion sections %> - <%# Make sure to name the new partials in `step` subdir matching `ALL_PARTIALS` in app/models/partner.rb %> - <%# Have to figure out which one should be open and the rest are collapsed based on what section user just finished editing %> - <%# Then always render partner_settings %> - <%# See `app/views/partners/profiles/edit.html.erb` for original logic %> <% current_partner.partials_to_show.each do |partial| %>