Skip to content

Commit

Permalink
[rubyforgood#4504] Start on logic to determine next open section base…
Browse files Browse the repository at this point in the history
…d on currently submitted partial
  • Loading branch information
danielabar committed Sep 21, 2024
1 parent 29af4a1 commit 4405074
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
42 changes: 36 additions & 6 deletions app/controllers/partners/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ def edit
@client_share_total = current_partner.profile.client_share_total

if Flipper.enabled?("partner_step_form")
# TODO: 4504 need to populate `open_section` param with the correct value
# @open_section = ...
@open_section = params[:open_section] || "agency_information"
# temp debug
Rails.logger.info("=== [ProfilesController#edit] open_section=#{@open_section}")
render "partners/profiles/step/edit"
else
render "edit"
Expand All @@ -20,10 +21,8 @@ def update
result = PartnerProfileUpdateService.new(current_partner, partner_params, profile_params).call
if result.success?
if Flipper.enabled?("partner_step_form")
# TODO: 4504 need better logic to determine which section to open
# TODO: 4504 maybe the open_section logic doesn't belong here but rather in `edit` action
# TODO: 4504 do we also need a flash message to let user know that section was updated
open_section = params[:open_section] || "agency_information"
submitted_partial = params[:submitted_partial]
open_section = next_step(submitted_partial)
redirect_to edit_partners_profile_path(open_section: open_section)
else
flash[:success] = "Details were successfully updated."
Expand All @@ -37,6 +36,37 @@ def update

private

# TODO: 4504 move this to somewhere easier to test like a service
# TODO: 4504 implement logic to determine which section should be next -> complexity dynamics!
# 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 |
# | media_information | true | dynamic | collapsed | agency_stability |
# | agency_stability | true | dynamic | collapsed | organizational_capacity |
# | organizational_capacity | true | dynamic | collapsed | sources_of_funding |
# | sources_of_funding | true | dynamic | collapsed | area_served |
# | area_served | true | dynamic | collapsed | population_served |
# | population_served | true | dynamic | collapsed | executive_director |
# | executive_director | true | dynamic | collapsed | pick_up_person |
# | pick_up_person | true | dynamic | collapsed | agency_distribution_information |
# | agency_distribution_information | true | dynamic | collapsed | attached_documents |
# | attached_documents | true | dynamic | collapsed | partner_settings |
# | partner_settings | true | static | collapsed | NA |
def next_step(submitted_partial)
case submitted_partial
when "agency_information"
"program_delivery_address"
when "program_delivery_address"
"media_information"
when "partner_settings"
"NA"
else
"agency_information"
end
end

def partner_params
params.require(:partner).permit(:name)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for partner, url: partners_profile_path, html: { multipart: true } do |f| %>
<%= simple_form_for partner, url: partners_profile_path(submitted_partial: "agency_information"), html: { multipart: true } do |f| %>
<div class="form-group">
<%= f.input :name, label: "Agency Name", required: true, class: "form-control" %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/partners/profiles/step/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="accordion" id="accordionExample">

<%# Agency Information: By default, this section is expanded and is always rendered %>
<%# TODO: 4504 Use `open_section` param to determine which accordion to expand, all others should be collapsed %>
<%# TODO: 4504 Use `open_section` instance var to determine which accordion to expand, all others should be collapsed %>
<div class="accordion-item">
<h2 class="accordion-header">
<%# TODO: 4504 add the .collapsed class to the button and set its aria-expanded attribute to false if should be hidden %>
Expand Down

0 comments on commit 4405074

Please sign in to comment.