Skip to content

Commit

Permalink
feat(cms): add school picker to case creation
Browse files Browse the repository at this point in the history
Jira: PWNN-1659
  • Loading branch information
EdwinKruglov committed Oct 27, 2023
1 parent 1f7f064 commit 25e2df4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
32 changes: 32 additions & 0 deletions app/controllers/support/case_requests/school_pickers_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Support
module CaseRequests
class SchoolPickersController < ApplicationController
before_action :case_request, only: %i[edit update]

def edit
@back_url = params[:source] == "change_link" ? support_case_request_path(@case_request) : edit_support_case_request_path(@case_request)
@school_picker = @case_request.school_picker
@group = @case_request.organisation
@all_schools = @group.organisations.order(:name)
@filters = @all_schools.filtering(form_params[:filters] || {})
@filtered_schools = @filters.results.map { |s| Support::OrganisationPresenter.new(s) }
end

def update
@school_picker = @case_request.school_picker(school_urns: form_params[:school_urns].compact_blank.excluding("all"))
@school_picker.save!
redirect_to support_case_request_path(@case_request)
end

private

def case_request
@case_request = CaseRequest.find_by(id: params[:id])
end

def form_params
params.fetch(:case_request, {}).permit(filters: params.key?(:clear) ? nil : { local_authorities: [], phases: [] }, school_urns: [])
end
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/support/case_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def update

if @case_request.valid?
@case_request.save!
redirect_to support_case_request_path(@case_request)
redirect_to(@case_request.eligible_for_school_picker? && @case_request.school_urns.empty? ? edit_support_case_request_school_picker_path(@case_request) : support_case_request_path(@case_request))
else
render :edit
end
Expand Down
9 changes: 9 additions & 0 deletions app/views/support/case_requests/school_pickers/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1 class="govuk-heading-l"><%= I18n.t("support.case_hub_migration.school_picker.title") %></h1>

<%= render "components/school_picker/school_picker",
results_model: @school_picker,
filters_model: @filters,
scope: :case_request,
update_url: support_case_request_school_picker_path(@case_request),
filters_url: edit_support_case_request_school_picker_path(@case_request),
method: :patch %>
14 changes: 14 additions & 0 deletions app/views/support/case_requests/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@
<%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_path, class: "govuk-link govuk-link--no-visited-state" %>
</dd>
</div>

<% if @case_request.multischool? %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= I18n.t("support.case_hub_migration.label.participating_schools") %>
</dt>
<dd class="govuk-summary-list__value">
<%= I18n.t("support.case_hub_migration.label.school_number", selected: @case_request.school_urns.count, total: @case_request.organisation.organisations.length ) %>
</dd>
<dd class="govuk-summary-list__actions">
<%= link_to I18n.t("generic.button.change_answer"), edit_support_case_request_school_picker_path(source: :change_link), class: "govuk-link govuk-link--no-visited-state" %>
</dd>
</div>
<% end %>
</dl>

<h2 class="govuk-heading-m">
Expand Down

0 comments on commit 25e2df4

Please sign in to comment.