import AccentSubmitButton from "@/components/AccentSubmitButton"; import TextInput from "@/components/TextInput"; import CenteredForm from "@/layouts/CenteredForm"; import Link from "next/link"; import { FormEvent, useState } from "react"; import { toast } from "react-hot-toast"; interface FormData { email: string; } export default function Forgot() { const [submitLoader, setSubmitLoader] = useState(false); const [form, setForm] = useState({ email: "", }); const [isEmailSent, setIsEmailSent] = useState(false); async function submitRequest() { const response = await fetch("/api/v1/auth/forgot-password", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(form), }); const data = await response.json(); if (response.ok) { toast.success(data.response); setIsEmailSent(true); } else { toast.error(data.response); } } async function sendConfirmation(event: FormEvent) { event.preventDefault(); if (form.email !== "") { setSubmitLoader(true); const load = toast.loading("Sending password recovery link..."); await submitRequest(); toast.dismiss(load); setSubmitLoader(false); } else { toast.error("Please fill out all the fields."); } } return (

{isEmailSent ? "Email Sent!" : "Forgot Password?"}

{!isEmailSent ? ( <>

Enter your email so we can send you a link to create a new password.

Email

setForm({ ...form, email: e.target.value })} />
) : (

Check your email for a link to reset your password. If it doesn’t appear within a few minutes, check your spam folder.

)}
Back to Login
); }