import { useState } from "react"; import { changeEmail, resendVerificationEmail } from "~/fns/account-security"; import { useAction } from "~/hooks/use-action"; import { Button } from "~/components/ui/Button"; import { ErrorBanner, TextField } from "~/components/ui/Field"; import { Badge, Panel } from "~/components/ui/Primitives"; export function EmailPanel({ email, verified, hasPassword, }: { email: string; verified: boolean; hasPassword: boolean; }) { const resend = useAction(resendVerificationEmail, { invalidate: false }); const change = useAction(changeEmail, { invalidate: false }); const [notice, setNotice] = useState(null); return (
{notice &&

{notice}

}
{email} {verified ? Verified : Unverified} {!verified && ( )}
{ event.preventDefault(); const formElement = event.currentTarget; const form = new FormData(formElement); const next = String(form.get("email") ?? ""); const result = await change.run({ data: { email: next, password: String(form.get("password") ?? "") } }); if (result) { formElement.reset(); setNotice(`Check ${next} for a link to confirm the change.`); } }} > {hasPassword && ( )}
); }