import { useState } from "react"; import Link from "next/link"; import { Button } from "@documenso/ui"; import Logo from "./logo"; import { ArrowLeftIcon } from "@heroicons/react/24/outline"; import { FormProvider, useForm } from "react-hook-form"; import { toast } from "react-hot-toast"; interface ForgotPasswordForm { email: string; } export default function ForgotPassword() { const { register, formState, resetField, handleSubmit } = useForm(); const [resetSuccessful, setResetSuccessful] = useState(false); const onSubmit = async (values: ForgotPasswordForm) => { const response = await toast.promise( fetch(`/api/auth/forgot-password`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(values), }), { loading: "Sending...", success: "Reset link sent.", error: "Could not send reset link :/", } ); if (!response.ok) { toast.dismiss(); if (response.status == 404) { toast.error("Email address not found."); } if (response.status == 400) { toast.error("Password reset requested."); } if (response.status == 500) { toast.error("Something went wrong."); } return; } if (response.ok) { setResetSuccessful(true); } resetField("email"); }; return ( <>

{resetSuccessful ? "Reset Password" : "Forgot Password?"}

{resetSuccessful ? "Please check your email for reset instructions." : "No worries, we'll send you reset instructions."}

{!resetSuccessful && (
)}
Back to log in
); }