mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
Refactor forgot password and reset component
This commit is contained in:
@ -57,32 +57,6 @@ export default function ForgotPassword() {
|
||||
resetField("email");
|
||||
};
|
||||
|
||||
if (resetSuccessful) {
|
||||
return (
|
||||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||
<div className="w-full max-w-md space-y-8">
|
||||
<div>
|
||||
<Logo className="mx-auto h-20 w-auto"></Logo>
|
||||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
|
||||
Reset Password
|
||||
</h2>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">
|
||||
Please check your email for reset instructions.
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<Link href="/login">
|
||||
<div className="relative mt-10 flex items-center justify-center gap-2 text-sm text-gray-500 hover:cursor-pointer hover:text-gray-900">
|
||||
<ArrowLeftIcon className="h-4 w-4" />
|
||||
Back to log in
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||
@ -90,12 +64,15 @@ export default function ForgotPassword() {
|
||||
<div>
|
||||
<Logo className="mx-auto h-20 w-auto"></Logo>
|
||||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
|
||||
Forgot Password?
|
||||
{resetSuccessful ? "Reset Password" : "Forgot Password?"}
|
||||
</h2>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">
|
||||
No worries, we'll send you reset instructions.
|
||||
{resetSuccessful
|
||||
? "Please check your email for reset instructions."
|
||||
: "No worries, we'll send you reset instructions."}
|
||||
</p>
|
||||
</div>
|
||||
{resetSuccessful ? null : (
|
||||
<FormProvider {...methods}>
|
||||
<form className="mt-8 space-y-6" onSubmit={methods.handleSubmit(onSubmit)}>
|
||||
<div className="-space-y-px rounded-md shadow-sm">
|
||||
@ -124,6 +101,9 @@ export default function ForgotPassword() {
|
||||
Reset password
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
)}
|
||||
<div>
|
||||
<Link href="/login">
|
||||
<div className="relative mt-10 flex items-center justify-center gap-2 text-sm text-gray-500 hover:cursor-pointer hover:text-gray-900">
|
||||
@ -132,8 +112,6 @@ export default function ForgotPassword() {
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@ -7,7 +7,7 @@ import { ArrowLeftIcon } from "@heroicons/react/24/outline";
|
||||
import { FormProvider, useForm } from "react-hook-form";
|
||||
import { toast } from "react-hot-toast";
|
||||
|
||||
interface ForgotPasswordForm {
|
||||
interface ResetPasswordForm {
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
@ -16,13 +16,13 @@ export default function ResetPassword(props: any) {
|
||||
const router = useRouter();
|
||||
const { token } = router.query;
|
||||
|
||||
const methods = useForm<ForgotPasswordForm>();
|
||||
const methods = useForm<ResetPasswordForm>();
|
||||
const { register, formState, watch } = methods;
|
||||
const password = watch("password", "");
|
||||
|
||||
const [resetSuccessful, setResetSuccessful] = useState(false);
|
||||
|
||||
const onSubmit = async (values: ForgotPasswordForm) => {
|
||||
const onSubmit = async (values: ResetPasswordForm) => {
|
||||
const response = await toast.promise(
|
||||
fetch(`/api/auth/reset-password`, {
|
||||
method: "POST",
|
||||
@ -52,40 +52,6 @@ export default function ResetPassword(props: any) {
|
||||
}
|
||||
};
|
||||
|
||||
if (!token) {
|
||||
return (
|
||||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||
<div className="w-full max-w-md space-y-8">
|
||||
<div>
|
||||
<Logo className="mx-auto h-20 w-auto"></Logo>
|
||||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
|
||||
Reset Password
|
||||
</h2>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">
|
||||
The token you provided is invalid. Please try again.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (resetSuccessful) {
|
||||
return (
|
||||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||
<div className="w-full max-w-md space-y-8">
|
||||
<div>
|
||||
<Logo className="mx-auto h-20 w-auto"></Logo>
|
||||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
|
||||
Reset Password
|
||||
</h2>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">Your password has been reset.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||
@ -95,8 +61,11 @@ export default function ResetPassword(props: any) {
|
||||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
|
||||
Reset Password
|
||||
</h2>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">Please chose your new password</p>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">
|
||||
{resetSuccessful ? "Your password has been reset." : "Please chose your new password"}
|
||||
</p>
|
||||
</div>
|
||||
{resetSuccessful ? null : (
|
||||
<FormProvider {...methods}>
|
||||
<form className="mt-8 space-y-6" onSubmit={methods.handleSubmit(onSubmit)}>
|
||||
<div className="-space-y-px rounded-md shadow-sm">
|
||||
@ -142,6 +111,9 @@ export default function ResetPassword(props: any) {
|
||||
Reset password
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
)}
|
||||
<div>
|
||||
<Link href="/login">
|
||||
<div className="relative mt-10 flex items-center justify-center gap-2 text-sm text-gray-500 hover:cursor-pointer hover:text-gray-900">
|
||||
@ -150,8 +122,6 @@ export default function ResetPassword(props: any) {
|
||||
</div>
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
20
apps/web/pages/auth/reset/index.tsx
Normal file
20
apps/web/pages/auth/reset/index.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import React from "react";
|
||||
import Logo from "../../../components/logo";
|
||||
|
||||
export default function ResetPage() {
|
||||
return (
|
||||
<div className="flex min-h-full items-center justify-center py-12 px-4 sm:px-6 lg:px-8">
|
||||
<div className="w-full max-w-md space-y-8">
|
||||
<div>
|
||||
<Logo className="mx-auto h-20 w-auto"></Logo>
|
||||
<h2 className="mt-6 text-center text-3xl font-bold tracking-tight text-gray-900">
|
||||
Reset Password
|
||||
</h2>
|
||||
<p className="mt-2 text-center text-sm text-gray-600">
|
||||
The token you provided is invalid. Please try again.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user