Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
elceebee committed Dec 18, 2024
1 parent 02c8edb commit f7354ad
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<%= govuk_summary_list do |summary_list| %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t('withdrawal_reasons.secondary_reasons_review_component.provider')) %>
<% row.with_value(text: @application_choice.current_course.provider.name) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t('withdrawal_reasons.secondary_reasons_review_component.course')) %>
<% row.with_value(text: @application_choice.current_course.name_and_code) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t('withdrawal_reasons.secondary_reasons_review_component.reason')) %>
<% row.with_value(text: primary_reason_text) %>
<% row.with_action(
text: t('withdrawal_reasons.secondary_reasons_review_component.change'),
href: candidate_interface_withdrawal_reasons_primary_reason_edit_path(withdrawal_reason_id: redirect_id),
visually_hidden_text: t('withdrawal_reasons.secondary_reasons_review_component.primary_reason_visually_hidden_change_text'),
) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t('withdrawal_reasons.secondary_reasons_review_component.reason_details')) %>
<% row.with_value do %>
<%= govuk_list(reason_details) %>
<% end %>
<% row.with_action(
text: t('withdrawal_reasons.secondary_reasons_review_component.change'),
href: candidate_interface_withdrawal_reasons_secondary_reasons_start_path(primary_reason: @primary_reason),
) %>
<% end %>
<% end %>

<%= form_with(
url: candidate_interface_withdrawal_reasons_secondary_reasons_withdraw_path(@application_choice),
method: :post,
) do |f| %>

<%= f.govuk_submit 'Yes I’m sure – withdraw this application', warning: true %>
<% end %>

<p class="govuk-body">
<%= govuk_link_to(
t('cancel'),
candidate_interface_application_choices_path,
) %>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module CandidateInterface
module WithdrawalReasons
class SecondaryReasonsReviewComponent < ViewComponent::Base
PERSONAL_CIRCUMSTANCES_KEY = 'personal-circumstances-have-changed'.freeze

def initialize(primary_reason, application_choice:)
@application_choice = application_choice
@primary_reason = primary_reason
end

def primary_reason_text
translate("#{@primary_reason}.label")
end

def reason_details
withdrawal_reasons.pluck(:reason, :comment).map do |reason, comment|
if reason.include? PERSONAL_CIRCUMSTANCES_KEY
reasons_with_further_detail(reason, comment)
else
reason_without_further_detail(reason, comment)
end
end
end

def redirect_id
withdrawal_reasons.first.id
end

private

def withdrawal_reasons
@withdrawal_reasons ||= @application_choice.draft_withdrawal_reasons.reject do |withdrawal_reason|
withdrawal_reason.reason.exclude?(@primary_reason)
end
end

def reason_without_further_detail(reason, comment = nil)
label = translate("#{reason}.label")

comment.present? ? "#{label}: #{comment}" : label
end

def reasons_with_further_detail(reason, comment = nil)
personal_circumstances_label = translate("#{@primary_reason}.#{PERSONAL_CIRCUMSTANCES_KEY}.label")
label = translate("#{reason}.label")

if comment.present?
"#{personal_circumstances_label} (#{label}): #{comment}"
else
"#{personal_circumstances_label}: #{label}"
end
end

def translate(string)
I18n.t("candidate_interface.withdrawal_reasons.reasons.#{string}".gsub!('-', '_'))
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ def withdraw
end

def review
@secondary_reasons_form = SecondaryReasonsForm.new(
{ primary_reason: },
application_choice: @application_choice,
withdrawal_reasons: @application_choice.withdrawal_reasons,
)
@primary_reason = primary_reason
end

def cancel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class SecondaryReasonsForm
include ActiveModel::Model
include ActiveModel::Validations::Callbacks

PERSONAL_CIRCUMSTANCES_KEY = 'personal-circumstances-have-changed'.freeze

attr_accessor :primary_reason,
:secondary_reasons,
:personal_circumstances_reasons,
Expand Down Expand Up @@ -32,27 +34,19 @@ def self.build_from_application_choice(primary_reason, application_choice)
withdrawal_reasons = application_choice.draft_withdrawal_reasons.reject do |withdrawal_reason|
withdrawal_reason.reason.exclude?(primary_reason)
end

