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

[CAPT-1729] Use GOVUK formbuilder for multiple eligibility #2879

Merged
merged 1 commit into from
Jun 21, 2024
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
@@ -1,6 +1,8 @@
module Journeys
module AdditionalPaymentsForTeaching
class EligibilityConfirmedForm < Form
include ActionView::Helpers::NumberHelper

attribute :selected_claim_policy, :string

validates :selected_claim_policy, presence: {message: ->(object, _) { object.i18n_errors_path(:blank) }}
Expand All @@ -18,6 +20,16 @@ def save
journey_session.save!
end

def radio_options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

policies_eligible_now_and_sorted.map do |policy|
OpenStruct.new(
id: policy.to_s,
name: "#{award_amount_with_currency(policy)} #{policy.short_name.downcase.singularize}",
description: I18n.t("#{policy.locale_key}.purpose")
)
end
end

def single_choice_only?
eligibility_checker.single_choice_only?
end
Expand All @@ -34,6 +46,10 @@ def award_amount(policy)
policy::PolicyEligibilityChecker.new(answers: answers).calculate_award_amount
end

def award_amount_with_currency(policy)
number_to_currency(award_amount(policy), precision: 0)
end

def selected_policy?(policy)
policy.to_s == journey_session.answers.selected_policy
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,53 +1,26 @@
<%= render("shared/error_summary", instance: @form, errored_field_id_overrides: {
"selected_claim_policy": "claim_selected_claim_policy_#{@form.first_eligible_compact_policy_name}"
}) if @form.errors.any? %>
<%= form_with model: @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>

<%= form_for @form, url: claim_path(current_journey_routing_name) do |f| %>
<%= form_group_tag @form do %>
<fieldset class="govuk-fieldset">
<legend class="govuk-fieldset__legend govuk-fieldset__legend--l">
<h1 class="govuk-fieldset__heading govuk-!-padding-top-2">
Which additional payment do you want to choose?
</h1>
</legend>
<%= f.govuk_collection_radio_buttons :selected_claim_policy, @form.radio_options, :id, :name, :description,
legend: {
text: "Which additional payment do you want to choose?",
tag: "h1",
size: "l"
},
hint: {
text: "You can only make one claim per academic year. Your choice does not impact your ability to apply in future years."
} %>

<div id="payments-hint" class="govuk-hint govuk-!-padding-bottom-2">
You can only make one claim per academic year. Your choice does not impact your ability to apply in future years.
</div>

<%= errors_tag f.object, :selected_claim_policy %>

<div class="govuk-radios" id="claim_base" data-module="govuk-radios">
<% policies.each do |policy| %>
<div class="govuk-radios__item">
<%= f.radio_button(:selected_claim_policy, policy, class: "govuk-radios__input", checked: @form.selected_policy?(policy)) %>
<%= f.label "selected_claim_policy_#{policy.to_s.downcase}", "#{award_amount(@form.award_amount(policy))} #{policy_name(policy)}", class: "govuk-label govuk-radios__label" %>
<div class="govuk-hint govuk-radios__hint">
<%= t("#{policy.locale_key}.purpose") %>
</div>
</div>
<% end %>
</div>
</fieldset>
<%= govuk_details(summary_text: "Help with choosing an additional payment") do %>
For the majority of teachers, the larger payment is the most beneficial option. In rare cases, some may prefer to choose the smaller option, such as if you are close to the threshold for the higher rate of tax.
<% end %>

<details class="govuk-details" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Help with choosing an additional payment
</span>
</summary>
<div class="govuk-details__text">
For the majority of teachers, the larger payment is the most beneficial option. In rare cases, some may prefer to choose the smaller option, such as if you are close to the threshold for the higher rate of tax.
</div>
</details>

<%= f.submit "Apply now", class: "govuk-button", data: { module: "govuk-button" } %>
<%= f.govuk_submit "Apply now" %>
<% end %>

<p class="govuk-body">
For more information about why you are eligible for different additional payments, read about the
<%= link_to "early-career payments (opens in new tab)", Policies::EarlyCareerPayments.eligibility_page_url, class: "govuk-link govuk-link--no-visited-state", target: "_blank" %>
<%= govuk_link_to "early-career payments", Policies::EarlyCareerPayments.eligibility_page_url, no_visited_state: true, new_tab: true %>
and
<%= link_to "levelling up premium payments (opens in new tab)", Policies::LevellingUpPremiumPayments.eligibility_page_url, class: "govuk-link govuk-link--no-visited-state", target: "_blank" %>.
<%= govuk_link_to "levelling up premium payments", Policies::LevellingUpPremiumPayments.eligibility_page_url, no_visited_state: true, new_tab: true %>.
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% if @form.single_choice_only? %>
<%= render partial: "eligibility_confirmed_single", locals: { policy: @form.policies_eligible_now.first } %>
<% else %>
<%= render partial: "eligibility_confirmed_multiple", locals: { policies: @form.policies_eligible_now_and_sorted } %>
<%= render "eligibility_confirmed_multiple" %>
<% end %>
</div>
</div>