From a19dc5ceca9c90f917dcdb171f57c550cfefaef2 Mon Sep 17 00:00:00 2001 From: vanshika147 Date: Thu, 2 Oct 2025 18:04:26 +0530 Subject: [PATCH] Restructured Register page UI --- .../pages/login-register/Register.jsx | 73 ++++++++++++++----- 1 file changed, 55 insertions(+), 18 deletions(-) diff --git a/user/src/components/pages/login-register/Register.jsx b/user/src/components/pages/login-register/Register.jsx index 77aeba5a..81092aa5 100644 --- a/user/src/components/pages/login-register/Register.jsx +++ b/user/src/components/pages/login-register/Register.jsx @@ -27,6 +27,11 @@ const schema = z.object({ path: ["confirmPassword"] }); +// Calculates how many of the 5 passwoord criteria are met +const getPasswordScore = (strength) => { + return Object.values(strength).filter(Boolean).length; +}; + const RegisterForm = ({ setIsAuthenticated }) => { const navigate = useNavigate(); const [countryid, setCountryid] = useState(""); @@ -34,6 +39,8 @@ const RegisterForm = ({ setIsAuthenticated }) => { const [otp, setOtp] = useState(""); const [isPhoneVerified, setIsPhoneVerified] = useState(false); const [loading, setLoading] = useState(false); + const [isTypingPassword, setIsTypingPassword] = useState(false); + // ✅ Password toggle state const [showPassword, setShowPassword] = useState(false); @@ -55,16 +62,21 @@ const RegisterForm = ({ setIsAuthenticated }) => { // Track password strength React.useEffect(() => { - if (!password) return; - setPasswordStrength({ - length: password.length >= 8, - uppercase: /[A-Z]/.test(password), - lowercase: /[a-z]/.test(password), - number: /\d/.test(password), - symbol: /[!@#$%^&*(),.?":{}|<>]/.test(password), - }); + if (password && password.length > 0) { + setIsTypingPassword(true); + setPasswordStrength({ + length: password.length >= 8, + uppercase: /[A-Z]/.test(password), + lowercase: /[a-z]/.test(password), + number: /\d/.test(password), + symbol: /[!@#$%^&*(),.?":{}|<>]/.test(password), + }); + } else { + setIsTypingPassword(false); // hide when password is empty + } }, [password]); + // Google Sign-Up Handler const handleGoogleSignUp = async (id_token) => { try { @@ -244,13 +256,27 @@ const onSubmit = async (data) => { {showPassword ? : } {errors.password &&

{errors.password.message}

} -
- 8 characters - Uppercase - Lowercase - Number - Symbol + {/* Password Strength Progress Bar + Label */} + {isTypingPassword && ( +
+
+
+
+

+ Strength: { + ["Too Weak", "Too Weak", "Weak", "Medium", "Strong"][getPasswordScore(passwordStrength)] || "Too Weak" + } +

+ )}
{/* Confirm Password */} @@ -268,11 +294,22 @@ const onSubmit = async (data) => {
{/* Mobile + OTP */} -
- - + {errors.mobile &&

{errors.mobile.message}

} {otpSent && !isPhoneVerified && ( @@ -285,7 +322,7 @@ const onSubmit = async (data) => { )} {/* Profile Picture */} - + {/* */} {/* Country + State */}