Skip to content
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

Applying new style and fixing timeout #4940

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Changes from all commits
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
33 changes: 27 additions & 6 deletions src/components/InputUserEmailVerify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,32 @@ const InputUserEmailVerify = forwardRef<HTMLInputElement, InputType>(
// It will send request to backend to check if email exists and if it's not verified yet
// or email is already exist on another user account
// If email isn't verified it will send email with verification code to user
let intervalId: NodeJS.Timeout;
const intervalIdRef = useRef<NodeJS.Timeout | null>(null);

const verificationEmailHandler = async () => {
// Prevent the button from being clicked during cooldown
if (isCooldown) {
return;
}

// Clear any existing interval
if (intervalIdRef.current) {
clearInterval(intervalIdRef.current);
}

// Start cooldown timer
setIsCooldown(true);
setCooldownTime(180);

intervalId = setInterval(() => {
intervalIdRef.current = setInterval(() => {
setCooldownTime(prev => {
if (prev <= 1) {
resetCoolDown();
setDisableVerifyButton(false);
if (intervalIdRef.current) {
clearInterval(intervalIdRef.current);
intervalIdRef.current = null;
}
return 0;
}
return prev - 1;
Expand Down Expand Up @@ -290,7 +299,10 @@ const InputUserEmailVerify = forwardRef<HTMLInputElement, InputType>(
}
} catch (error) {
if (error instanceof Error) {
clearInterval(intervalId);
if (intervalIdRef.current) {
clearInterval(intervalIdRef.current);
intervalIdRef.current = null;
}
kkatusic marked this conversation as resolved.
Show resolved Hide resolved
resetCoolDown();
showToastError(error.message);
}
Expand Down Expand Up @@ -339,7 +351,10 @@ const InputUserEmailVerify = forwardRef<HTMLInputElement, InputType>(
resetCoolDown();

// Clear interval when fetch is done
clearInterval(intervalId);
if (intervalIdRef.current) {
clearInterval(intervalIdRef.current);
intervalIdRef.current = null;
}
}
} catch (error) {
if (error instanceof Error) {
Expand Down Expand Up @@ -514,7 +529,7 @@ const InputUserEmailVerify = forwardRef<HTMLInputElement, InputType>(
</button>
),
time: () => (
<b>
<CoolDownTime>
{Math.floor(
cooldownTime / 60,
)}
Expand All @@ -523,7 +538,7 @@ const InputUserEmailVerify = forwardRef<HTMLInputElement, InputType>(
'0' +
(cooldownTime % 60)
).slice(-2)}
</b>
</CoolDownTime>
),
}}
/>
Expand Down Expand Up @@ -755,4 +770,10 @@ const InputCodeDesc = styled(GLink)`
}
`;

const CoolDownTime = styled.strong`
color: ${brandColors.giv[500]};
font-size: 0.785rem;
line-height: 1.1;
`;

export default InputUserEmailVerify;
Loading