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(csm): Adding multiple additional contacts into case
- Loading branch information
1 parent
a8aba39
commit 5fa08b1
Showing
29 changed files
with
427 additions
and
55 deletions.
There are no files selected for viewing
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
27 changes: 27 additions & 0 deletions
27
app/cores/case_management/update_case_additional_contacts.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,27 @@ | ||
module CaseManagement | ||
class UpdateCaseAdditionalContacts | ||
include Wisper::Publisher | ||
|
||
def call(support_case_id:, first_name:, last_name:, phone:, email:, extension_number:, role:) | ||
support_case = Support::Case.find(support_case_id) | ||
support_case.update!( | ||
first_name:, | ||
last_name:, | ||
phone_number: phone, | ||
email:, | ||
extension_number:, | ||
role:, | ||
) | ||
|
||
broadcast(:case_additional_contacts_changed, { | ||
case_id: support_case_id, | ||
first_name:, | ||
last_name:, | ||
phone_number: phone, | ||
email:, | ||
extension_number:, | ||
role:, | ||
}) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Support | ||
class CaseAdditionalContactForm | ||
extend Dry::Initializer | ||
include Concerns::ValidatableForm | ||
|
||
option :first_name, Types::Params::String | Types::Nil, optional: true | ||
option :last_name, Types::Params::String | Types::Nil, optional: true | ||
option :email, Types::Params::String, optional: true, default: proc { "" } | ||
option :phone_number, Types::Params::String | Types::Nil, optional: true | ||
option :extension_number, Types::Params::String | Types::Nil, optional: true | ||
option :role, Types::Params::String | Types::Array, optional: true | ||
|
||
def self.from_case(additional_contact) | ||
new(first_name: additional_contact.first_name, last_name: additional_contact.last_name, email: additional_contact.email, phone: additional_contact.phone_number, extension_number: additional_contact.extension_number, role: additional_contact.role) | ||
end | ||
|
||
def update_contact_details(kase) | ||
CaseManagement::UpdateCaseAdditionalContacts.new.call( | ||
support_case_id: kase.id, | ||
first_name:, | ||
last_name:, | ||
phone:, | ||
email:, | ||
extension_number:, | ||
role:, | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Support | ||
class CaseAdditionalContactFormSchema < Dry::Validation::Contract | ||
include Concerns::TranslatableFormSchema | ||
|
||
params do | ||
required(:first_name).value(:string) | ||
required(:last_name).value(:string) | ||
optional(:phone_number).value(:string) | ||
required(:email).value(:string) | ||
optional(:extension_number).value(:string) | ||
end | ||
|
||
rule(:email) do | ||
if value.blank? | ||
key(:email).failure(:missing) | ||
else | ||
key(:email).failure(:invalid_format) unless value.scan(URI::MailTo::EMAIL_REGEXP).any? | ||
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,7 @@ | ||
module Support | ||
module CaseAdditionalContactsHelper | ||
def role_options | ||
CheckboxOption.from(I18nOption.from("support.case_additional_contact.role.options.%%key%%", Support::CaseAdditionalContact.role_values), exclusive_fields: %w[none]) | ||
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,12 @@ | ||
module Support | ||
class CaseAdditionalContact < ApplicationRecord | ||
belongs_to :case, class_name: "Support::Case", foreign_key: "support_case_id" | ||
belongs_to :organisation, class_name: "Support::Organisation", optional: true | ||
|
||
validates :first_name, :last_name, :email, presence: true | ||
|
||
def self.role_values | ||
%w[lead evaluator] | ||
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
50 changes: 50 additions & 0 deletions
50
app/views/support/cases/additional_contacts/_form.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,50 @@ | ||
<!-- app/views/support_case_additional_contacts/_form.html.erb --> | ||
<h1 class="govuk-heading-xl"><%= I18n.t("support.case_contact_details.header") %></h1> | ||
<%new_contact = action_name == 'new' || action_name == 'create'%> | ||
<p class="govuk-hint"><%= I18n.t("support.case_contact_details.description") %></p> | ||
<%= form_with(model: @case_additional_contact_form, scope: :case_additional_contacts_form, url: new_contact ? support_case_additional_contacts_path(@current_case) : support_case_additional_contact_path(@current_case, support_case_additional_contact), method: new_contact ? :post : :put, remote: true) do |form| %> | ||
<%= form.govuk_error_summary %> | ||
|
||
<%= form.govuk_text_field :first_name, autofocus: true, width: 'one-half', label: { text: I18n.t("support.case_contact_details.label.first_name") } %> | ||
<%= form.govuk_text_field :last_name, width: 'one-half', label: { text: I18n.t("support.case_contact_details.label.last_name") } %> | ||
<%= form.govuk_text_field :email, width: 'one-half', label: { text: I18n.t("support.case_contact_details.label.email") } %> | ||
<%= form.govuk_text_field :phone_number, width: 'one-quarter', label: { text: I18n.t("support.case_contact_details.label.phone") } %> | ||
<%= form.govuk_text_field :extension_number, width: 'one-quarter', label: { text: I18n.t("support.case_contact_details.label.extension_number") } %> | ||
|
||
<% | ||
|
||
=begin%> | ||
#below code is commented because it can be used later. It is a field for organisation selection. | ||
<%= render "components/autocomplete", | ||
container_id: "case-contacts-organisation-field", | ||
label_text: I18n.t("support.case_additional_contact.organisation.header"), | ||
label_class: "govuk_text_field", | ||
element_id: "additional_contacts-autocomplete", | ||
element_name: "organisation_name", | ||
template_suggestion: "{{autocomplete_template}}", | ||
value_field: :name, | ||
default_value: form.object.organisation&.name, | ||
hidden_fields: { | ||
'support_case_additional_contact[organisation_id]' => [:id, form.object.organisation&.id], | ||
# 'case_request[organisation_type]' => [:source, form.object.organisation.class&.name], | ||
}, | ||
query_url: support_establishments_path(format: :json, q: "{{QUERY}}") %> | ||
<% | ||
=end%> | ||
<div class="govuk_text_field"> | ||
<%= form.govuk_collection_check_boxes :role, role_options, :id, :title, legend: { text: "Roles" } %> | ||
</div> | ||
<%= form.hidden_field :support_case_id, value: @current_case.id %> | ||
<div class="actions"> | ||
<%= form.submit I18n.t("support.case_contact_details.submit"), class: "govuk-button" %> | ||
<%if !new_contact%> | ||
<%= link_to 'Delete', support_case_additional_contact_path(@current_case, support_case_additional_contact), method: :delete, data: { confirm: 'Are you sure you want to delete this contact?' }, class: 'govuk-button govuk-button--secondary' %> | ||
<%end%> | ||
<%= link_to 'Cancel changes', support_case_additional_contacts_path(@current_case), class: 'govuk-button govuk-button--secondary' %> | ||
</div> | ||
<% 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render 'form', support_case_additional_contact: @additional_contact %> |
32 changes: 32 additions & 0 deletions
32
app/views/support/cases/additional_contacts/index.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,32 @@ | ||
<!-- app/views/support_case_additional_contacts/index.html.erb --> | ||
|
||
<h1 class="govuk-heading-l"><%= I18n.t("support.case_contact_details.listing_heading") %></h1> | ||
<p class="govuk-hint"><%= I18n.t("support.case_contact_details.listing_description") %></p> | ||
|
||
<table class="govuk-table messages-table"> | ||
<thead class="govuk-table__head"> | ||
<tr class="govuk-table__row"> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.contact_name") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.contact_email") %></th> | ||
<th scope="col" class="govuk-table__header"><%= I18n.t("support.case.label.contact_role") %></th> | ||
<th scope="col" class="govuk-table__header"></th> | ||
|
||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody class="govuk-table__body"> | ||
<% @additional_contacts&.each do |contact| %> | ||
<div class="govuk-summary-list__row"> | ||
<tr> | ||
<td class="govuk-table__cell"><%= contact.first_name %> <%= contact.last_name %></td> | ||
<td class="govuk-table__cell"><%= contact.email %></td> | ||
<td class="govuk-table__cell"><%= contact.role.join(", ").titleize if contact.role %></td> | ||
<td class="govuk-table__cell"><%= link_to 'change', edit_support_case_additional_contact_path(@current_case, contact) %></td> | ||
|
||
</tr> | ||
</div> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<%= link_to 'Add', new_support_case_additional_contact_path(@current_case), class: 'govuk-button' %> | ||
|
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 @@ | ||
<%= render 'form', support_case_additional_contact: @additional_contact %> |
Oops, something went wrong.