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.
- Loading branch information
1 parent
4fc0883
commit 81e1c6a
Showing
16 changed files
with
673 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
module Engagement | ||
class CaseRequestsController < ApplicationController | ||
before_action -> { @back_url = engagement_cases_path }, only: %i[new create] | ||
|
||
def new | ||
@case_request = CaseRequest.new | ||
@upload_reference = SecureRandom.hex | ||
end | ||
|
||
def create | ||
@case_request = CaseRequest.new(form_params.except(:upload_reference)) | ||
@case_request.created_by = current_agent | ||
|
||
if @case_request.valid? | ||
@case_request.save! | ||
# kase = @case_request.create_case | ||
|
||
# CaseFiles::SubmitCaseUpload.new.call(upload_reference: form_params[:upload_reference], support_case_id: kase.id) | ||
|
||
# create_interaction(kase.id, "create_case", "Case created", @case_request.attributes.slice(:source, :category)) | ||
|
||
redirect_to @case_request.eligible_for_school_picker? ? edit_support_case_request_school_picker_path(@case_request) : engagement_case_request_path(@case_request) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def submit | ||
end | ||
|
||
private | ||
|
||
def form_params | ||
params.require(:case_request).permit( | ||
:organisation_id, | ||
:organisation_type, | ||
:first_name, | ||
:last_name, | ||
:email, | ||
:phone_number, | ||
:extension_number, | ||
:discovery_method, | ||
:discovery_method_other_text, | ||
:category_id, | ||
:query_id, | ||
:request_text, | ||
:other_category, | ||
:other_query, | ||
:procurement_amount, | ||
:upload_reference, | ||
).merge({ | ||
source: :engagement_and_outreach_cms.to_s, | ||
creation_source: :engagement_and_outreach_team.to_s, | ||
}) | ||
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,51 @@ | ||
module Support | ||
class CaseRequestsController < ApplicationController | ||
before_action -> { @back_url = support_cases_path }, only: %i[new create] | ||
|
||
def new | ||
@case_request = CaseRequest.new | ||
end | ||
|
||
def create | ||
@case_request = CaseRequest.new(form_params.except(:upload_reference)) | ||
@case_request.created_by = current_agent | ||
|
||
if @case_request.valid? | ||
@case_request.save! | ||
# kase = @case_request.create_case | ||
|
||
# create_interaction(kase.id, "create_case", "Case created", @case_request.attributes.slice(:source, :category)) | ||
|
||
redirect_to support_case_request_path(@case_request) | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def submit | ||
end | ||
|
||
private | ||
|
||
def form_params | ||
params.require(:case_request).permit( | ||
:organisation_id, | ||
:organisation_type, | ||
:first_name, | ||
:last_name, | ||
:email, | ||
:phone_number, | ||
:extension_number, | ||
:discovery_method, | ||
:discovery_method_other_text, | ||
:category_id, | ||
:query_id, | ||
:source, | ||
:request_text, | ||
:other_category, | ||
:other_query, | ||
:procurement_amount, | ||
) | ||
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,62 @@ | ||
class CaseRequest < ApplicationRecord | ||
belongs_to :category, class_name: "Support::Category", optional: true | ||
belongs_to :query, class_name: "Support::Query", optional: true | ||
belongs_to :organisation, polymorphic: true, optional: true | ||
belongs_to :created_by, class_name: "Support::Agent", optional: true | ||
belongs_to :support_case, class_name: "Support::Case", optional: true | ||
|
||
enum source: { digital: 0, nw_hub: 1, sw_hub: 2, incoming_email: 3, faf: 4, engagement_and_outreach: 5, schools_commercial_team: 6, engagement_and_outreach_cms: 7 } | ||
enum creation_source: { default: 0, engagement_and_outreach_team: 5 } | ||
|
||
validates :first_name, :last_name, :email, :source, presence: true | ||
validates :phone_number, length: { maximum: 12 } | ||
validates :phone_number, format: /\A(0|\+?44)[12378]\d{8,9}\z/, if: -> { phone_number.present? } | ||
validate :discovery_method_validation | ||
validates :discovery_method_other_text, presence: true, if: -> { discovery_method == Support::Case.discovery_methods[:other] } | ||
validate :request_type_validation | ||
validates :procurement_amount, presence: true, numericality: { greater_than: 0.99 } | ||
validates :other_category, presence: true, if: -> { category_id == Support::Category.other_category_id } | ||
validates :other_query, presence: true, if: -> { query_id == Support::Query.other_query_id } | ||
|
||
def organisation_name | ||
return nil unless organisation | ||
|
||
organisation.name | ||
end | ||
|
||
def organisation_urn | ||
return nil unless organisation | ||
|
||
organisation.urn | ||
end | ||
|
||
def request_type | ||
return nil unless category.present? || query.present? | ||
|
||
category.present? | ||
end | ||
|
||
def eligible_for_school_picker? | ||
return false unless organisation.is_a?(Support::EstablishmentGroup) | ||
|
||
organisation.eligible_for_school_picker? | ||
end | ||
|
||
def create_case | ||
CreateCase.new(attributes).call | ||
end | ||
|
||
private | ||
|
||
def request_type_validation | ||
return if category.present? || query.present? | ||
|
||
errors.add(:request_type, I18n.t("case_requests.validation.request_type")) | ||
end | ||
|
||
def discovery_method_validation | ||
return if Support::Case.discovery_methods.value?(discovery_method) | ||
|
||
errors.add(:discovery_method, I18n.t("case_requests.validation.discovery_method")) | ||
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/components/_new_case_request_components.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 @@ | ||
<h1 class="govuk-heading-l"> | ||
<%= I18n.t("support.case.label.create") %> | ||
</h1> | ||
<%= render "components/autocomplete", | ||
container_id: "case-request-school-urn-field", | ||
label_text: I18n.t("support.case_hub_migration.label.school_name"), | ||
label_class: "govuk-hint", | ||
element_id: "school-urn-autocomplete", | ||
element_name: "case_request[organisation_name]", | ||
template_suggestion: "<strong>{{name}}</strong>, {{postcode}}<br />{{establishment_type}}<br />URN: {{urn}} - UKPRN: {{ukprn}}", | ||
value_field: :name, | ||
default_value: form.object.organisation_name, | ||
hidden_fields: { | ||
'case_request[organisation_id]' => [:id, form.object.organisation_id], | ||
'case_request[organisation_type]' => [:source, form.object.organisation_type], | ||
'case_request[organisation_urn]' => [:urn, form.object.organisation_urn], | ||
}, | ||
query_url: support_establishments_path(format: :json, q: "{{QUERY}}") %> | ||
|
||
|
||
|
||
<%= form.govuk_text_field :first_name, | ||
label: { text: I18n.t("support.case_hub_migration.label.first_name") } | ||
%> | ||
|
||
<%= form.govuk_text_field :last_name, | ||
label: { text: I18n.t("support.case_hub_migration.label.last_name") } | ||
%> | ||
|
||
<%= form.govuk_email_field :email, | ||
label: { text: I18n.t("support.case_hub_migration.label.email") } | ||
%> | ||
|
||
<%= form.govuk_phone_field :phone_number, | ||
label: { text: I18n.t("support.case_hub_migration.label.phone_number", optional: I18n.t("support.generic.form.optional")) } | ||
%> | ||
|
||
<%= form.govuk_phone_field :extension_number, | ||
label: { text: I18n.t("support.case_hub_migration.label.extension_number", optional: I18n.t("support.generic.form.optional")) } | ||
%> | ||
|
||
<%= render "support/cases/discovery_method/discovery_method", form: form %> | ||
|
||
<%= render "support/cases/request_details/form_fields", form: form, show_request_text: false %> | ||
|
||
<%= form.govuk_text_field :procurement_amount, width: 5, | ||
label: { text: I18n.t("support.case.label.procurement_value"), size: "m" }, | ||
prefix_text: "£" %> | ||
|
||
|
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,72 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: @case_request, scope: :case_request, url: engagement_case_requests_path, html: { | ||
"data-controller" => "case-attachment", | ||
"data-action" => "submit->case-attachment#onFormSubmitted", | ||
"data-case-attachment-target" => "form", | ||
"data-case-attachment-dropzone-outlet" => ".drop-zone-container", | ||
"data-case-attachment-error-summary-outlet" => ".govuk-error-summary", | ||
"data-case-attachment-reference-value" => @upload_reference | ||
} do |form| %> | ||
<%= form.govuk_error_summary %> | ||
|
||
<%= render "components/new_case_request_components", form: %> | ||
|
||
<h2 class="govuk-heading-m"> | ||
<%= I18n.t("support.case.label.files") %> | ||
</h2> | ||
<div class="drop-zone-container govuk-!-margin-bottom-5" | ||
data-controller="dropzone" | ||
data-dropzone-list-files-url-value="<%= list_uploads_engagement_cases_url(@upload_reference) %>" | ||
data-dropzone-add-file-url-value="<%= add_uploads_engagement_cases_url(@upload_reference) %>" | ||
data-dropzone-remove-file-url-value="<%= remove_uploads_engagement_cases_url(@upload_reference) %>"> | ||
<div class="upload-preview-template govuk-!-display-none" data-dropzone-target="previewTemplate"> | ||
<div class="upload-item"> | ||
<div class="upload-row file-details"> | ||
<h3 class="govuk-heading-s"><span data-dz-name></span> (<span data-dz-size></span>)</h3> | ||
<a href="#" class="btn-remove govuk-link govuk-link--no-visited-state" data-dz-remove>Remove</a> | ||
</div> | ||
<div class="upload-row progress-status-container"> | ||
<p class="govuk-body-s progress-status govuk-!-display-none" data-dz-errormessage></p> | ||
|
||
<div class="upload-progress-container govuk-!-display-none"> | ||
<div data-dz-uploadprogress class="upload-progress" aria-valuenow="0"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="drop-zone govuk-!-margin-bottom-5" data-case-attachment-target="dropZone"> | ||
<p class="govuk-body">Drag and drop files here or</p> | ||
|
||
<span class="govuk-button govuk-button--secondary" | ||
data-dropzone-target="btnDisplayFileDialog"> | ||
Choose files | ||
</span> | ||
</div> | ||
|
||
<div class="file-previews"> | ||
<div class="files-added-now govuk-!-margin-bottom-5 govuk-!-display-none" | ||
data-case-attachment-target="filesAddedNow" | ||
data-dropzone-target="filePreview"> | ||
<h2 class="govuk-heading-m"> | ||
Files added | ||
</h2> | ||
</div> | ||
|
||
<div class="files-added-before govuk-!-margin-bottom-5 govuk-!-display-none" | ||
data-case-attachment-target="filesAddedBefore"> | ||
<h2 class="govuk-heading-m"> | ||
Files already uploaded | ||
</h2> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="govuk-button-group"> | ||
<%= form.hidden_field :upload_reference, :value => @upload_reference %> | ||
<%= form.submit I18n.t("support.case_hub_migration.submit"), class: "govuk-button", role: "button", "data-prevent-double-click" => true, "data-case-attachment-target" => "btnSubmit" %> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> |
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,22 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: @case_request, scope: :case_request, url: support_case_requests_path do |form| %> | ||
<%= form.govuk_error_summary %> | ||
|
||
<%= render "components/new_case_request_components", form: %> | ||
|
||
<h2 class="govuk-heading-m"> | ||
<%= I18n.t("support.case_source.header") %> | ||
</h2> | ||
<%= form.govuk_select(:source, | ||
[ | ||
["Please select", ""], | ||
[I18n.t("support.case.label.source.engagement_and_outreach"), "engagement_and_outreach"], | ||
[I18n.t("support.case.label.source.schools_commercial_team"), "schools_commercial_team"] | ||
], | ||
label: { text: I18n.t("support.case_source.select.header") }) | ||
%> | ||
<%= form.submit I18n.t("support.case_hub_migration.submit"), class: "govuk-button", role: "button" %> | ||
<% end %> | ||
</div> | ||
</div> |
Oops, something went wrong.