Skip to content

Commit

Permalink
fix: improve form submission logic and loading state handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffreyArt1 committed Feb 5, 2025
1 parent 1acb349 commit b03884f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/app/[lang]/register/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,23 @@ export function Form({ cedula, flow, returnTo }: FormProps) {
<form
action={action}
onSubmit={async (e) => {
setLoading(true);
if (!isValid) {
e.preventDefault();
e.preventDefault();

if (!isValid) {
await trigger();
return false;
setLoading(false);
return;
}

checkPwned(password).then(setIsPwned);
e.currentTarget.requestSubmit();
setLoading(true);
const pwned = await checkPwned(password);
setIsPwned(pwned);

if (!pwned) {
(e.target as HTMLFormElement).submit();
} else {
setLoading(false);
}
}}
>
<input type="hidden" name="flow" value={flow} />
Expand Down

0 comments on commit b03884f

Please sign in to comment.