'use client'; import { resetPasswordSchema, type ResetPasswordFormData } from '@nextsparkjs/core/lib/validation'; import { useAuth } from '@nextsparkjs/core/hooks/useAuth'; import { zodResolver } from '@hookform/resolvers/zod'; import { AlertCircle, ArrowLeft, CheckCircle, Loader2, Mail } from 'lucide-react'; import Link from 'next/link'; import { useState, useCallback } from 'react'; import { sel } from '@nextsparkjs/core/selectors'; import { useTranslations } from 'next-intl'; import { useForm } from 'react-hook-form'; import { Button } from '@nextsparkjs/core/components/ui/button'; import { Input } from '@nextsparkjs/core/components/ui/input'; import { Label } from '@nextsparkjs/core/components/ui/label'; import { Alert, AlertDescription } from '@nextsparkjs/core/components/ui/alert'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@nextsparkjs/core/components/ui/card'; import { getTemplateOrDefaultClient } from '@nextsparkjs/registries/template-registry.client' function ForgotPasswordPage() { const { resetPassword } = useAuth(); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(false); const [statusMessage, setStatusMessage] = useState(''); const t = useTranslations('auth'); const form = useForm({ resolver: zodResolver(resetPasswordSchema), defaultValues: { email: '', }, }); const { register, handleSubmit, formState: { errors }, watch, } = form; const email = watch('email'); const onSubmit = useCallback(async (data: ResetPasswordFormData) => { setLoading(true); setError(null); setStatusMessage(t('forgotPassword.messages.sending')); try { const result = await resetPassword(data.email); if (!result.success) { const errorMsg = result.error || 'Failed to send reset email'; setError(errorMsg); setStatusMessage(`Error: ${errorMsg}`); } else { setSuccess(true); setStatusMessage(t('forgotPassword.messages.sent')); } } catch { setError('An unexpected error occurred'); setStatusMessage(t('forgotPassword.messages.error')); } finally { setLoading(false); } }, [resetPassword, t]); if (success) { return ( <>
{statusMessage}

{t('forgotPassword.success.title')}

We've sent a password reset link to {email}

Please check your inbox and click the link to reset your password.

Didn't receive the email?
• Check your spam folder
• Make sure you entered the correct email address
• Wait a few minutes and try again
); } return ( <>
{statusMessage}
{t('forgotPassword.title')} {t('forgotPassword.description')} {error && ( {error}
Please check your email address and try again.
)}
{errors.email && (

{errors.email.message}

)}
Back to Login
); } // Opt out of static generation due to client-side state export default getTemplateOrDefaultClient('app/(auth)/forgot-password/page.tsx', ForgotPasswordPage)