import { type FormEvent, useEffect, useRef, useState } from 'react' import { Link } from 'react-router-dom' import { requestForgotPassword } from '../api/passwordFlow' /** Mirrors CodeIgniter `user/forgot_password.php` + confirmation modal from `password_reset_confirmation.php`. */ export function ForgotPasswordPage() { const [email, setEmail] = useState('') const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const [confirmEmail, setConfirmEmail] = useState(null) const confirmModalRef = useRef(null) useEffect(() => { if (!confirmEmail) return const el = confirmModalRef.current const B = ( window as unknown as { bootstrap?: { Modal: { getOrCreateInstance: (n: HTMLElement) => { show: () => void } } } } ).bootstrap if (el && B?.Modal?.getOrCreateInstance) { B.Modal.getOrCreateInstance(el).show() } }, [confirmEmail]) async function onSubmit(e: FormEvent) { e.preventDefault() setLoading(true) setError(null) try { await requestForgotPassword(email) setConfirmEmail(email.trim()) } catch (err) { setError(err instanceof Error ? err.message : 'Request failed.') } finally { setLoading(false) } } return (
void onSubmit(e)} noValidate >
{ ;(ev.target as HTMLImageElement).style.display = 'none' }} />

Reset Your Password

Please enter the email address you used to register with us.

We'll send you a link to reset your password.

{error ? (
{error}
) : null}
setEmail(e.target.value)} autoComplete="email" />

Don't have an account?

Register now
) }