'use client'; import { useState } from 'react'; import { useRouter, Link } from '@/core/lib/navigation'; import { proxyResetPassword } from '@/core/lib/auth'; import { LoadingSpinner } from '@/ui/shared/loading-spinner'; import { useTranslations } from '@/core/lib/translations'; import { getPasswordError } from '@/core/lib/validation'; export function ResetPasswordForm() { const router = useRouter(); const t = useTranslations('auth'); const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (loading) return; const pwCode = getPasswordError(newPassword); if (pwCode) { setError(t(pwCode)); return; } if (newPassword !== confirmPassword) { setError(t('passwordsMustMatch')); return; } try { setLoading(true); setError(null); await proxyResetPassword(newPassword); setSuccess(true); setTimeout(() => router.push('/login'), 2000); } catch (err) { const message = err instanceof Error ? err.message : 'Something went wrong. Please try again.'; setError(message); } finally { setLoading(false); } } return (

{t('resetPasswordTitle')}

{t('resetPasswordSubtitle')}

{error && (

{error}

{t('sendResetLink')}
)} {success ? (
{t('passwordResetSuccess')}
) : (
setNewPassword(e.target.value)} placeholder={t('newPasswordPlaceholder')} autoComplete="new-password" className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2" />
setConfirmPassword(e.target.value)} placeholder={t('confirmPasswordPlaceholder')} autoComplete="new-password" className="border-border bg-background text-foreground placeholder:text-muted-foreground focus:ring-primary/20 focus:border-primary h-10 w-full rounded border px-3 text-sm focus:outline-none focus:ring-2" />
)}
); }