import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useSearchParams, useNavigate } from 'react-router-dom'; import { Helmet } from 'react-helmet-async'; import { KeyRound } from 'lucide-react'; import { toast } from 'sonner'; import { getApiClient } from '../services/api'; const api = getApiClient(); export default function ResetPasswordPage() { const { t } = useTranslation(); const navigate = useNavigate(); const [searchParams] = useSearchParams(); const token = searchParams.get('token') || ''; const [password, setPassword] = useState(''); const [confirm, setConfirm] = useState(''); const [success, setSuccess] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (password.length < 8) { const msg = t('auth.resetPassword.tooShort'); setError(msg); toast.error(msg); return; } if (password !== confirm) { const msg = t('account.passwordMismatch'); setError(msg); toast.error(msg); return; } setLoading(true); try { await api.post('/auth/reset-password', { token, password }); setSuccess(true); toast.success(t('auth.resetPassword.success')); setTimeout(() => navigate('/account'), 3000); } catch (err) { const errMsg = err instanceof Error ? err.message : t('auth.resetPassword.error'); setError(errMsg); toast.error(errMsg); } finally { setLoading(false); } }; if (!token) { return (

{t('auth.resetPassword.noToken')}

); } return ( <> {t('auth.resetPassword.title')} — {t('common.appName')}

{t('auth.resetPassword.title')}

{success ? (

{t('auth.resetPassword.success')}

) : (
setPassword(e.target.value)} className="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-700 dark:text-slate-200" />
setConfirm(e.target.value)} className="w-full rounded-lg border border-slate-300 px-3 py-2 text-sm dark:border-slate-600 dark:bg-slate-700 dark:text-slate-200" />
{error && (

{error}

)}
)}
); }