-
Notifications
You must be signed in to change notification settings - Fork 1
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
Passcodes | Auto submit form on paste or change when valid #3052
Conversation
79dce06
to
edd2687
Compare
@@ -8,6 +8,7 @@ import { remSpace } from '@guardian/source/foundations'; | |||
interface PasscodeInputProps extends TextInputProps { | |||
passcode?: string; | |||
fieldErrors?: FieldError[]; | |||
formRef?: React.RefObject<HTMLFormElement | null>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this ever be undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way it's currently being used, it's always defined, so will refactor that.
@@ -112,6 +112,7 @@ export const PasscodeEmailSent = ({ | |||
const [recaptchaErrorMessage, setRecaptchaErrorMessage] = useState(''); | |||
const [recaptchaErrorContext, setRecaptchaErrorContext] = | |||
useState<ReactNode>(null); | |||
const formRef = createRef<HTMLFormElement>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use useRef
instead as we're using function components
as per
https://react.dev/reference/react/createRef
![image](https://private-user-images.githubusercontent.com/21217225/409971063-0b77904d-f17c-4e29-9606-e9f0aeaa6f45.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkzNjU4MDcsIm5iZiI6MTczOTM2NTUwNywicGF0aCI6Ii8yMTIxNzIyNS80MDk5NzEwNjMtMGI3NzkwNGQtZjE3Yy00ZTI5LTk2MDYtZTlmMGFlYWE2ZjQ1LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEyVDEzMDUwN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk2NWI0MjlkNGFhMDZmOTFmNWUzNzMyZTk3YjNiODlhMWU1ZDA2NGRlMWM1ODM5MGEzYTNhODIyNzVhMWFjOWUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.pBo6huE0IhQFj-f3grh0r6zH0tUrSeNyhpExRjYMu8M)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good spot! I'll try and refactor it!
edd2687
to
9ed284a
Compare
What does this change?
Currently the reader has to manually submit the code after typing it in or pasting it in.
To make it faster for the reader, this PR updates the functionality to automatically submit the code when it reaches 6 digits long or pasting it in.
We added checks to make sure that the auto-submission is disabled for specifc scenarios
It is also disabled in scenarios where
formRef
isn't passed in.Speaking of which, a minor refactor had to be performed on the
MainForm
to makeformRef
a parameter instead. This allows us to pass in aref
for theMainForm
, so it can be used in other components, specifically in this scenario thePasscodeInput
component.Finally
PasscodeEmailSent
page was updated to create the newformRef
and pass it to bothMainForm
andPasscodeInput
Screen.Recording.2025-02-04.at.08.52.11.mov
Screen.Recording.2025-02-04.at.09.00.35.mov
Screen.Recording.2025-02-04.at.08.59.09.mov
Screen.Recording.2025-02-04.at.09.01.25.mov
Tested