Skip to content

Commit

Permalink
Adds check your answers form
Browse files Browse the repository at this point in the history
This form doesn't perform any validations and save isn't called on the
form so we have an empty form object, however this form object is still
required. The check your answers page is submitted to the claim
submission controller, which does perform validations, and if the
validation fails the check your answers rerenders with the claim
submission form. Rather than mapping "check-your-answers" to the
`ClaimSubmissionForm` we instead use the "empty" `CheckYourAnswersForm`
so we can avoid changing the api of the `ClaimSubmissionForm` just to
make it compatable with the `Form` base class, ie the
`ClaimSubmissionForm` doesn't need any of the parameters passed to `Form`
subclasses in `Journeys::Base` module, it just needs an instance of
`Journeys::Session`.

Also of note we've had to introduce a conditional in the
BaseAnswersPresenter as we need this to work with both a `CurrentClaim`
and a `Claim`. When dealing with a `CurrentClaim` (`check-your-answers`
rendered from the `ClaimController#show`) we can't always assume the
eligibility is eligible. We also rander the `check-your-answers` page
from the `SubmissionController#create` action if the form is invalid, in
which case we'll be working with a `Claim`. We want to avoid adding
`eligible_eligibility` to the `Claim`. Once we've removed `CurrentClaim`
we can remove this conditional.
  • Loading branch information
rjlynch committed May 13, 2024
1 parent 9f74b96 commit 066c234
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 12 deletions.
1 change: 0 additions & 1 deletion app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def create
clear_claim_session
redirect_to claim_confirmation_path
else
current_claim.valid?(:submit)
render "claims/check_your_answers"
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/forms/check_your_answers_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class CheckYourAnswersForm < Form
end
3 changes: 2 additions & 1 deletion app/models/journeys/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module Base
"personal-bank-account" => BankDetailsForm,
"building-society-account" => BankDetailsForm,
"teacher-reference-number" => TeacherReferenceNumberForm,
"address" => AddressForm
"address" => AddressForm,
"check-your-answers" => CheckYourAnswersForm
}

def configuration
Expand Down
7 changes: 6 additions & 1 deletion app/models/journeys/base_answers_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ class BaseAnswersPresenter

def initialize(claim)
@claim = claim
@eligibility = claim.eligible_eligibility

@eligibility = if @claim.is_a?(CurrentClaim)
claim.eligible_eligibility
else
claim.eligibility
end
end

def identity_answers
Expand Down
17 changes: 13 additions & 4 deletions app/views/additional_payments/claims/check_your_answers.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
<% content_for(:page_title, page_title("Check your answers before sending your application", journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %>
<% content_for(
:page_title,
page_title(
"Check your answers before sending your application",
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render("shared/error_summary", instance: current_claim) if current_claim.errors.any? %>
<% if @form.errors.any? %>
<%= render("shared/error_summary", instance: @form) %>
<% end %>

<h1 class="govuk-heading-xl">
Check your answers before sending your application
</h1>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Identity details", answers: journey.answers_for_claim(current_claim).identity_answers} %>
<%= render partial: "claims/check_your_answers_section", locals: {heading: "Identity details", answers: journey.answers_for_claim(@form.claim).identity_answers} %>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Payment details", answers: journey.answers_for_claim(current_claim).payment_answers} %>
<%= render partial: "claims/check_your_answers_section", locals: {heading: "Payment details", answers: journey.answers_for_claim(@form.claim).payment_answers} %>

<%= form_with url: claim_submission_path do |form| %>
<h2 class="govuk-heading-m"><%= t("additional_payments.check_your_answers.heading_send_application") %></h2>
Expand Down
19 changes: 14 additions & 5 deletions app/views/student_loans/claims/check_your_answers.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
<% content_for(:page_title, page_title("Check your answers before sending your application", journey: current_journey_routing_name, show_error: current_claim.errors.any?)) %>
<% content_for(
:page_title,
page_title(
"Check your answers before sending your application",
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= render("shared/error_summary", instance: current_claim) if current_claim.errors.any? %>
<% if @form.errors.any? %>
<%= render("shared/error_summary", instance: @form) %>
<% end %>

<h1 class="govuk-heading-xl">
Check your answers before sending your application
</h1>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Eligibility details", answers: journey.answers_for_claim(current_claim).eligibility_answers} %>
<%= render partial: "claims/check_your_answers_section", locals: {heading: "Eligibility details", answers: journey.answers_for_claim(@form.claim).eligibility_answers} %>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Identity details", answers: journey.answers_for_claim(current_claim).identity_answers} %>
<%= render partial: "claims/check_your_answers_section", locals: {heading: "Identity details", answers: journey.answers_for_claim(@form.claim).identity_answers} %>

<%= render partial: "claims/check_your_answers_section", locals: {heading: "Payment details", answers: journey.answers_for_claim(current_claim).payment_answers} %>
<%= render partial: "claims/check_your_answers_section", locals: {heading: "Payment details", answers: journey.answers_for_claim(@form.claim).payment_answers} %>

<%= form_with url: claim_submission_path do |form| %>
<h2 class="govuk-heading-m"><%= t("check_your_answers.heading_send_application") %></h2>
Expand Down

0 comments on commit 066c234

Please sign in to comment.