Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[426] candidate withdrawal reasons list refinement and mandatory #10191

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<% if show_withdraw? %>
<h2 class="govuk-heading-m">Withdraw your application</h2>
<p class="govuk-body">You can <%= govuk_link_to 'withdraw this application', candidate_interface_withdraw_path(application_choice) %> if you no longer wish to be considered for this course.</p>
<p class="govuk-body">You can <%= govuk_link_to 'withdraw this application', path_for_withdrawals %> if you no longer wish to be considered for this course.</p>
<% end %>

<% if show_provider_contact_component? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,13 @@ def can_add_more_choices?
def provider
application_choice.current_provider
end

def path_for_withdrawals
elceebee marked this conversation as resolved.
Show resolved Hide resolved
if FeatureFlag.active?(:new_candidate_withdrawal_reasons)
candidate_interface_withdrawal_reasons_level_one_reason_new_path(application_choice)
else
candidate_interface_withdraw_path(application_choice)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<span class="govuk-visually-hidden"> <%= application_choice.current_course.name_and_code %></span>
<% end %>
<% elsif withdrawable?(application_choice) %>
<%= govuk_link_to candidate_interface_withdraw_path(application_choice.id), data: { action: :withdraw } do %>
<%= govuk_link_to path_for_withdrawals(application_choice), data: { action: :withdraw } do %>
<%= t('application_form.courses.withdraw') %>
<span class="govuk-visually-hidden"> <%= application_choice.current_course.name_and_code %></span>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def application_choices
end
end

def path_for_withdrawals(application_choice)
if FeatureFlag.active? :new_candidate_withdrawal_reasons
candidate_interface_withdrawal_reasons_level_one_reason_new_path(application_choice)
else
candidate_interface_withdraw_path(application_choice)
end
end

private

attr_reader :application_form
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if action == :withdraw %>
<p class="govuk-body">
<%= govuk_link_to 'Withdraw this application', candidate_interface_withdraw_path(application_choice.id) %>
<%= govuk_link_to 'Withdraw this application', path_for_withdrawals %>
</p>
<% elsif action == :respond_to_offer %>
<p class="govuk-body">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ def initialize(action:, application_choice:)
@action = action
@application_choice = application_choice
end

def path_for_withdrawals
if FeatureFlag.active? :new_candidate_withdrawal_reasons
candidate_interface_withdrawal_reasons_level_one_reason_new_path(application_choice.id)
else
candidate_interface_withdraw_path(application_choice.id)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<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: t('withdrawal_reasons.level_one_reason_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.level_one_reason_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.level_one_reason_review_component.reason')) %>
<% row.with_value(text: level_one_reason_text) %>
<% row.with_action(
text: t('withdrawal_reasons.level_one_reason_review_component.change'),
href: candidate_interface_withdrawal_reasons_level_one_reason_edit_path,
visually_hidden_text: t('withdrawal_reasons.level_one_reason_review_component.visually_hidden_change_text'),
) %>
<% end %>
<% end %>

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

<%= f.govuk_submit t('withdrawal_reasons.level_one_reason_review_component.submit'), 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,23 @@
module CandidateInterface
module WithdrawalReasons
class LevelOneReasonReviewComponent < ViewComponent::Base
def initialize(application_choice:, withdrawal_reason:)
@application_choice = application_choice
@withdrawal_reason = withdrawal_reason
end

def level_one_reason_text
[translate("#{withdrawal_reason.reason}.label"), withdrawal_reason.comment].join(': ')
end

private

attr_reader :application_choice, :withdrawal_reason

def translate(string)
string.gsub!('-', '_')
I18n.t("candidate_interface.withdrawal_reasons.reasons.#{string}")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<%= govuk_summary_list do |summary_list| %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t('withdrawal_reasons.level_two_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.level_two_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.level_two_reasons_review_component.reason')) %>
<% row.with_value(text: level_one_reason_text) %>
<% row.with_action(
text: t('withdrawal_reasons.level_two_reasons_review_component.change'),
href: candidate_interface_withdrawal_reasons_level_one_reason_edit_path(withdrawal_reason_id: redirect_id),
visually_hidden_text: t('withdrawal_reasons.level_two_reasons_review_component.level_one_reason_visually_hidden_change_text'),
) %>
<% end %>
<% summary_list.with_row do |row| %>
<% row.with_key(text: t('withdrawal_reasons.level_two_reasons_review_component.reason_details')) %>
<% row.with_value do %>
<%= govuk_list(reason_details) %>
<% end %>
<% row.with_action(
text: t('withdrawal_reasons.level_two_reasons_review_component.change'),
href: candidate_interface_withdrawal_reasons_level_two_reasons_new_path(level_one_reason: @level_one_reason),
visually_hidden_text: t('withdrawal_reasons.level_two_reasons_review_component.level_two_reasons_visually_hidden_change_text'),
) %>
<% end %>
<% end %>

