import { useId, useState, type FormEvent } from "react"; import { Button, Dialog, DismissibleAlert, FormField, FormLayout, PasswordField, i18nMessage, usePlatformLanguage, type ApiSettings } from "@govoplan/core-webui"; import { issuePasswordRecovery, passwordErrorMessage, type PasswordRecoveryCode } from "../../api/passwords"; export default function PasswordRecoveryIssueDialog({ settings, account, onClose }: { settings: ApiSettings; account: { account_id: string; email: string }; onClose: () => void; }) { const { translateText } = usePlatformLanguage(); const formId = useId(); const [password, setPassword] = useState(""); const [verified, setVerified] = useState(false); const [result, setResult] = useState(null); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const ready = verified && Boolean(password) && Array.from(password).length <= 1024; async function submit(event: FormEvent) { event.preventDefault(); if (busy || !ready || result) return; setBusy(true); setError(""); try { setResult(await issuePasswordRecovery(settings, account.account_id, password, true)); } catch (reason) { setError(passwordErrorMessage(reason)); } finally { setPassword(""); setVerified(false); setBusy(false); } } return { if (!busy) onClose(); }} footer={<> {!result && } }>

{i18nMessage("i18n:govoplan-access.password.issue_for", { value0: account.email })}

{error && {error}} {result ? <>

i18n:govoplan-access.password.code_once

{i18nMessage("i18n:govoplan-access.password.code_expires", { value0: new Date(result.expires_at).toLocaleString() })}

i18n:govoplan-access.password.code_delivery

:

i18n:govoplan-access.password.issue_consequences

}
; }