import React, { useState } from "react"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { Link } from "react-router-dom"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import Logo from "@/components/ui/logo"; import { toast } from "@/lib/custom-toast"; import { authService } from "@/lib/api"; // Form schema and validation const formSchema = z.object({ email: z.string().email({ message: "Please enter a valid email address", }), }); const ForgotPassword = () => { const [isLoading, setIsLoading] = useState(false); const [isEmailSent, setIsEmailSent] = useState(false); const [apiError, setApiError] = useState(null); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { email: "", }, }); const onSubmit = async (values: z.infer) => { try { setIsLoading(true); setApiError(null); // Call the password reset request API const response = await authService.requestPasswordReset(values.email); // Show success message and update UI setIsEmailSent(true); toast.success(response.message || "Password reset link sent to your email"); } catch (error: any) { // Show error message const errorMessage = error.message || "Failed to send reset link. Please try again."; setApiError(errorMessage); toast.error(errorMessage); } finally { setIsLoading(false); } }; return (

Forgot Password

Enter your email to receive a password reset link

{isEmailSent ? (

Check Your Email

We've sent a password reset link to your email address.

) : ( <> {apiError && (
{apiError}
)}
( Email )} /> )}
); }; export default ForgotPassword;