import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle, CardDescription, } from '@/components/ui/card'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import * as z from 'zod'; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, FormDescription, } from '@/components/ui/form'; import { useState } from 'react'; import { httpClient } from '@/app/infra/http/HttpClient'; import { useNavigate } from 'react-router-dom'; import { Mail, Lock, ArrowLeft, KeyRound } from 'lucide-react'; import { toast } from 'sonner'; import { useTranslation } from 'react-i18next'; import { Link } from 'react-router-dom'; import { ThemeToggle } from '@/components/ui/theme-toggle'; const formSchema = (t: (key: string) => string) => z.object({ email: z.string().email(t('common.invalidEmail')), recoveryKey: z.string().min(1, t('resetPassword.recoveryKeyRequired')), newPassword: z.string().min(1, t('resetPassword.newPasswordRequired')), }); export default function ResetPassword() { const navigate = useNavigate(); const { t } = useTranslation(); const [isResetting, setIsResetting] = useState(false); const form = useForm>>({ resolver: zodResolver(formSchema(t)), defaultValues: { email: '', recoveryKey: '', newPassword: '', }, }); function onSubmit(values: z.infer>) { handleResetPassword(values.email, values.recoveryKey, values.newPassword); } function handleResetPassword( email: string, recoveryKey: string, newPassword: string, ) { setIsResetting(true); httpClient .resetPassword(email, recoveryKey, newPassword) .then(() => { toast.success(t('resetPassword.resetSuccess')); navigate('/login'); }) .catch(() => { toast.error(t('resetPassword.resetFailed')); }) .finally(() => { setIsResetting(false); }); } return (
{t('resetPassword.backToLogin')}
{t('resetPassword.title')} {t('resetPassword.description')}
( {t('common.email')}
)} /> ( {t('resetPassword.recoveryKey')} {t('resetPassword.recoveryKeyDescription')} {/* Recovery keys are case-sensitive base64url strings; send them verbatim */}
)} /> ( {t('resetPassword.newPassword')}
)} />
); }