fix: send code button behavior on enter key press (#1121)

This commit is contained in:
Anmol Singh Bhatia 2023-05-25 12:19:48 +05:30 committed by GitHub
parent def391cb76
commit 74329a49cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,6 +88,25 @@ export const EmailCodeForm = ({ onSuccess }: any) => {
setErrorResendingCode(false);
}, [emailOld]);
useEffect(() => {
const submitForm = (e: KeyboardEvent) => {
if (!codeSent && e.key === "Enter") {
e.preventDefault();
handleSubmit(onSubmit)().then(() => {
setResendCodeTimer(30);
});
}
};
if (!codeSent) {
window.addEventListener("keydown", submitForm);
}
return () => {
window.removeEventListener("keydown", submitForm);
};
}, [handleSubmit, codeSent]);
return (
<>
<form className="space-y-5 py-5 px-5">