withdrawal_reasons.each do |withdrawal_reason|
if withdrawal_reason.reason.include?('personal-circumstances-have-changed.')
secondary_reasons << 'personal-circumstances-have-changed' unless secondary_reasons.include?('personal-circumstances-have-changed')
personal_circumstances_reasons << (withdrawal_reason.reason.split('.') - [primary_reason]).join('.')
personal_circumstances_reasons_comment = withdrawal_reason.comment if withdrawal_reason.comment.present?
else
secondary_reasons << (withdrawal_reason.reason.split('.') - [primary_reason]).join('.')
comment = withdrawal_reason.comment if withdrawal_reason.comment.present?
end
end
new(
{
primary_reason:,
secondary_reasons:,
personal_circumstances_reasons:,
comment:,
personal_circumstances_reasons_comment:,
},
application_choice:,
withdrawal_reasons:,
)

secondary_reasons << PERSONAL_CIRCUMSTANCES_KEY if personal_circumstances_reasons.present?
new({ primary_reason:, secondary_reasons:, personal_circumstances_reasons:, comment:, personal_circumstances_reasons_comment: }, application_choice:, withdrawal_reasons:)
end

def initialize(attributes = {}, application_choice: nil, withdrawal_reasons: nil)
Expand All @@ -68,7 +62,7 @@ def create!

# Then create from valid form attributes
[secondary_reasons, personal_circumstances_reasons].flatten.each do |reason|
next if reason == 'personal-circumstances-have-changed'
next if reason == PERSONAL_CIRCUMSTANCES_KEY

other_comment = if reason == 'other'
comment
Expand Down Expand Up @@ -103,57 +97,13 @@ def reason_options
end
end

def review_reasons
[non_nested_reasons, nested_reasons].flatten
end

def nested_reasons
@withdrawal_reasons.pluck(:reason, :comment).map do |reason, comment|
next unless reason.include? 'personal-circumstances-have-changed'

personal_circumstances_label = translate('personal-circumstances-have-changed.label')

if comment.present?
[personal_circumstances_label, comment].join(': ')
else

label = translate("#{reason.gsub(primary_reason, '')}.label")
[personal_circumstances_label, label].join(': ')
end
end
end

def non_nested_reasons
@withdrawal_reasons.pluck(:reason, :comment).map do |reason, comment|
next if reason.include? 'personal-circumstances-have-changed'

translate("#{reason.gsub(primary_reason, '')}.label")

label = I18n.t("candidate_interface.withdrawal_reasons.reasons.#{reason}.label".gsub('-', '_'))

if comment.present?
[label, comment].join(': ')
else
label
end
end
end

def review_primary_reason
translate('label')
end

def form_title
translate('secondary_reasons_title')
end

def withdrawal_reason_id_for_primary_redirect
@withdrawal_reasons.first.id
end

def return_to_primary_reasons_path
if @withdrawal_reasons.present?
Rails.application.routes.url_helpers.candidate_interface_withdrawal_reasons_primary_reason_edit_path(@application_choice, withdrawal_reason_id: withdrawal_reason_id_for_primary_redirect)
Rails.application.routes.url_helpers.candidate_interface_withdrawal_reasons_primary_reason_edit_path(@application_choice, withdrawal_reason_id: @withdrawal_reasons.first.id)
else
Rails.application.routes.url_helpers.candidate_interface_withdrawal_reasons_primary_reason_start_path(@application_choice)
end
Expand All @@ -170,7 +120,7 @@ def personal_circumstances_reasons_comment_required?
end

def personal_circumstances_reasons_required?
secondary_reasons.present? && secondary_reasons.include?('personal-circumstances-have-changed')
secondary_reasons.present? && secondary_reasons.include?(PERSONAL_CIRCUMSTANCES_KEY)
end

