diff options
| author | Joe Carstairs <me@joeac.net> | 2025-12-18 11:04:03 +0000 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2025-12-18 11:04:03 +0000 |
| commit | 46c9b7731622f1f4d0f6a03c3179e747e0ce065d (patch) | |
| tree | 71c60d9cf72797b06054a61990f7baa41db2e8a0 /website/src/scripts/contact/reset-resend-button.ts | |
| parent | 40d6c7f248c3fe506690ee3ccb3894f952e164ed (diff) | |
contact page
Diffstat (limited to 'website/src/scripts/contact/reset-resend-button.ts')
| -rw-r--r-- | website/src/scripts/contact/reset-resend-button.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/website/src/scripts/contact/reset-resend-button.ts b/website/src/scripts/contact/reset-resend-button.ts new file mode 100644 index 0000000..21b0adc --- /dev/null +++ b/website/src/scripts/contact/reset-resend-button.ts @@ -0,0 +1,32 @@ +import type { Selectors } from "./selectors"; + +export function resetResendButton( + { otpDialog }: Selectors, + resendButtonInterval: NodeJS.Timeout | undefined, +): Result { + clearInterval(resendButtonInterval); + + const resendButton = otpDialog.resendButton(); + if (resendButton) { + resendButton.setAttribute("data-countdown", "60"); + resendButton.setAttribute("disabled", ""); + + resendButtonInterval = setInterval(() => { + const countdown = +(resendButton.getAttribute("data-countdown") ?? 1) - 1; + resendButton.setAttribute("data-countdown", countdown.toString()); + resendButton.textContent = `Resend (${countdown}s)`; + }, 1000); + + setTimeout(() => { + clearInterval(resendButtonInterval); + resendButton.textContent = "Resend"; + resendButton.removeAttribute("disabled"); + }, 1000 * 60); + } + + return { resendButtonInterval }; +} + +type Result = { + resendButtonInterval: NodeJS.Timeout | undefined; +}; |
