-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
9 changed files
with
137 additions
and
117 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...onents/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.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,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> |
59 changes: 59 additions & 0 deletions
59
app/components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.rb
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,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 |
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
2 changes: 1 addition & 1 deletion
2
app/views/candidate_interface/withdrawal_reasons/secondary_reasons/_form.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
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
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
12 changes: 12 additions & 0 deletions
12
.../components/candidate_interface/withdrawal_reasons/secondary_reasons_review_component.yml
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,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 |