def secondary_reasons_presence
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= form_with(model: @secondary_reasons_form, url: candidate_interface_withdrawal_reasons_secondary_reasons_continue_path) do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_check_boxes_fieldset(:secondary_reasons, legend: { text: @secondary_reasons_form.form_title, tag: 'h1', size: 'l' }) do %>
<%= f.govuk_check_boxes_fieldset(:secondary_reasons, legend: { text: @secondary_reasons_form.form_title, tag: 'h1', size: 'l' }, hint: { text: t('candidate_interface.withdrawal_reasons.select_all_that_apply') }) do %>
<% @secondary_reasons_form.reason_options.each_with_index do |reason, index| %>
<%= f.govuk_check_box(:secondary_reasons, reason.id, link_errors: index.zero?, label: { text: reason.name }) do %>
<% if reason.other_reason.present? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,8 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<h1 class="govuk-heading-l"><%= t('page_titles.decisions.withdraw') %></h1>
<%= govuk_summary_list do |summary_list| %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: 'Provider') %>
<% row.with_value(text: @application_choice.current_course.provider.name) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: 'Course') %>
<% row.with_value(text: @application_choice.current_course.name_and_code) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: 'Reason') %>
<% row.with_value(text: @secondary_reasons_form.review_primary_reason) %>
<% row.with_action(
text: 'Change',
href: candidate_interface_withdrawal_reasons_primary_reason_edit_path(withdrawal_reason_id: @secondary_reasons_form.withdrawal_reason_id_for_primary_redirect),
visually_hidden_text: 'primary reason for withdrawal',
) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: 'Reason details') %>
<% row.with_value do %>
<%= govuk_list(@secondary_reasons_form.review_reasons) %>
<% end %>
<% row.with_action(
text: 'Change',
href: candidate_interface_withdrawal_reasons_secondary_reasons_start_path(primary_reason: @secondary_reasons_form.primary_reason),
) %>

<% end %>
<% end %>

<%= form_with(
url: candidate_interface_withdrawal_reasons_secondary_reasons_withdraw_path(@application_choice),
method: :post,
) do |f| %>

<%= f.govuk_submit 'Yes I’m sure – withdraw this application', warning: true %>
<% end %>
<%= render CandidateInterface::WithdrawalReasons::SecondaryReasonsReviewComponent.new(
@primary_reason, application_choice: @application_choice
) %>
</div>
</div>
21 changes: 7 additions & 14 deletions config/candidate_withdrawal_reasons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,27 @@ candidate-withdrawal-reasons:
concerns-about-training-with-a-disability-or-health-condition: {}
other: {}
course-no-longer-available: {}
other:
comment: {}
other: {}
change-or-update-application-with-this-provider:
update-my-application-correct-an-error-or-add-information: {}
change-study-pattern: {}
apply-for-a-different-subject-with-the-same-provider: {}
other:
comment: {}
other: {}
apply-in-the-future:
personal-circumstances-have-changed:
concerns-about-cost-of-doing-course: {}
concerns-about-having-enough-time-to-train: {}
concerns-about-training-with-a-disability-or-health-condition: {}
other:
comment: {}
other: {}
gain-more-experience: {}
improve-qualifications: {}
other:
comment: {}
other: {}
do-not-want-to-train-anymore:
personal-circumstances-have-changed:
concerns-about-cost-of-doing-course: {}
concerns-about-having-enough-time-to-train: {}
concerns-about-training-with-a-disability-or-health-condition: {}
other:
comment: {}
other: {}
another-career-path-or-accepted-a-job-offer: {}
other:
comment: {}
other:
comment: {}
other: {}
other: {}
1 change: 1 addition & 0 deletions config/locales/candidate_interface/withdrawal_reasons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ en:
withdrawal_reasons:
success_message: You have withdrawn your application to %{provider_name}
primary_reason_title: Why are you withdrawing this application?
select_all_that_apply: Select all that apply
personal_circumstances_legend: Details about the change to your personal circumstances
reasons:
applying_to_another_provider:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
en:
withdrawal_reasons:
secondary_reasons_review_component:
submit: Yes I’m sure – withdraw this application
provider: Provider
course: Course
reason: Reason
reason_details: Reason details
change: Change
cancel: Cancel
secondary_reasons_visually_hidden_change_text: additional details for withdrawal
primary_reason_visually_hidden_change_text: primary reason for withdrawal

0 comments on commit f7354ad

Please sign in to comment.