Skip to content

Commit

Permalink
fix: multiple bookings created on verify-email (#12864)
Browse files Browse the repository at this point in the history
Co-authored-by: Rajiv Sahal <[email protected]>
  • Loading branch information
SomayChauhan and Ryukemeister authored Dec 19, 2023
1 parent 2e0c9c7 commit 6ce2d98
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/features/bookings/components/VerifyCodeDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const VerifyCodeDialog = ({
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState("");
const [value, setValue] = useState("");
const [hasVerified, setHasVerified] = useState(false);

const digits = useDigitInput({
acceptedCharacters: /^[0-9]$/,
Expand Down Expand Up @@ -77,6 +78,7 @@ export const VerifyCodeDialog = ({
email,
});
}
setHasVerified(true);
}, [
email,
isUserSessionRequiredToVerify,
Expand All @@ -89,10 +91,10 @@ export const VerifyCodeDialog = ({
// trim the input value because "react-digit-input" creates a string of the given length,
// even when some digits are missing. And finally we use regex to check if the value consists
// of 6 non-empty digits.
if (error || isLoading || !/^\d{6}$/.test(value.trim())) return;
if (hasVerified || error || isLoading || !/^\d{6}$/.test(value.trim())) return;

verifyCode();
}, [error, isLoading, value, verifyCode]);
}, [error, isLoading, value, verifyCode, hasVerified]);

useEffect(() => setValue(""), [isOpenDialog]);

Expand Down

0 comments on commit 6ce2d98

Please sign in to comment.