From 46c9b7731622f1f4d0f6a03c3179e747e0ce065d Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 18 Dec 2025 11:04:03 +0000 Subject: contact page --- website/src/scripts/contact/reset-resend-button.ts | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 website/src/scripts/contact/reset-resend-button.ts (limited to 'website/src/scripts/contact/reset-resend-button.ts') 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; +}; -- cgit v1.2.3