Skip to content

Commit

Permalink
Merge pull request #1796 from DFE-Digital/decline-content
Browse files Browse the repository at this point in the history
Improve decline email and view content
  • Loading branch information
thomasleese authored Nov 14, 2023
2 parents f34f31c + 1beea5f commit f65b24a
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 289 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ApplicationFormsController < BaseController
define_history_check :edit

def new
existing_application_form = current_teacher.application_form
existing_application_form = application_form

@already_applied = existing_application_form.present?
@needs_region = false
Expand All @@ -26,7 +26,7 @@ def new
end

def create
@already_applied = current_teacher.application_form.present?
@already_applied = application_form.present?

@country_region_form =
CountryRegionForm.new(
Expand All @@ -44,15 +44,15 @@ def create
end

def show
@view_object = ApplicationFormShowViewObject.new(current_teacher:)

if @view_object.application_form.nil?
if application_form.nil?
redirect_to %i[new teacher_interface application_form]
end

@view_object = ApplicationFormViewObject.new(application_form:)
end

def edit
@view_object = ApplicationFormShowViewObject.new(current_teacher:)
@view_object = ApplicationFormViewObject.new(application_form:)

@sanction_confirmation_form =
SanctionConfirmationForm.new(
Expand All @@ -62,7 +62,7 @@ def edit
end

def update
@view_object = ApplicationFormShowViewObject.new(current_teacher:)
@view_object = ApplicationFormViewObject.new(application_form:)

if (
@sanction_confirmation_form =
Expand Down
3 changes: 3 additions & 0 deletions app/mailers/teacher_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ def application_awarded
end

def application_declined
@view_object =
TeacherInterface::ApplicationFormViewObject.new(application_form:)

view_mail(
GOVUK_NOTIFY_TEMPLATE_ID,
to: teacher.email,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
# frozen_string_literal: true

class TeacherInterface::ApplicationFormShowViewObject
class TeacherInterface::ApplicationFormViewObject
include RegionHelper

def initialize(current_teacher:)
@current_teacher = current_teacher
def initialize(application_form:)
@application_form = application_form
end

def teacher
@current_teacher
end

def application_form
@application_form ||= teacher.application_form
end
attr_reader :application_form

def assessment
@assessment ||= application_form&.assessment
end
delegate :assessment, :region, :teacher, to: :application_form

def further_information_request
@further_information_request ||=
assessment&.further_information_requests&.first
end

def professional_standing_request
@professional_standing_request ||= assessment&.professional_standing_request
end

def started_at
application_form.created_at.strftime("%e %B %Y")
application_form.created_at.to_fs(:date).strip
end

def expires_at
(application_form.created_at + 6.months).strftime("%e %B %Y")
application_form.expires_at.to_fs(:date).strip
end

def task_list_sections
@task_list_sections ||= [
[
task_list_section(
:about_you,
%i[personal_information identification_document],
Expand All @@ -62,40 +50,46 @@ def task_list_sections
end

def completed_task_list_sections
@completed_task_list_sections ||=
task_list_sections.filter do |section|
section[:items].all? { |item| item[:status] == "completed" }
end
task_list_sections.filter do |section|
section[:items].all? { |item| item[:status] == "completed" }
end
end

def can_submit?
completed_task_list_sections.count == task_list_sections.count
end

def notes_from_assessors
return [] if assessment.nil? || further_information_request.present?

assessment.sections.filter_map do |section|
next nil if section.selected_failure_reasons.empty?

failure_reasons =
section.selected_failure_reasons.map do |failure_reason|
is_decline =
FailureReasons.decline?(failure_reason: failure_reason.key)
def declined_reasons
if further_information_request&.expired?
{
"" => [
I18n.t(
"teacher_interface.application_forms.show.declined.failure_reasons.further_information_request_expired",
),
],
}
elsif professional_standing_request&.expired?
{
"" => [
I18n.t(
"teacher_interface.application_forms.show.declined.failure_reasons.professional_standing_request_expired",
certificate_name: region_certificate_name(region),
teaching_authority_name: region_teaching_authority_name(region),
),
],
}
else
reasons = {}

{
key: failure_reason.key,
is_decline:,
assessor_feedback: failure_reason.assessor_feedback,
}
end
if (note = assessment&.recommendation_assessor_note).present?
reasons.merge!({ "" => [note] })
end

failure_reasons =
failure_reasons.sort_by do |failure_reason|
[failure_reason[:is_decline] ? 0 : 1, failure_reason[:key]]
end
if assessment.present? && further_information_request.nil?
reasons.merge!(assessment_declined_reasons)
end

{ assessment_section_key: section.key, failure_reasons: }
reasons
end
end

Expand All @@ -111,14 +105,6 @@ def declined_cannot_reapply?
end
end

def show_further_information_request_expired_content?
further_information_request&.expired? || false
end

def show_professional_standing_request_expired_content?
professional_standing_request&.expired? || false
end

def request_further_information?
further_information_request.present? &&
further_information_request.requested? &&
Expand All @@ -134,17 +120,16 @@ def request_professional_standing_certificate?
) || false
end

delegate :region, to: :application_form

private

delegate :needs_work_history,
:needs_written_statement,
:needs_registration_number,
:teaching_authority_provides_written_statement,
:requires_preliminary_check,
to: :application_form,
allow_nil: true
to: :application_form

delegate :professional_standing_request, to: :assessment, allow_nil: true

def task_list_section(key, item_keys)
{
Expand All @@ -156,14 +141,14 @@ def task_list_section(key, item_keys)
def task_list_items(keys)
keys.map do |key|
{
name: name_for_task_item(key),
link: link_for_task_item(key),
status: status_for_task_item(key),
name: task_list_item_name(key),
link: task_list_item_link(key),
status: task_list_item_status(key),
}
end
end

def name_for_task_item(key)
def task_list_item_name(key)
if key == :written_statement
if application_form.teaching_authority_provides_written_statement
I18n.t("application_form.tasks.items.written_statement.provide")
Expand All @@ -175,7 +160,7 @@ def name_for_task_item(key)
end
end

def link_for_task_item(key)
def task_list_item_link(key)
case key
when :identification_document
[
Expand Down Expand Up @@ -205,7 +190,49 @@ def link_for_task_item(key)
end
end

def status_for_task_item(key)
def task_list_item_status(key)
application_form.send("#{key}_status")
end

def assessment_declined_reasons
assessment
.sections
.each_with_object({}) do |section, hash|
next if section.selected_failure_reasons.empty?

sorted_reasons =
section.selected_failure_reasons.sort_by do |failure_reason|
is_decline =
FailureReasons.decline?(failure_reason: failure_reason.key)

[is_decline ? 0 : 1, failure_reason.key]
end

reasons =
sorted_reasons.map do |failure_reason|
title =
I18n.t(
failure_reason.key,
scope: %i[
teacher_interface
application_forms
show
declined
failure_reasons
],
)

if (
assessor_feedback = failure_reason.assessor_feedback
).present? &&
FailureReasons.decline?(failure_reason: failure_reason.key)
"#{title}\n\n#{assessor_feedback}"
else
title
end
end

hash[section.key.humanize] = reasons
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
<% @assessment.sections.not_preliminary.each do |section| %>
<% if (selected_failure_reasons = section.selected_failure_reasons).present? %>
<h3 class="govuk-heading-m"><%= t(".assessment_section.#{section.key}") %></h3>
<ul class="govuk-list">
<ul class="govuk-list govuk-list--bullet">
<% selected_failure_reasons.each do |failure_reason| %>
<li>
<h4 class="govuk-heading-s">
<%= t(failure_reason.key, scope: %i[assessor_interface assessment_sections failure_reasons as_statement]) %>
</h4>

<% if FailureReasons.decline?(failure_reason: failure_reason.key) %>
<p class="govuk-body govuk-!-margin-bottom-2">Your note to the applicant:</p>
<% else %>
<p class="govuk-body govuk-!-margin-bottom-2">Your note (the applicant won’t see this):</p>
<% end %>
<% if (assessor_feedback = failure_reason.assessor_feedback).present? %>
<% if FailureReasons.decline?(failure_reason: failure_reason.key) %>
<p class="govuk-body govuk-!-margin-bottom-2">Your note to the applicant:</p>
<% else %>
<p class="govuk-body govuk-!-margin-bottom-2">Your note (the applicant won’t see this):</p>
<% end %>

<%= govuk_inset_text do %>
<%= simple_format failure_reason.assessor_feedback %>
<%= govuk_inset_text { simple_format assessor_feedback } %>
<% end %>
</li>
<% end %>
Expand Down
4 changes: 1 addition & 3 deletions app/views/shared/teacher_mailer/_reference_number.text.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
Your application reference number is:

<%= @application_form.reference %>
Application reference number: <%= @application_form.reference %>
Loading

0 comments on commit f65b24a

Please sign in to comment.