import { Button } from "@rallly/ui/button"; import { Input } from "@rallly/ui/input"; import { Trans, useTranslation } from "next-i18next"; import type React from "react"; import { useForm } from "react-hook-form"; import { requiredString } from "../../utils/form-validation"; export const verifyCode = async (options: { email: string; token: string }) => { const url = `${ window.location.origin }/api/auth/callback/email?email=${encodeURIComponent(options.email)}&token=${ options.token }`; const res = await fetch(url); return !res.url.includes("auth/error"); }; export const VerifyCode: React.FunctionComponent<{ email: string; onSubmit: (code: string) => Promise; }> = ({ onSubmit, email }) => { const { register, handleSubmit, setError, formState } = useForm<{ code: string; }>(); const { t } = useTranslation(); return (
{ try { await onSubmit(code); } catch { setError("code", { type: "not_found", message: t("wrongVerificationCode"), }); } })} >

{t("verifyYourEmail")}

{t("stepSummary", { current: 2, total: 2, })}

, }} />

{formState.errors.code?.message ? (

{formState.errors.code.message}

) : null}

{t("verificationCodeHelp")}

); };