summaryrefslogtreecommitdiff
path: root/http/public/scripts/contact/reset-resend-button.js
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-06-04 15:15:02 +0100
committerJoe Carstairs <me@joeac.net>2026-06-04 15:16:34 +0100
commit813836fbba884388e6013e9fd377430ef33b6c8d (patch)
tree056149f5c51eabaa89960a7d8d2eb68fe9b158e8 /http/public/scripts/contact/reset-resend-button.js
parentfac1199cd61e069b1a144d2548477a2c3b3b94b0 (diff)
http: adds scripts
Diffstat (limited to 'http/public/scripts/contact/reset-resend-button.js')
-rw-r--r--http/public/scripts/contact/reset-resend-button.js32
1 files changed, 32 insertions, 0 deletions
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 };
+}