import { zodResolver } from "@hookform/resolvers/zod" import { useMutation } from "@tanstack/react-query" import { createFileRoute, Link as RouterLink, redirect, } from "@tanstack/react-router" import { useForm } from "react-hook-form" import { z } from "zod" import { LoginService } from "@/client" import { AuthLayout } from "@/components/Common/AuthLayout" import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form" import { Input } from "@/components/ui/input" import { LoadingButton } from "@/components/ui/loading-button" import { isLoggedIn } from "@/hooks/useAuth" import useCustomToast from "@/hooks/useCustomToast" import { handleError } from "@/utils" const formSchema = z.object({ email: z.email(), }) type FormData = z.infer export const Route = createFileRoute("/recover-password")({ component: RecoverPassword, beforeLoad: async () => { if (isLoggedIn()) { throw redirect({ to: "/", }) } }, head: () => ({ meta: [ { title: "Recover Password - FastAPI Cloud", }, ], }), }) function RecoverPassword() { const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { email: "", }, }) const { showSuccessToast, showErrorToast } = useCustomToast() const recoverPassword = async (data: FormData) => { await LoginService.recoverPassword({ email: data.email, }) } const mutation = useMutation({ mutationFn: recoverPassword, onSuccess: () => { showSuccessToast("Password recovery email sent successfully") form.reset() }, onError: handleError.bind(showErrorToast), }) const onSubmit = async (data: FormData) => { if (mutation.isPending) return mutation.mutate(data) } return (

Password Recovery

( Email )} /> Continue
Remember your password?{" "} Log in
) }