Skip to content

Commit

Permalink
[LUPEYALPHA-1075] Early Years Practitioner mobile number (#3293)
Browse files Browse the repository at this point in the history
* Early Years Practitioner mobile number
* fix resend passcode functionality
* fix bug - clear mobile number when answer changed to "Would you like to provide your mobile number?"
  • Loading branch information
alkesh authored Oct 17, 2024
1 parent 2106ef3 commit e896389
Show file tree
Hide file tree
Showing 33 changed files with 471 additions and 178 deletions.
3 changes: 2 additions & 1 deletion app/forms/email_address_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class EmailAddressForm < Form
attribute :email_address
attribute :resend, :boolean

validates :email_address,
presence: {
Expand All @@ -18,7 +19,7 @@ class EmailAddressForm < Form

def save
return false unless valid?
return true unless email_address_changed?
return true unless email_address_changed? || resend

journey_session.answers.assign_attributes(
email_address: email_address,
Expand Down
5 changes: 3 additions & 2 deletions app/forms/mobile_number_form.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class MobileNumberForm < Form
attribute :mobile_number
attribute :resend, :boolean

validates :mobile_number,
presence: {
Expand All @@ -15,7 +16,7 @@ class MobileNumberForm < Form

def save
return false unless valid?
return true unless mobile_number_changed?
return true unless mobile_number_changed? || resend

sent_one_time_password_at = if send_sms_message
Time.now
Expand All @@ -37,7 +38,7 @@ def save

def send_sms_message
if Rails.env.development?
Rails.logger.info("SMS CODE: #{OneTimePassword::Generator.new.code}")
Rails.logger.info("\n\nSMS CODE: #{OneTimePassword::Generator.new.code}\n")
return true
end

Expand Down
1 change: 1 addition & 0 deletions app/forms/provide_mobile_number_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def save

if provide_mobile_number_changed?
journey_session.answers.assign_attributes(mobile_verified: nil)
journey_session.answers.assign_attributes(mobile_number: nil) unless provide_mobile_number
end

journey_session.answers.assign_attributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ class SlugSequence
email-address
email-verification
provide-mobile-number
mobile-number
mobile-verification
personal-bank-account
gender
check-your-answers
].freeze

RESULTS_SLUGS = %w[
check-your-answers
ineligible
].freeze

Expand All @@ -35,7 +37,12 @@ def initialize(journey_session)
end

def slugs
SLUGS
SLUGS.dup.tap do |sequence|
if answers.provide_mobile_number == false
sequence.delete("mobile-number")
sequence.delete("mobile-verification")
end
end
end
end
end
Expand Down
38 changes: 38 additions & 0 deletions app/views/claims/_email_address.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<% content_for(
:page_title,
page_title(
@form.t("label"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %>
<%= f.govuk_error_summary %>
<% caption_settings = { text: t("questions.personal_details"), size: "xl" } if show_caption %>
<%= f.govuk_text_field :email_address,
autocomplete: "email",
spellcheck: "false",
caption: caption_settings,
label: {
text: @form.t("label"),
tag: "h1",
size: heading_size
},
hint: -> do %>
<p><%= @form.t("hint1") %></p>
<p><%= @form.t("hint2") %></p>
<% end %>
<%= f.hidden_field :resend, value: params[:resend] %>
<% if show_help_with_access_codes %>
<%= render "help_with_access_codes", communication_type: "Email" %>
<% end %>
<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
32 changes: 32 additions & 0 deletions app/views/claims/_mobile_number.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<% content_for(
:page_title,
page_title(
t("questions.mobile_number"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>
<% caption_settings = { text: t("questions.personal_details"), size: "xl" } if show_caption %>
<%= f.govuk_phone_field :mobile_number,
spellcheck: "false",
caption: caption_settings,
label: {
text: t("questions.mobile_number"),
tag: "h1",
size: heading_size,
},
hint: { text: "To verify your mobile number we will send you a text message with a 6-digit passcode. You can enter the passcode on the next screen." } %>
<%= f.hidden_field :resend, value: params[:resend] %>
<%= render "help_with_access_codes", communication_type: "Mobile" %>
<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
4 changes: 2 additions & 2 deletions app/views/claims/_one_time_password.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

<div class="govuk-!-margin-bottom-6">
<% if email_or_mobile == "email" %>
<%= govuk_link_to "Resend passcode (you will be sent back to the email address page)", claim_path(current_journey_routing_name, "email-address"), no_visited_state: true %>
<%= govuk_link_to "Resend passcode (you will be sent back to the email address page)", claim_path(current_journey_routing_name, "email-address", resend: true), no_visited_state: true %>
<% else %>
<%= govuk_link_to "Resend passcode (you will be sent back to the mobile number page)", claim_path(current_journey_routing_name, "mobile-number"), no_visited_state: true %>
<%= govuk_link_to "Resend passcode (you will be sent back to the mobile number page)", claim_path(current_journey_routing_name, "mobile-number", resend: true), no_visited_state: true %>
<% end %>
</div>

Expand Down
23 changes: 23 additions & 0 deletions app/views/claims/_provide_mobile_number.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% content_for(:page_title, page_title(t("questions.provide_mobile_number"), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>
<% caption_settings = { text: t("questions.personal_details"), size: "xl" } if show_caption %>
<%= f.govuk_collection_radio_buttons :provide_mobile_number, @form.radio_options, :id, :name,
caption: caption_settings,
legend: {
text: t("questions.provide_mobile_number"),
tag: "h1",
size: "l"
},
hint: {
text: "We will only use this number if we are unable to contact you via email. It may slow down your application if we are unable to reach you."
} %>
<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
38 changes: 1 addition & 37 deletions app/views/claims/email_address.html.erb
Original file line number Diff line number Diff line change
@@ -1,37 +1 @@
<% content_for(
:page_title,
page_title(
t("questions.email_address"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_text_field :email_address,
autocomplete: "email",
spellcheck: "false",
caption: {
text: t("questions.personal_details"),
size: "xl"
},
label: {
text: t("questions.email_address"),
tag: "h1",
size: "xl"
},
hint: -> do %>
<p><%= I18n.t("questions.email_address_hint1") %></p>
<p><%= I18n.t("questions.email_address_hint2") %></p>
<% end %>
<%= render "help_with_access_codes", communication_type: "Email" %>
<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
<%= render partial: "email_address", locals: { show_caption: true, heading_size: "xl", show_help_with_access_codes: true } %>
34 changes: 1 addition & 33 deletions app/views/claims/mobile_number.html.erb
Original file line number Diff line number Diff line change
@@ -1,33 +1 @@
<% content_for(
:page_title,
page_title(
t("questions.mobile_number"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_phone_field :mobile_number,
spellcheck: "false",
caption: {
text: t("questions.personal_details"),
size: "xl"
},
label: {
text: t("questions.mobile_number"),
tag: "h1",
size: "xl",
},
hint: { text: "To verify your mobile number we will send you a text message with a 6-digit passcode. You can enter the passcode on the next screen." } %>
<%= render "help_with_access_codes", communication_type: "Mobile" %>
<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
<%= render partial: "mobile_number", locals: { show_caption: true, heading_size: "xl" } %>
26 changes: 1 addition & 25 deletions app/views/claims/provide_mobile_number.html.erb
Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
<% content_for(:page_title, page_title(t("questions.provide_mobile_number"), journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_with model: @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_collection_radio_buttons :provide_mobile_number, @form.radio_options, :id, :name,
caption: {
text: t("questions.personal_details"),
size: "xl"
},
legend: {
text: t("questions.provide_mobile_number"),
tag: "h1",
size: "l"
},
hint: {
text: "We will only use this number if we are unable to contact you via email. It may slow down your application if we are unable to reach you."
} %>
<%= f.govuk_submit "Continue" %>
<% end %>
</div>
</div>
<%= render partial: "provide_mobile_number", locals: { show_caption: true} %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
<% content_for(:page_title, page_title("Your email address", journey: current_journey_routing_name, show_error: @form.errors.any?)) %>

<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds">
<%= form_for @form, url: claim_path(current_journey_routing_name), builder: GOVUKDesignSystemFormBuilder::FormBuilder, html: { novalidate: false } do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_text_field :email_address,
autocomplete: "email",
spellcheck: "false",
label: {
text: @form.t("label"),
tag: "h1",
size: "l"
},
hint: -> do %>
<p><%= @form.t("hint1") %></p>
<p><%= @form.t("hint2") %></p>
<% end %>
<%= f.govuk_submit %>
<% end %>
</div>
</div>
<%= render partial: "email_address", locals: { show_caption: false, heading_size: "l", show_help_with_access_codes: false } %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "mobile_number", locals: { show_caption: false, heading_size: "l" } %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% content_for(
:page_title,
page_title(
t("one_time_password.title"),
journey: current_journey_routing_name,
show_error: @form.errors.any?
)
) %>
<%= render(
partial: "one_time_password",
locals: {
form: @form,
current_journey_routing_name: current_journey_routing_name,
email_or_mobile: "mobile",
email_or_text_message: "a text message",
show_caption: false
}
) %>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render partial: "provide_mobile_number", locals: { show_caption: false} %>
11 changes: 6 additions & 5 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ en:
no_address_found: "No addresses found matching those details"
date_of_birth: "What is your date of birth?"
email_address: "Email address"
email_address_hint1:
"We recommend you use a non-work email address in case your circumstances change while we process your payment."
email_address_hint2:
"To verify your email address we will send you an email with a 6-digit passcode. You can enter the passcode on the
next screen."
provide_mobile_number: "Would you like to provide your mobile number?"
mobile_number: "Mobile number"
personal_details: "Personal details"
Expand Down Expand Up @@ -265,6 +260,12 @@ en:
select_email: Select an option to indicate whether the email is correct or not
invalid_email: Invalid email address. Please select a different email address
email_address:
label: "Email address"
hint1:
"We recommend you use a non-work email address in case your circumstances change while we process your payment."
hint2:
"To verify your email address we will send you an email with a 6-digit passcode. You can enter the passcode on the
next screen."
errors:
presence: "Enter an email address"
format: "Enter an email address in the correct format, like [email protected]"
Expand Down
Loading

0 comments on commit e896389

Please sign in to comment.