import { useState } from "react"; import { useForm } from "react-hook-form"; import {useResetPasswordMutation, TResetPassword} from "~/data-provider"; import { useNavigate, useSearchParams } from "react-router-dom"; function ResetPassword() { const { register, handleSubmit, watch, formState: { errors }, } = useForm(); const resetPassword = useResetPasswordMutation(); const [resetError, setResetError] = useState(false); const [params] = useSearchParams(); const navigate = useNavigate(); const password = watch("password"); const onSubmit = (data: TResetPassword) => { resetPassword.mutate(data, { onError: () => { setResetError(true); } }); }; if (resetPassword.isSuccess) { return (

Password Reset Success

You may now login with your new password.
) } else { return (

Reset your password

{resetError && (
This password reset token is no longer valid. Click here to try again.
)}
{errors.password && ( {/* @ts-ignore */} {errors.password.message} )}
{ e.preventDefault(); return false; }} {...register("confirm_password", { validate: (value) => value === password || "Passwords do not match", })} aria-invalid={!!errors.confirm_password} className="block rounded-t-md px-2.5 pb-2.5 pt-5 w-full text-sm text-gray-900 bg-gray-50 border-0 border-b-2 border-gray-300 appearance-none focus:outline-none focus:ring-0 focus:border-green-500 peer" placeholder=" " >
{errors.confirm_password && ( {/* @ts-ignore */} {errors.confirm_password.message} )} {errors.token && ( {/* @ts-ignore */} {errors.token.message} )} {errors.userId && ( {/* @ts-ignore */} {errors.userId.message} )}
) } }; export default ResetPassword;