diff options
| author | Joe Carstairs <me@joeac.net> | 2026-06-04 15:15:02 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-06-04 15:16:34 +0100 |
| commit | 813836fbba884388e6013e9fd377430ef33b6c8d (patch) | |
| tree | 056149f5c51eabaa89960a7d8d2eb68fe9b158e8 /http/public/scripts/contact/resend-otp.js | |
| parent | fac1199cd61e069b1a144d2548477a2c3b3b94b0 (diff) | |
http: adds scripts
Diffstat (limited to 'http/public/scripts/contact/resend-otp.js')
| -rw-r--r-- | http/public/scripts/contact/resend-otp.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/http/public/scripts/contact/resend-otp.js b/http/public/scripts/contact/resend-otp.js new file mode 100644 index 0000000..e083d95 --- /dev/null +++ b/http/public/scripts/contact/resend-otp.js @@ -0,0 +1,31 @@ +/** @typedef {import("./selectors.js").Selectors} Selectors */ + +import { actions } from "./actions.js"; +import { resetResendButton } from "./reset-resend-button.js"; +import { postErrorMessageOnOtpForm } from "./post-error-message.js"; + +/** @typedef {{ resendButtonInterval: NodeJS.Timeout | undefined }} Result */ + +const fallbackErrorMsg = + "No can do. I'm afraid joeac.net is a bit broken right now - sorry about that."; + +/** + * @param {Selectors} selectors + * @param {NodeJS.Timeout | undefined} resetButtonInterval + * @returns {Promise<Result>} + */ +export async function resendOtp(selectors, resetButtonInterval) { + const result = resetResendButton(selectors, resetButtonInterval); + const name = selectors.contactForm.nameElem()?.value; + const email = selectors.contactForm.emailElem().value; + + try { + await actions.sendOtp({ type: "email", name, email }); + } catch (sendOtpError) { + const errorMsg = sendOtpError?.toString() ?? fallbackErrorMsg; + postErrorMessageOnOtpForm(selectors, errorMsg); + throw sendOtpError; + } + + return result; +} |
