"use client"; import { useId, useState } from "react"; import Link from "next/link"; import { useRouter, useSearchParams } from "next/navigation"; import { useTranslation } from "../../../contexts/MessagesContext"; import Login from "../../../components/modals/Login"; import Button from "../../../components/buttons/Button"; import TextInput from "../../../components/controls/TextInput"; import ContentLockup from "../../../components/type/ContentLockup"; import { EMAIL_MAX_LEN } from "../../../../lib/create/isValidCreateFlowSaveEmail"; import { INVITE_EMAIL_PATTERN } from "../../../../lib/create/parseInviteEmails"; import { resendExpiredStakeholderInvite } from "../../../../lib/create/api"; const expiredPageBgClass = "min-h-[100dvh] bg-[var(--color-surface-invert-brand-primary)]"; export function ExpiredInviteScreen() { const t = useTranslation("pages.invite"); const router = useRouter(); const searchParams = useSearchParams(); const token = searchParams.get("token") ?? ""; const titleId = useId(); const [email, setEmail] = useState(""); const [emailError, setEmailError] = useState(""); const [formError, setFormError] = useState(""); const [submitting, setSubmitting] = useState(false); const [sent, setSent] = useState(false); const heading = sent ? { title: t("sentTitle"), description: t("sentBody") } : { title: t("expiredTitle"), description: t("expiredDescription") }; async function sendLink() { const trimmed = email.trim().toLowerCase(); if (!INVITE_EMAIL_PATTERN.test(trimmed)) { setEmailError(t("emailInvalid")); return; } if (token.length < 10) { setFormError(t("missingToken")); return; } setEmailError(""); setFormError(""); setSubmitting(true); const result = await resendExpiredStakeholderInvite(token, trimmed); setSubmitting(false); if (result.ok === false) { if (result.retryAfterMs) { const seconds = Math.max(1, Math.ceil(result.retryAfterMs / 1000)); setFormError(t("rateLimited").replace("{seconds}", String(seconds))); return; } setFormError(result.error || t("genericError")); return; } setSent(true); } return (
{ router.push("/"); }} ariaLabelledBy={titleId} belowCard={ {t("backToHome")} } >
{formError ? (

{formError}

) : null} {!sent ? (
{ event.preventDefault(); void sendLink(); }} noValidate > { setEmail(event.target.value); setEmailError(""); }} disabled={submitting} error={Boolean(emailError)} showHelpIcon maxLength={EMAIL_MAX_LEN} /> {emailError ? (

{emailError}

) : null}

{t("notInvitedAddress")}

) : null}
); }