From ab1024be75b5777d461d886f9709d2e197a64c8d Mon Sep 17 00:00:00 2001 From: Fingertips Date: Mon, 23 Sep 2024 18:39:29 +0800 Subject: [PATCH 1/2] Create reset password page - Added a reset password form with three inputs: `old password`, `new password`, and `confirm password`. - Included a submit button to handle form submission for the password reset. - Ensured validation for new password and confirm password fields to match. - Applied basic styling consistent with the current design. --- client/src/App.tsx | 5 ++ client/src/constants/collections.ts | 43 +++++++++++++- client/src/constants/keys.ts | 1 + .../_components/reset-password-form.tsx | 56 +++++++++++++++++++ client/src/pages/reset-password/page.tsx | 18 ++++++ .../sign-in/_components/sign-in-form.tsx | 10 ++-- .../sign-up/_components/sign-up-form.tsx | 4 +- 7 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 client/src/pages/reset-password/_components/reset-password-form.tsx create mode 100644 client/src/pages/reset-password/page.tsx diff --git a/client/src/App.tsx b/client/src/App.tsx index 386f2b1..30811c4 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,6 +1,7 @@ import { Route, Routes } from "react-router-dom"; import { ForgotPasswordPage } from "@/pages/forgot-password/page"; +import { ResetPasswordPage } from "@/pages/reset-password/page"; import VerifyEmailPage from "@/pages/verify-email/page"; import PrivateGuard from "@/guards/private-guard"; import { AppRoutes } from "@/constants/routes"; @@ -25,6 +26,10 @@ function App() { path={AppRoutes.ForgotPassword} element={} /> + } + /> ); diff --git a/client/src/constants/collections.ts b/client/src/constants/collections.ts index 453f821..27a6ab2 100644 --- a/client/src/constants/collections.ts +++ b/client/src/constants/collections.ts @@ -7,7 +7,7 @@ import { ValidateUsername, } from "@/lib/utils/validations"; -export const SIGNUPINPUTS = [ +export const SIGNUP_INPUTS = [ { name: "username", label: "Username", @@ -35,7 +35,7 @@ export const SIGNUPINPUTS = [ name: "password", label: "Password", tooltip: - "Create a strong password with at least 8 characters. Include a mix of uppercase letters, lowercase letters, numbers, and special characters for better security.", + "Create a password with at least 8 characters, including uppercase, lowercase, numbers, and special characters for security.", placeholder: "e.g. m#P52s@ap$V", type: "password", autoComplete: "new-password", @@ -56,7 +56,7 @@ export const SIGNUPINPUTS = [ }, ]; -export const SIGNININPUTS = [ +export const SIGNIN_INPUTS = [ { name: "email", label: "Email Address", @@ -82,3 +82,40 @@ export const SIGNININPUTS = [ maxLength: 128, }, ]; + +export const RESET_PASSWORD_INPUTS = [ + { + name: "old-password", + label: "Old Password", + tooltip: "Enter your current password", + placeholder: "e.g. m#P52s@ap$V", + type: "password", + autoComplete: "new-password", + suffixIcon: Lock, + validation: ValidatePassword, + maxLength: 128, + }, + { + name: "new-password", + label: "New Password", + tooltip: + "Create a password with at least 8 characters, including uppercase, lowercase, numbers, and special characters for security", + placeholder: "e.g. m#P52s@ap$V", + type: "password", + autoComplete: "new-password", + suffixIcon: Lock, + validation: ValidatePassword, + maxLength: 128, + }, + { + label: "Confirm Password", + tooltip: + "Re-enter your password to confirm it matches the one you typed above. Ensure both passwords are identical.", + placeholder: "e.g. m#P52s@ap$V", + type: "password", + autoComplete: "new-password", + suffixIcon: Lock, + validation: ValidateConfirmPassword, + maxLength: 128, + }, +]; diff --git a/client/src/constants/keys.ts b/client/src/constants/keys.ts index f22fa6f..a7c242f 100644 --- a/client/src/constants/keys.ts +++ b/client/src/constants/keys.ts @@ -5,3 +5,4 @@ export const VERIFYEMAILKEY = "verify-email"; export const RESENDVERIFYKEY = "resend-verify"; export const VERIFYTOKENKEY = "verify-token"; export const FORGOTPASSWORDKEY = "forgot-password"; +export const RESETPASSWORDKEY = "reset-password"; diff --git a/client/src/pages/reset-password/_components/reset-password-form.tsx b/client/src/pages/reset-password/_components/reset-password-form.tsx new file mode 100644 index 0000000..92018a3 --- /dev/null +++ b/client/src/pages/reset-password/_components/reset-password-form.tsx @@ -0,0 +1,56 @@ +import { useMutation } from "@tanstack/react-query"; +import { FormEvent, useState } from "react"; + +import { RESET_PASSWORD_INPUTS } from "@/constants/collections"; +import { RESETPASSWORDKEY } from "@/constants/keys"; +import { Button } from "@/components/text-button"; +import { Input } from "@/components/input"; + +const ResetPasswordForm = () => { + const [confirmPassword, setConfirmPassword] = useState(""); + const { isPending } = useMutation({ + mutationKey: [RESETPASSWORDKEY], + }); + + const onSubmit = (e: FormEvent) => { + e.preventDefault(); + }; + + return ( +
+ {RESET_PASSWORD_INPUTS.map((r) => ( + { + if (r.name === "new-password") { + setConfirmPassword(value); + } + if (r.name === undefined) { + return r.validation({ + pass1: value, + pass2: confirmPassword, + }); + } + + return r.validation(value); + }} + /> + ))} + +