From 813836fbba884388e6013e9fd377430ef33b6c8d Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 4 Jun 2026 15:15:02 +0100 Subject: http: adds scripts --- http/public/scripts/contact/reset-resend-button.js | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 http/public/scripts/contact/reset-resend-button.js (limited to 'http/public/scripts/contact/reset-resend-button.js') diff --git a/http/public/scripts/contact/reset-resend-button.js b/http/public/scripts/contact/reset-resend-button.js new file mode 100644 index 0000000..47bc9ac --- /dev/null +++ b/http/public/scripts/contact/reset-resend-button.js @@ -0,0 +1,32 @@ +/** @typedef {import("./selectors.js").Selectors} Selectors */ + +/** @typedef {{ resendButtonInterval: NodeJS.Timeout | undefined }} Result */ + +/** + * @param {Selectors} selectors + * @param {NodeJS.Timeout | undefined} resetButtonInterval + * @returns {Result} + */ +export function resetResendButton({ otpDialog }, resendButtonInterval) { + 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 }; +} -- cgit v1.2.3