'use client'; import { useState, useEffect, Suspense } from 'react'; import { useSearchParams } from 'next/navigation'; import { Link, useRouter } from '@/i18n/navigation'; import Image from 'next/image'; import { useTranslations } from 'next-intl'; import { resetPassword } from '@/lib/api/auth'; function ResetPasswordContent() { const t = useTranslations('auth.resetPassword'); const tFooter = useTranslations('auth.footerLinks'); const searchParams = useSearchParams(); const router = useRouter(); const [token, setToken] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [success, setSuccess] = useState(false); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [tokenError, setTokenError] = useState(false); useEffect(() => { const tokenFromUrl = searchParams.get('token'); if (tokenFromUrl) { setToken(tokenFromUrl); } else { setTokenError(true); } }, [searchParams]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); if (password !== confirmPassword) { setError(t('errors.passwordsMismatch')); return; } if (password.length < 12) { setError(t('errors.passwordMin')); return; } setLoading(true); try { await resetPassword(token, password); setSuccess(true); setTimeout(() => router.push('/login'), 3000); } catch (err: any) { setError(err.message || t('errors.generic')); } finally { setLoading(false); } }; const tips = t.raw('sidePanel.tips') as string[]; return (
{t('invalidTokenMessage')}
{t('successMessage')}
{t('subtitle')}
{error}
{t('sidePanel.description')}
{tip}