From 7cc1ae2de09dc0bd441eff82d2f0fb5dd433f6ad Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Wed, 7 Jun 2023 10:33:05 +0000 Subject: [PATCH] Refactor forgot password and reset component --- apps/web/components/forgot-password.tsx | 98 ++++++--------- apps/web/components/reset-password.tsx | 152 ++++++++++-------------- apps/web/pages/auth/reset.tsx | 0 apps/web/pages/auth/reset/index.tsx | 20 ++++ 4 files changed, 119 insertions(+), 151 deletions(-) delete mode 100644 apps/web/pages/auth/reset.tsx create mode 100644 apps/web/pages/auth/reset/index.tsx diff --git a/apps/web/components/forgot-password.tsx b/apps/web/components/forgot-password.tsx index a0eee29f4..cafdd067e 100644 --- a/apps/web/components/forgot-password.tsx +++ b/apps/web/components/forgot-password.tsx @@ -57,19 +57,53 @@ export default function ForgotPassword() { resetField("email"); }; - if (resetSuccessful) { - return ( + return ( + <>

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

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

+ {resetSuccessful ? null : ( + +
+
+
+ + +
+
+ +
+ +
+
+
+ )}
@@ -80,62 +114,6 @@ export default function ForgotPassword() {
- ); - } - - return ( - <> -
-
-
- -

- Forgot Password? -

-

- No worries, we'll send you reset instructions. -

-
- -
-
-
- - -
-
- -
- -
-
- -
- - Back to log in -
- -
-
-
-
-
); } diff --git a/apps/web/components/reset-password.tsx b/apps/web/components/reset-password.tsx index a1b240058..3ac6c8b74 100644 --- a/apps/web/components/reset-password.tsx +++ b/apps/web/components/reset-password.tsx @@ -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(); + const methods = useForm(); 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 ( -
-
-
- -

- Reset Password -

-

- The token you provided is invalid. Please try again. -

-
-
-
- ); - } - - if (resetSuccessful) { - return ( -
-
-
- -

- Reset Password -

-

Your password has been reset.

-
-
-
- ); - } - return ( <>
@@ -95,63 +61,67 @@ export default function ResetPassword(props: any) {

Reset Password

-

Please chose your new password

+

+ {resetSuccessful ? "Your password has been reset." : "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 + {resetSuccessful ? null : ( + + +
+
+ +
- +
+ + 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
- - + +
diff --git a/apps/web/pages/auth/reset.tsx b/apps/web/pages/auth/reset.tsx deleted file mode 100644 index e69de29bb..000000000 diff --git a/apps/web/pages/auth/reset/index.tsx b/apps/web/pages/auth/reset/index.tsx new file mode 100644 index 000000000..f21145422 --- /dev/null +++ b/apps/web/pages/auth/reset/index.tsx @@ -0,0 +1,20 @@ +import React from "react"; +import Logo from "../../../components/logo"; + +export default function ResetPage() { + return ( +
+
+
+ +

+ Reset Password +

+

+ The token you provided is invalid. Please try again. +

+
+
+
+ ); +}