import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/router"; 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 IResetPassword { password: string; confirmPassword: string; } export default function ResetPassword(props: any) { const router = useRouter(); const { token } = router.query; const methods = useForm(); const { register, formState, watch } = methods; const password = watch("password", ""); const [resetSuccessful, setResetSuccessful] = useState(false); const onSubmit = async (values: IResetPassword) => { const response = await toast.promise( fetch(`/api/auth/reset-password`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ password: values.password, token }), }), { loading: "Resetting...", success: `Reset password successful`, error: "Could not reset password :/", } ); if (!response.ok) { toast.dismiss(); const error = await response.json(); toast.error(error.message); } if (response.ok) { setResetSuccessful(true); setTimeout(() => { router.push("/login"); }, 2000); } }; if (!token) { return (

Reset Password

The token you provided is invalid. Please try again.

); } if (resetSuccessful) { return (

Reset Password

Your password has been reset.

); } return ( <>

Reset Password

Please chose your new password

value === password || "The passwords do not match", })} id="confirmPassword" name="confirmPassword" type="password" required className="focus:border-neon focus:ring-neon relative block w-full appearance-none rounded-none rounded-b-md border border-gray-300 px-3 py-2 text-gray-900 placeholder-gray-500 focus:z-10 focus:outline-none sm:text-sm" placeholder="Confirm new password" />
Back to log in
); }