import React, { useState, useEffect } from 'react'; import { useTranslation } from '../i18n'; import './ResetPasswordView.css'; function ResetPasswordView({ token, onReset }) { const { t } = useTranslation(); const [password, setPassword] = useState(''); const [confirm, setConfirm] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [success, setSuccess] = useState(false); useEffect(() => { if (!token) setError(t('reset.invalidToken')); }, [token, t]); async function handleSubmit(e) { e.preventDefault(); if (password.length < 8) { setError(t('login.passwordError')); return; } if (password !== confirm) { setError(t('reset.passwordsDontMatch')); return; } setLoading(true); setError(''); try { const res = await fetch('/api/auth/reset-password', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, password }), }); const data = await res.json().catch(() => ({})); if (!res.ok) { setError(data.error || t('reset.error')); return; } setSuccess(true); } catch { setError(t('login.networkError')); } finally { setLoading(false); } } if (success) { return (
{t('reset.successText')}
{t('reset.subtitle')}