From a28d290febafbac413d181f961daf0df91a00ad1 Mon Sep 17 00:00:00 2001 From: Pramod Mahajan Date: Mon, 7 Apr 2025 17:17:21 +0530 Subject: [PATCH] hide or visible password --- .../authentication/ResetPasswordPage.jsx | 244 +++++++++++------- 1 file changed, 157 insertions(+), 87 deletions(-) diff --git a/src/pages/authentication/ResetPasswordPage.jsx b/src/pages/authentication/ResetPasswordPage.jsx index c933cd7c..fbcc0fef 100644 --- a/src/pages/authentication/ResetPasswordPage.jsx +++ b/src/pages/authentication/ResetPasswordPage.jsx @@ -4,68 +4,80 @@ import "./page-auth.css"; import { AuthWrapper } from "./AuthWrapper"; import showToast from "../../services/toastService"; import AuthRepository from "../../repositories/AuthRepository"; -import { z } from 'zod'; -import { useForm } from 'react-hook-form'; -import { zodResolver } from '@hookform/resolvers/zod'; +import { z } from "zod"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; import { useNavigate } from "react-router-dom"; -import {clearAllCache} from "../../slices/apiDataManager"; +import { clearAllCache } from "../../slices/apiDataManager"; -const resetPasswordSchema = z.object( { - email:z.string().email(), - password: z - .string() - .min(8, 'Password must be at least 8 characters') - .regex(/[A-Z]/, 'Password must contain at least one uppercase letter') - .regex(/[a-z]/, 'Password must contain at least one lowercase letter') - .regex(/\d/, 'Password must contain at least one number') - .regex(/[!@#$%^&*()_+{}\[\]:;<>,.?~\\/-]/, 'Password must contain at least one special character'), - - confirmPassword: z.string().min(8, 'Password must be at least 8 characters'), -}) - .refine((data) => data.password === data.confirmPassword, { - message: 'Passwords do not match', - path: ['confirmPassword'], - } ); - -const ResetPasswordPage = () => -{ - const [ searchParams ] = useSearchParams(); - const [loading,setLoading] = useState(false) +const resetPasswordSchema = z + .object({ + email: z.string().email(), + password: z + .string() + .min(8, "Password must be at least 8 characters") + .regex(/[A-Z]/, "Password must contain at least one uppercase letter") + .regex(/[a-z]/, "Password must contain at least one lowercase letter") + .regex(/\d/, "Password must contain at least one number") + .regex( + /[!@#$%^&*()_+{}\[\]:;<>,.?~\\/-]/, + "Password must contain at least one special character" + ), - const token = searchParams.get('token'); - const navigate = useNavigate() - - const {register,handleSubmit,formState: { errors }} = useForm({ - resolver:zodResolver(resetPasswordSchema) + confirmPassword: z + .string() + .min(8, "Password must be at least 8 characters"), }) + .refine((data) => data.password === data.confirmPassword, { + message: "Passwords do not match", + path: ["confirmPassword"], + }); + +const ResetPasswordPage = () => { + const [searchParams] = useSearchParams(); + const [loading, setLoading] = useState(false); + const [hidepass, setHidepass] = useState(true); + + const token = searchParams.get("token"); + const navigate = useNavigate(); + + const { + register, + handleSubmit, + formState: { errors }, + } = useForm({ + resolver: zodResolver(resetPasswordSchema), + }); + + const onSubmitResetPassword = async (data) => { + try { + setLoading(true); + const { email, password, confirmPassword } = data; - const onSubmitResetPassword = async(data) => { - try - { - setLoading(true) - const {email, password, confirmPassword} = data; - let reqObject = { - email, - token: token, - newPassword: password - } - let response = await AuthRepository.resetPassword( reqObject ); - showToast( "Password Reseted", "success" ) - clearAllCache() - setLoading(false) - navigate("/auth/login",{replace:true}) - } catch ( error ) - { - setLoading(false) - showToast("Token is expries or Invalid ","error") + email, + token: token, + newPassword: password, + }; + let response = await AuthRepository.resetPassword(reqObject); + showToast("Password Reseted", "success"); + clearAllCache(); + setLoading(false); + navigate("/auth/login", { replace: true }); + } catch (error) { + setLoading(false); + showToast("Token is expries or Invalid ", "error"); } }; return (

Reset Password? 🔒

Enter your email and new password to update.

-
+
-
- - - {errors.password &&
{errors.password.message}
} -
-
- - - {errors.confirmPassword &&
{errors.confirmPassword.message}
} + +
+
+ +
+
+ + setHidepass(!hidepass)} + > + {hidepass ? ( + + ) : ( + + )} + +
+ {errors.password && ( +
+ {errors.password.message} +
+ )} +
+ {" "} + {" "} +
+
+ + setHidepass(!hidepass)} + > + {hidepass ? ( + + ) : ( + + )} + +
+ {errors.confirmPassword && ( +
+ {errors.confirmPassword.message} +
+ )}
+
-

Password must be at least 8 characters

-

Password must contain at least one uppercase letter

-

Password must contain at least one number

-

Password must contain at least one special character

+

+ Password must be at least 8 characters +

+

+ Password must contain at least one uppercase letter +

+

+ Password must contain at least one number +

+

+ Password must contain at least one special character +