diff options
Diffstat (limited to 'website/src/scripts/contact/resend-otp.ts')
| -rw-r--r-- | website/src/scripts/contact/resend-otp.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/website/src/scripts/contact/resend-otp.ts b/website/src/scripts/contact/resend-otp.ts new file mode 100644 index 0000000..3f3a4f3 --- /dev/null +++ b/website/src/scripts/contact/resend-otp.ts @@ -0,0 +1,29 @@ +import { actions } from "astro:actions"; +import { resetResendButton } from "./reset-resend-button"; +import { postErrorMessageOnOtpForm } from "./post-error-message"; +import type { Selectors } from "./selectors"; + +const fallbackErrorMsg = + "No can do. I'm afraid joeac.net is a bit broken right now - sorry about that."; + +export async function resendOtp( + selectors: Selectors, + resetButtonInterval: NodeJS.Timeout | undefined, +): Promise<Result> { + const result = resetResendButton(selectors, resetButtonInterval); + const name = selectors.contactForm.nameElem()?.value; + const email = selectors.contactForm.emailElem().value; + + const sendOtpResult = await actions.otp.send({ type: "email", name, email }); + if (sendOtpResult.error) { + const errorMsg = sendOtpResult.error?.toString() ?? fallbackErrorMsg; + postErrorMessageOnOtpForm(selectors, errorMsg); + throw sendOtpResult.error; + } + + return result; +} + +type Result = { + resendButtonInterval: NodeJS.Timeout | undefined; +}; |