<%= form_with(
url: candidate_interface_withdrawal_create_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 LevelTwoReasonsReviewComponent < ViewComponent::Base
def initialize(level_one_reason, application_choice:)
@application_choice = application_choice
@level_one_reason = level_one_reason
end

def level_one_reason_text
translate("#{@level_one_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.by_level_one_reason(@level_one_reason)
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("#{@level_one_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

def personal_circumstances_key
WithdrawalReason::PERSONAL_CIRCUMSTANCES_KEY
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module CandidateInterface
module WithdrawalReasons
class LevelOneReasonsController < WithdrawalsController
before_action :set_draft_reason, only: %i[show edit create]
before_action :clear_earlier_drafts, only: %i[show]

def show
@level_one_reasons_form = LevelOneReasonsForm.build_from_reason(@level_one_reason)
end

def new
@level_one_reasons_form = LevelOneReasonsForm.new({ level_one_reason: level_one_reason_params[:level_one_reason] })
end

def edit
@level_one_reasons_form = LevelOneReasonsForm.build_from_reason(@level_one_reason)
end

def create
attributes = @level_one_reason.present? ? form_params.merge(id: @level_one_reason.id) : form_params
@level_one_reasons_form = LevelOneReasonsForm.new(attributes, application_choice: @application_choice)

if @level_one_reasons_form.invalid?
render :new
elsif @level_one_reasons_form.ready_for_review?
draft_withdrawal_reason = @level_one_reasons_form.persist!
redirect_to candidate_interface_withdrawal_reasons_level_one_reason_show_path(
withdrawal_reason_id: draft_withdrawal_reason.id,
)
else
redirect_to candidate_interface_withdrawal_reasons_level_two_reasons_new_path(
level_one_reason: @level_one_reasons_form.level_one_reason,
)
end
end

private

def form_params
params.require(:candidate_interface_withdrawal_reasons_level_one_reasons_form).permit(:level_one_reason, :comment)
end

def set_draft_reason
if withdrawal_reason_id.positive?
@level_one_reason = @application_choice.draft_withdrawal_reasons.find(withdrawal_reason_id)
end
end

def clear_earlier_drafts
@application_choice.draft_withdrawal_reasons.where.not(id: withdrawal_reason_id).destroy_all
end

def withdrawal_reason_id
params[:withdrawal_reason_id].to_i
end

def level_one_reason_params
params.permit(:level_one_reason)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module CandidateInterface
module WithdrawalReasons
class LevelTwoReasonsController < WithdrawalsController
def show
@level_one_reason = level_one_reason
end

def new
@level_two_reasons_form = LevelTwoReasonsForm.build_from_application_choice(level_one_reason, @application_choice)
end

def create
@level_two_reasons_form = LevelTwoReasonsForm.new(form_params, application_choice: @application_choice)
if @level_two_reasons_form.valid?
@level_two_reasons_form.persist!
redirect_to candidate_interface_withdrawal_reasons_level_two_reasons_show_path
else
render :new
end
end

private

def form_params
params.require(:candidate_interface_withdrawal_reasons_level_two_reasons_form)
.permit(:comment, :personal_circumstances_reasons_comment, level_two_reasons: [], personal_circumstances_reasons: [])
.merge({ level_one_reason: })
end

def level_one_reason
params[:level_one_reason]
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module CandidateInterface
module WithdrawalReasons
class WithdrawalsController < CandidateInterfaceController
before_action :set_application_choice
before_action :check_that_candidate_can_withdraw

def create
WithdrawApplication.new(application_choice: @application_choice).save!
flash[:success] = I18n.t(
'candidate_interface.withdrawal_reasons.success_message',
provider_name: @application_choice.current_course_option.provider.name,
)
redirect_to candidate_interface_application_choices_path
end

private

def set_application_choice
@application_choice = @current_application.application_choices.find(params[:id])
end

def check_that_candidate_can_withdraw
unless ApplicationStateChange.new(@application_choice).can_withdraw?
render_404
end
end
end
end
end
Loading
Loading