import React, { useState, useEffect, FormEvent, ChangeEvent } from 'react' import { useNavigate } from 'react-router-dom' import { Mail, ArrowLeft, CheckCircle2, Terminal } from 'lucide-react' import { useTranslation } from '../i18n' import { authApi } from '../api/client' const inputBase: React.CSSProperties = { width: '100%', padding: '11px 12px 11px 38px', borderRadius: 12, border: '1px solid #e5e7eb', fontSize: 14, fontFamily: 'inherit', outline: 'none', transition: 'border-color 120ms', background: 'white', color: '#111827', } const ForgotPasswordPage: React.FC = () => { const { t } = useTranslation() const navigate = useNavigate() const [email, setEmail] = useState('') const [submitted, setSubmitted] = useState(false) const [isLoading, setIsLoading] = useState(false) const [smtpConfigured, setSmtpConfigured] = useState(null) useEffect(() => { // Probe whether SMTP is configured so we can warn the user up-front // that the link will land in the server console instead of their // inbox. Null while pending — hint is hidden until we know. authApi.getAppConfig?.() .then((cfg: any) => { const hasEmail = !!cfg?.available_channels?.email setSmtpConfigured(hasEmail) }) .catch(() => setSmtpConfigured(null)) }, []) const handleSubmit = async (e: FormEvent) => { e.preventDefault() if (isLoading) return setIsLoading(true) try { await authApi.forgotPassword({ email: email.trim() }) } catch { // Enumeration-safe: success UX regardless of server outcome. } setSubmitted(true) setIsLoading(false) } return (
{submitted ? (

{t('login.forgotPasswordSentTitle')}

{t('login.forgotPasswordSentBody')}

{smtpConfigured === false && (

{t('login.forgotPasswordSmtpHintOff')}

)}
) : ( <>

{t('login.forgotPasswordTitle')}

{t('login.forgotPasswordBody')}

{smtpConfigured === false && (

{t('login.forgotPasswordSmtpHintOff')}

)}
) => setEmail(e.target.value)} required placeholder={t('login.emailPlaceholder')} style={inputBase} onFocus={(e) => { e.currentTarget.style.borderColor = '#111827' }} onBlur={(e) => { e.currentTarget.style.borderColor = '#e5e7eb' }} />
)}
) } export default ForgotPasswordPage