diff --git a/app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.html.erb b/app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.html.erb new file mode 100644 index 00000000000..619b0e3849a --- /dev/null +++ b/app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.html.erb @@ -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 %> + +

+ <%= govuk_link_to( + t('cancel'), + candidate_interface_application_choices_path, + ) %> +

diff --git a/app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.rb b/app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.rb new file mode 100644 index 00000000000..4b13beeb558 --- /dev/null +++ b/app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.rb @@ -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 diff --git a/app/controllers/candidate_interface/withdrawal_reasons/secondary_reasons_controller.rb b/app/controllers/candidate_interface/withdrawal_reasons/secondary_reasons_controller.rb index 118e57cbc21..28cef31b088 100644 --- a/app/controllers/candidate_interface/withdrawal_reasons/secondary_reasons_controller.rb +++ b/app/controllers/candidate_interface/withdrawal_reasons/secondary_reasons_controller.rb @@ -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 diff --git a/app/forms/candidate_interface/withdrawal_reasons/secondary_reasons_form.rb b/app/forms/candidate_interface/withdrawal_reasons/secondary_reasons_form.rb index 6d3f1e39569..c9063f56df2 100644 --- a/app/forms/candidate_interface/withdrawal_reasons/secondary_reasons_form.rb +++ b/app/forms/candidate_interface/withdrawal_reasons/secondary_reasons_form.rb @@ -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, @@ -32,9 +34,9 @@ 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 @@ -42,17 +44,9 @@ def self.build_from_application_choice(primary_reason, application_choice) 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) @@ -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 @@ -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 @@ -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 diff --git a/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/_form.html.erb b/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/_form.html.erb index 299903e448c..55fdd6c8b21 100644 --- a/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/_form.html.erb +++ b/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/_form.html.erb @@ -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? %> diff --git a/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/review.html.erb b/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/review.html.erb index 6f444d93fab..5674aedf2d6 100644 --- a/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/review.html.erb +++ b/app/views/candidate_interface/withdrawal_reasons/secondary_reasons/review.html.erb @@ -4,43 +4,8 @@

<%= t('page_titles.decisions.withdraw') %>

- <%= 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 + ) %>
diff --git a/config/candidate_withdrawal_reasons.yml b/config/candidate_withdrawal_reasons.yml index fcc2b201fc7..40a982d6af6 100644 --- a/config/candidate_withdrawal_reasons.yml +++ b/config/candidate_withdrawal_reasons.yml @@ -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: {} diff --git a/config/locales/candidate_interface/withdrawal_reasons.yml b/config/locales/candidate_interface/withdrawal_reasons.yml index ec69a059c2f..ca0efa344b8 100644 --- a/config/locales/candidate_interface/withdrawal_reasons.yml +++ b/config/locales/candidate_interface/withdrawal_reasons.yml @@ -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: diff --git a/config/locales/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.yml b/config/locales/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.yml new file mode 100644 index 00000000000..1e0e924c5e9 --- /dev/null +++ b/config/locales/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.yml @@ -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