Passwordless | Add countdown timer to "send again" functionality #3045
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this change?
A number of users are complaining that they're getting multiple passcodes to their email, each time with a different code, and the original code no longer valid.
We think this is due to delays in the user receiving the email
So rather than allow the user to resend the passcode straight away, we added a countdown timer so that they can only do it after a specificed amount of time, currently set to 30 seconds.
We've only enabled this for passcode users, as the same problem doesn't occur with links.
We also update the
MainForm
component to take adisabled
value.A new hook provides the countdown functionality on the client side:
useCountdownTimer
This hook takes a
durationInSeconds
parameter to start the countdown, and returns thetimeRemaining
in seconds, and anisComplete
boolean.This is then integrated withing the
EmailSentInformationBox
component, which houses the "send again" functionality. Where it takes a newsendAgainTimerInSeconds
prop in order to control it.In turn the same thing was applied to
PasscodeEmailSent
component which uses theEmailSentInformationBox
, followed by the pages that use thePasscodeEmailSent
component.Finally in order to set the timer, rather than harcode the value everywhere, we add it to the
ClientState
andPageData
objects. This allows us to only set it in one place (throughgetRequestState
), but also lets us modify the value specifically for tests, i.e Cypress. AgetPasscodeSendAgainTimer
helper function helps with this.Screen.Recording.2025-01-27.at.13.04.40.mov
Tested