import React, { useState, useEffect, FormEvent, ChangeEvent } from 'react' import { useNavigate, useSearchParams } from 'react-router-dom' import { Lock, KeyRound, CheckCircle2, AlertTriangle, Eye, EyeOff } from 'lucide-react' import { useTranslation } from '../i18n' import { authApi } from '../api/client' import { getApiErrorMessage } from '../types' const inputBase: React.CSSProperties = { width: '100%', padding: '11px 44px 11px 38px', borderRadius: 12, border: '1px solid #e5e7eb', fontSize: 14, fontFamily: 'inherit', outline: 'none', transition: 'border-color 120ms', background: 'white', color: '#111827', } const ResetPasswordPage: React.FC = () => { const { t } = useTranslation() const navigate = useNavigate() const [params] = useSearchParams() const token = params.get('token') || '' const [pw, setPw] = useState('') const [pw2, setPw2] = useState('') const [showPw, setShowPw] = useState(false) const [mfaCode, setMfaCode] = useState('') const [mfaRequired, setMfaRequired] = useState(false) const [error, setError] = useState('') const [success, setSuccess] = useState(false) const [isLoading, setIsLoading] = useState(false) useEffect(() => { if (!token) setError(t('login.resetPasswordInvalidLink')) }, [token, t]) const handleSubmit = async (e: FormEvent) => { e.preventDefault() if (isLoading) return setError('') if (!token) return if (pw.length < 8) { setError(t('login.passwordMinLength')); return } if (pw !== pw2) { setError(t('login.passwordsDontMatch')); return } setIsLoading(true) try { const res = await authApi.resetPassword({ token, new_password: pw, ...(mfaRequired && mfaCode ? { mfa_code: mfaCode.trim() } : {}), }) if (res.mfa_required) { setMfaRequired(true) setIsLoading(false) return } if (res.success) { setSuccess(true) } } catch (err) { setError(getApiErrorMessage(err, t('login.resetPasswordFailed'))) } setIsLoading(false) } const shell = (inner: React.ReactNode) => (
{t('login.resetPasswordSuccessBody')}
{t('login.resetPasswordInvalidLinkBody')}
{mfaRequired ? t('login.resetPasswordMfaBody') : t('login.resetPasswordBody')}
{error && (