generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crm): Adding non participating schools in a group
- Loading branch information
1 parent
ef732fb
commit 0f43a0a
Showing
19 changed files
with
392 additions
and
19 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
app/controllers/support/cases/additional_contacts_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
module Support | ||
class Cases::AdditionalContactsController < Cases::ApplicationController | ||
before_action :set_current_case, only: %i[create update edit new] | ||
before_action :set_additional_contact, only: %i[edit update destroy] | ||
before_action :set_additional_contacts, only: %i[index] | ||
before_action :get_emails_of_contacts, only: %i[create update] | ||
|
||
def index; end | ||
|
||
def new | ||
@additional_contact = @current_case&.case_additional_contacts&.build | ||
end | ||
|
||
def create | ||
@current_case = Support::Case.find(additional_contact_params[:support_case_id]) if @current_case.blank? | ||
@additional_contact = Support::CaseAdditionalContact.build(additional_contact_params) | ||
|
||
if validation.success? && !@emails.include?(additional_contact_params[:email]) | ||
@additional_contact.save! | ||
redirect_to support_case_additional_contacts_path(case_id: @current_case.id), notice: I18n.t("support.case_contact_details.flash.success") | ||
else | ||
flash.now[:notice] = I18n.t("support.case_contact_details.flash.already_a_contact") if @emails.include?(additional_contact_params[:email]) | ||
render :new | ||
end | ||
end | ||
|
||
def edit | ||
@current_case = Support::Case.find(@additional_contact.support_case_id) | ||
end | ||
|
||
def update | ||
@emails.delete(@additional_contact.email) | ||
if validation.success? && !@emails.include?(additional_contact_params[:email]) | ||
@additional_contact.update!(additional_contact_params) | ||
redirect_to support_case_additional_contacts_path(case_id: @current_case.id), notice: I18n.t("support.case.label.non_participating_schools.success.message") if @additional_contact.update(additional_contact_params) | ||
|
||
else | ||
flash.now[:notice] = I18n.t("support.case_contact_details.flash.already_a_contact") if @emails.include?(additional_contact_params[:email]) | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@additional_contact.destroy! | ||
redirect_to support_case_additional_contacts_path(case_id: @current_case.id), notice: I18n.t("support.case_contact_details.flash.destroyed") | ||
end | ||
|
||
private | ||
|
||
def set_current_case | ||
@current_case = Support::Case.find(params[:case_id]) | ||
end | ||
|
||
def validation | ||
CaseAdditionalContactFormSchema.new.call(**additional_contact_params) | ||
end | ||
|
||
def set_additional_contact | ||
@additional_contact = Support::CaseAdditionalContact.find(params[:id]) | ||
end | ||
|
||
def set_additional_contacts | ||
@additional_contacts = @current_case.case_additional_contacts | ||
end | ||
|
||
def get_emails_of_contacts | ||
@emails = @current_case.case_additional_contacts.pluck(:email) | ||
@emails << @current_case.email | ||
end | ||
|
||
def additional_contact_params | ||
params.require(:support_case_additional_contact).permit(:first_name, :last_name, :email, :phone_number, :extension_number, :support_case_id, :organisation_id, role: []).tap do |p| | ||
p[:role].reject!(&:blank?) | ||
end | ||
end | ||
end | ||
end |
67 changes: 67 additions & 0 deletions
67
app/controllers/support/cases/school_details/other_schools_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
module Support | ||
module Cases | ||
module SchoolDetails | ||
class OtherSchoolsController < Cases::ApplicationController | ||
before_action :set_instances, only: %i[confirmation_message remove_school non_beneficiery_schools] | ||
|
||
def non_beneficiery_schools | ||
@back_url = support_case_path(@current_case, anchor: "school-details") | ||
@other_schools = @current_case.other_schools.map { |s| Support::OrganisationPresenter.new(s) } | ||
end | ||
|
||
def other_school | ||
@other_school_form = OtherSchoolForm.new if @other_school_form.blank? | ||
end | ||
|
||
def add_other_school | ||
@organisation = Support::Organisation.find_by(id: other_school_form_params[:school_id]) | ||
@other_school_form = OtherSchoolForm.from_validation(validation) | ||
if validation.success? | ||
if (@current_case.other_school_urns.include? @organisation.urn) || (@current_case.organisation.organisations.pluck(:urn).include? @organisation.urn) | ||
message = if @current_case.other_school_urns.include? @organisation.urn | ||
I18n.t("support.case.label.school_details.non_participating_schools.error.already_a_member_message", name: @organisation.name) | ||
else | ||
I18n.t("support.case.label.school_details.non_participating_schools.error.part_of_group_message", name: @organisation.name) | ||
end | ||
flash[:error] = { message:, class: "govuk-error" } | ||
render :other_school | ||
else | ||
urns = @current_case.other_school_urns << @organisation.urn | ||
@current_case.update!(other_school_urns: urns) | ||
redirect_to non_beneficiery_schools_support_case_school_details_other_schools_path(@current_case) | ||
flash[:notice] = I18n.t("support.case.label.school_details.non_participating_schools.success.message") | ||
end | ||
else | ||
flash[:error] = { class: "remove-message" } | ||
render :other_school | ||
end | ||
end | ||
|
||
def confirmation_message | ||
@back_url = non_beneficiery_schools_support_case_school_details_other_schools_path(@current_case) | ||
end | ||
|
||
def remove_school | ||
school_urns = @current_case.other_school_urns - [@organisation.urn] | ||
@current_case.update!(other_school_urns: school_urns) | ||
redirect_to non_beneficiery_schools_support_case_school_details_other_schools_path(@current_case) | ||
end | ||
|
||
private | ||
|
||
def validation | ||
OtherSchoolFormSchema.new.call(**other_school_form_params) | ||
end | ||
|
||
def set_instances | ||
@organisation = Support::Organisation.find_by(id: params[:school_id]) | ||
@current_case = Support::Case.find_by(id: params[:case_id]) | ||
end | ||
|
||
def other_school_form_params | ||
params.require(:case_organisation_form).permit(:school_id, :organisation_name) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# :nocov: | ||
module Support | ||
class OtherSchoolForm | ||
extend Dry::Initializer | ||
include Concerns::ValidatableForm | ||
|
||
option :school_id, Types::Params::String, optional: true | ||
option :organisation_name, Types::Params::String, optional: true | ||
|
||
def assign_organisation_to_case(kase, agent_id) | ||
CaseManagement::AssignOrganisationToCase.new.call( | ||
support_case_id: kase.id, | ||
agent_id:, | ||
organisation_id:, | ||
organisation_type:, | ||
) | ||
end | ||
end | ||
end | ||
# :nocov: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# :nocov: | ||
module Support | ||
class OtherSchoolFormSchema < Dry::Validation::Contract | ||
include Concerns::TranslatableFormSchema | ||
|
||
params do | ||
required(:school_id).value(:string) | ||
required(:organisation_name).value(:string) | ||
end | ||
|
||
rule(:school_id) do | ||
key(:school_id).failure(:missing) if value.blank? | ||
end | ||
|
||
rule(:organisation_name) do | ||
# intentional use of organisation_id - the user should only see 1 error around organisation | ||
key(:school_id).failure(:missing) if value.blank? | ||
end | ||
end | ||
end | ||
# :nocov: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
<% flash.each do |name, msg| %> | ||
<% if msg.is_a?(String) %> | ||
<div class="govuk-notification-banner govuk-notification-banner--<%= name %>" role="alert" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner"> | ||
<div class="govuk-notification-banner__header"> | ||
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title"> | ||
<%= name.capitalize %> | ||
</h2> | ||
<% if flash[:error].present? && flash[:error][:class].present? %> | ||
<%if flash[:error][:class]!= "remove-message"%> | ||
<div class="govuk-error-summary" data-module="govuk-error-summary"> | ||
<div role="alert"> | ||
<h2 class="govuk-error-summary__title" data-error-summary-target="title"> | ||
There is a problem | ||
</h2> | ||
<div class="govuk-error-summary__body" data-error-summary-target="body" aria-live="polite"> | ||
<ul class="govuk-list govuk-error-summary__list"> | ||
<li> | ||
<a data-turbo="false" href="#case-organisation-form-organisation-id-field-error"> <%= flash[:error][:message] %></a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="govuk-notification-banner__content"> | ||
<h3 class="govuk-notification-banner__heading"> | ||
<%= content_tag :div, msg, id: "flash_#{name}" %> | ||
</h3> | ||
<%end%> | ||
<%else%> | ||
<% if msg.is_a?(String) %> | ||
<div class="govuk-notification-banner govuk-notification-banner--<%= name %>" role="alert" aria-labelledby="govuk-notification-banner-title" data-module="govuk-notification-banner"> | ||
<div class="govuk-notification-banner__header"> | ||
<h2 class="govuk-notification-banner__title" id="govuk-notification-banner-title"> | ||
<%= name.capitalize %> | ||
</h2> | ||
</div> | ||
<div class="govuk-notification-banner__content"> | ||
<h3 class="govuk-notification-banner__heading"> | ||
<%= content_tag :div, msg, id: "flash_#{name}" %> | ||
</h3> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
<%end%> | ||
<% end %> |
35 changes: 35 additions & 0 deletions
35
app/views/support/cases/school_details/other_schools/confirmation_message.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<%= content_for :title, I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.title") %> | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l"><%= I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.title") %></h1> | ||
<table class="govuk-table"> | ||
<tbody class="govuk-table__body"> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="row" ><%= I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.name") %></th> | ||
<td class="govuk-table__cell"><%= @organisation.name %></td> | ||
</tr> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="row" ><%= I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.organisation") %></th> | ||
<td class="govuk-table__cell"><%= @organisation.org_type %></td> | ||
</tr> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="row" ><%= I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.status") %></th> | ||
<td class="govuk-table__cell"><%= I18n.t("components.school_picker.statuses.#{@organisation.status}") %></td> | ||
</tr> | ||
<%if @organisation.trust_name.present?%> | ||
<tr class="govuk-table__row"> | ||
<th class="govuk-table__header" scope="row" ><%= I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.parent") %></th> | ||
<td class="govuk-table__cell"><%= @organisation.trust_name %></td> | ||
</tr> | ||
<%end%> | ||
</tbody> | ||
</table> | ||
|
||
<br> | ||
|
||
<div class="govuk-button-group"> | ||
<%= link_to I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.remove"), remove_school_support_case_school_details_other_schools_path(@current_case, :school_id => @organisation.id), method: :patch, class: "govuk-button govuk-button--warning", role: "button" %> | ||
<%= link_to I18n.t("support.case.label.school_details.non_participating_schools.removal_modal.cancel"), @back_url, class: "govuk-link" %> | ||
</div> | ||
</div> | ||
</div> |
33 changes: 33 additions & 0 deletions
33
app/views/support/cases/school_details/other_schools/non_beneficiery_schools.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<h2 class="govuk-heading-l"> | ||
<%= I18n.t("support.case.label.school_details.non_participating_schools.heading")%> | ||
</h2> | ||
<p class="govuk-hint"><%= I18n.t("support.case.label.school_details.non_participating_schools.description")%></p> | ||
<p class="govuk-hint"><%= I18n.t("support.case.label.school_details.non_participating_schools.description_other")%></p> | ||
<table class="govuk-table" aria-label="Non Participating schools"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.school_details.non_participating_schools.table.school_name") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.school_details.non_participating_schools.table.address") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.school_details.non_participating_schools.table.organisation_type") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.school_details.non_participating_schools.table.status") %></th> | ||
<th scope="col" class="govuk-table__header"><%= %></th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
<% @other_schools.each do |school| %> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header"><%= "#{school.name} <br>( URN #{school.urn} )".html_safe %></th> | ||
<td class="govuk-table__cell"><%= school.formatted_address %></td> | ||
<td class="govuk-table__cell"><%= school.org_type %></td> | ||
<%time = (school.status == "opening" || school.status == "closing") && school.opened_date.present? ? " ( #{school.opened_date&.strftime("%B, %d, %Y")} )" : ""%> | ||
<td class="govuk-table__cell"><%= I18n.t("components.school_picker.statuses.#{school.status}")%></td> | ||
<td class="govuk-table__cell"> | ||
<%= link_to "remove", confirmation_message_support_case_school_details_other_schools_path(@current_case, :school_id => school.id), class: "govuk-link", target: "_top" %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<%= link_to "Add", other_school_support_case_school_details_other_schools_path(@current_case), class: "govuk-button govuk-button--secondary", target: "_top" %> | ||
|
||
|
20 changes: 20 additions & 0 deletions
20
app/views/support/cases/school_details/other_schools/other_school.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%= form_with model:@other_school_form, scope: :other_school_form, url: add_other_school_support_case_school_details_other_schools_path(@current_case), method: :patch do |form| %> | ||
<%= form.govuk_error_summary %> | ||
<%= link_to "Back", non_beneficiery_schools_support_case_school_details_other_schools_path(@current_case), class: "govuk-back-link pull-up" %> | ||
<h1 class="govuk-heading-l"> | ||
<%= I18n.t("support.case.label.school_details.non_participating_schools.add_school") %> | ||
</h1> | ||
<%= render "components/autocomplete", | ||
container_id: "organisation-autocomplete-container", | ||
label_text: I18n.t("support.case.label.school_details.non_participating_schools.add_school_hint"), | ||
label_class: "govuk-hint", | ||
element_id: "organisation-autocomplete", | ||
element_name: "case_organisation_form[organisation_name]", | ||
template_suggestion: "{{autocomplete_template}}", | ||
value_field: :name, | ||
hidden_fields: { | ||
'case_organisation_form[school_id]' => :id, | ||
}, | ||
query_url: support_list_for_non_participating_establishment_path(format: :json, q: "{{QUERY}}") %> | ||
<%= form.submit I18n.t("support.case.label.school_details.non_participating_schools.success.continue"), class: "govuk-button" %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,5 @@ | |
</tbody> | ||
</table> | ||
<% end %> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.