Skip to content

Render incorrect verify-by-mail OTP error inline#10329

Merged
jmhooper merged 4 commits intomainfrom
jmhooper-render-gpo-otp-error-correctly
Mar 28, 2024
Merged

Render incorrect verify-by-mail OTP error inline#10329
jmhooper merged 4 commits intomainfrom
jmhooper-render-gpo-otp-error-correctly

Conversation

@jmhooper
Copy link
Contributor

Prior to this commit the verify-by-mail OTP submission would add errors to the flash and redirect to the OTP entry path. This lead to a couple problems:

  1. The error for the OTP appeared in the flash instead of on the OTP field
  2. The did_not_receive_letter param was not sticky i.e. when a user submitted the OTP it would switch back to the “Welcome back” UI. This was because the param was not present on the redirected URL.

This commit changes the implementation to closer match what we would expect from a controller using the Form Object Pattern. Specifically the #create action no longer redirects, but renders the index template with the GpoVerifyForm that was used for submission and thus has all of the errors and context for the submission.

One wrinkle with this approach is I had to set the @can_request_another_letter, @user_did_not_receive_letter, and @last_date_letter_was_sent ivars in the create action and in the index action. I opted to add a #render_enter_code_form method which handles setting up these ivars and rendering the index template.

I also had to add a hidden input to the form with the did_not_receive_letter param so it appears in the params on submission.

Here is what the form looked like before:

image

Here is what it looks like now:

image

@jmhooper jmhooper requested a review from a team March 27, 2024 20:09
Copy link
Contributor

@matthinz matthinz left a comment

Choose a reason for hiding this comment

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

LGTM

Prior to this commit the verify-by-mail OTP submission would add errors to the flash and redirect to the OTP entry path. This lead to a couple problems:

1. The error for the OTP appeared in the flash instead of on the OTP field
2. The `did_not_receive_letter` param was not sticky i.e. when a user submitted the OTP it would switch back to the “Welcome back” UI. This was because the param was not present on the redirected URL.

This commit changes the implementation to closer match what we would expect from a controller using the [Form Object Pattern](https://dev.to/drbragg/rails-design-patterns-form-object-4d47). Specifically the `#create` action no longer redirects, but renders the `index` template with the `GpoVerifyForm` that was used for submission and thus has all of the eros and context for the submission in the `@gpo_verify_form` ivar.

One wrinkle with this approach is I had to set the `@can_request_another_letter`, `@user_did_not_receive_letter`, and `@last_date_letter_was_sent` ivars in the create action and in the index action. I opted to add a `#render_enter_code_form` method which handles setting up these ivars and rendering the index template.

[skip changelog]
@jmhooper jmhooper force-pushed the jmhooper-render-gpo-otp-error-correctly branch from f851d7a to f9a627a Compare March 27, 2024 20:20
@aduth
Copy link
Contributor

aduth commented Mar 28, 2024

Love the use of the form object here to automatically show errors on related fields 👍

Visually, I'd wonder if there'd be any UX feedback about the width constraints resulting in line breaks. This is some custom code we added a while back that I've been eyeing to remove since it's weird to apply the styling in JavaScript, and IMO doesn't always look great in practice.

@jmhooper
Copy link
Contributor Author

jmhooper commented Mar 28, 2024

Visually, I'd wonder if there'd be any UX feedback about the width constraints resulting in line breaks. This is some custom code we added a while back that I've been eyeing to remove since it's weird to apply the styling in JavaScript, and IMO doesn't always look great in practice.

Are you suggesting I remove this JS here or is there an alternative approach I can take to tweak the styling? Now that you point it out I can't unsee it.

@aduth
Copy link
Contributor

aduth commented Mar 28, 2024

Are you suggesting I remove this JS here or is there an alternative approach I can take to tweak the styling? Now that you point it out I can't unsee it.

I don't think we need to do it here, but in case it's noted as a point of feedback, that'd be the easiest solution. It'd apply everywhere so we might want to think through potential impact or look back at the initial context where it was added, but I feel like it'd be generally safe since I think it's cosmetic at-worst.

@jmhooper
Copy link
Contributor Author

@aduth: I just pushed a tweak to make the error message shorter so it won't wrap in most cases. I think that should do it.

@jmhooper jmhooper merged commit fc201da into main Mar 28, 2024
@jmhooper jmhooper deleted the jmhooper-render-gpo-otp-error-correctly branch March 28, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants