Skip to content

refactor(experience): add isSubmitting guard #7343

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const IdentifierRegisterForm = ({ className, autoFocus, signUpMethods }: Props)

const onSubmitHandler = useCallback(
async (event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage();

void handleSubmit(async ({ identifier: { type, value } }) => {
Expand Down Expand Up @@ -92,6 +96,7 @@ const IdentifierRegisterForm = ({ className, autoFocus, signUpMethods }: Props)
agreeToTermsPolicy,
clearErrorMessage,
handleSubmit,
isSubmitting,
navigateToSingleSignOn,
onSubmit,
setIdentifierInputValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const IdentifierSignInForm = ({ className, autoFocus, signInMethods }: Props) =>

const onSubmitHandler = useCallback(
async (event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage();

void handleSubmit(async ({ identifier: { type, value } }) => {
Expand All @@ -96,6 +100,7 @@ const IdentifierSignInForm = ({ className, autoFocus, signInMethods }: Props) =>
agreeToTermsPolicy,
clearErrorMessage,
handleSubmit,
isSubmitting,
navigateToSingleSignOn,
onSubmit,
setIdentifierInputValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const PasswordSignInForm = ({ className, autoFocus, signInMethods }: Props) => {

const onSubmitHandler = useCallback(
async (event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage();

await handleSubmit(async ({ identifier: { type, value }, password }) => {
Expand Down Expand Up @@ -92,6 +96,7 @@ const PasswordSignInForm = ({ className, autoFocus, signInMethods }: Props) => {
agreeToTermsPolicy,
clearErrorMessage,
handleSubmit,
isSubmitting,
navigateToSingleSignOn,
onSubmit,
setIdentifierInputValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const SingleSignOnForm = ({ isTermsAndPrivacyCheckboxVisible }: Props) => {
*/
event?.preventDefault();

if (isSubmitting) {
return;
}

/**
* Check if the user has agreed to the terms and privacy policy when the policy is set to `Manual`.
*/
Expand All @@ -66,7 +70,7 @@ const SingleSignOnForm = ({ isTermsAndPrivacyCheckboxVisible }: Props) => {

await handleSubmit(async ({ identifier: { value } }) => onSubmit(value, true))(event);
},
[agreeToTermsPolicy, clearErrorMessage, handleSubmit, onSubmit, termsValidation]
[agreeToTermsPolicy, clearErrorMessage, handleSubmit, isSubmitting, onSubmit, termsValidation]
);

return (
Expand Down
6 changes: 5 additions & 1 deletion packages/experience/src/containers/SetPassword/Lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ const Lite = ({ className, autoFocus, onSubmit, errorMessage, clearErrorMessage

const onSubmitHandler = useCallback(
(event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage?.();

void handleSubmit(async (data) => {
await onSubmit(data.newPassword);
})(event);
},
[clearErrorMessage, handleSubmit, onSubmit]
[clearErrorMessage, handleSubmit, isSubmitting, onSubmit]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ const SetPassword = ({

const onSubmitHandler = useCallback(
(event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage?.();

void handleSubmit(async (data) => {
await onSubmit(data.newPassword);
})(event);
},
[clearErrorMessage, handleSubmit, onSubmit]
[clearErrorMessage, handleSubmit, isSubmitting, onSubmit]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ const IdentifierProfileForm = ({

const onSubmitHandler = useCallback(
(event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage?.();

void handleSubmit(async ({ identifier: { type, value } }) => {
Expand All @@ -72,7 +76,7 @@ const IdentifierProfileForm = ({
await onSubmit?.(type, value);
})(event);
},
[clearErrorMessage, handleSubmit, onSubmit]
[clearErrorMessage, handleSubmit, isSubmitting, onSubmit]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ const ForgotPasswordForm = ({ className, autoFocus, defaultValue = '', enabledTy

const onSubmitHandler = useCallback(
async (event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage();

void handleSubmit(async ({ identifier: { type, value } }) => {
Expand All @@ -72,7 +76,7 @@ const ForgotPasswordForm = ({ className, autoFocus, defaultValue = '', enabledTy
await onSubmit({ identifier: type, value });
})(event);
},
[clearErrorMessage, handleSubmit, onSubmit, setForgotPasswordIdentifierInputValue]
[clearErrorMessage, handleSubmit, isSubmitting, onSubmit, setForgotPasswordIdentifierInputValue]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ const PasswordForm = ({

const onSubmitHandler = useCallback(
async (event?: React.FormEvent<HTMLFormElement>) => {
if (isSubmitting) {
return;
}

clearErrorMessage();

void handleSubmit(async ({ identifier: { type, value }, password }) => {
Expand All @@ -83,7 +87,7 @@ const PasswordForm = ({
});
})(event);
},
[clearErrorMessage, handleSubmit, onSubmit, setIdentifierInputValue]
[clearErrorMessage, handleSubmit, isSubmitting, onSubmit, setIdentifierInputValue]
);

return (
Expand Down
Loading