From 2f6d80a4d3765666c9cb80753ed7a8b595e94e94 Mon Sep 17 00:00:00 2001 From: AdithaBuwaneka Date: Tue, 22 Jul 2025 23:04:41 +0530 Subject: [PATCH] feat: add password visibility toggle for login and registration forms --- src/app/login/page.tsx | 122 +++++++++++++++++++----- src/app/register/page.tsx | 191 +++++++++++++++++++++++++++++++------- 2 files changed, 254 insertions(+), 59 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index d5312d0b..022d06bf 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -40,6 +40,9 @@ const Login = () => { }>({}); const [isLoading, setIsLoading] = useState(false); const [isGoogleLoading, setIsGoogleLoading] = useState(false); + + // Password visibility state + const [showPassword, setShowPassword] = useState(false); // Redirect if already logged in useEffect(() => { @@ -106,24 +109,24 @@ const Login = () => { ); // If user is suspended, show the popup and abort -if (result.suspended) { - showSuspendedPopup(result.message, result.suspensionDetails); - return; -} + if (result.suspended) { + showSuspendedPopup(result.message, result.suspensionDetails); + return; + } -if (result.success) { - showToast('Login successful! Redirecting...', 'success'); - // …redirect logic… - const redirectUrl = sessionStorage.getItem('redirectAfterLogin'); - if (redirectUrl) { - sessionStorage.removeItem('redirectAfterLogin'); - router.push(redirectUrl); + if (result.success) { + showToast('Login successful! Redirecting...', 'success'); + // …redirect logic… + const redirectUrl = sessionStorage.getItem('redirectAfterLogin'); + if (redirectUrl) { + sessionStorage.removeItem('redirectAfterLogin'); + router.push(redirectUrl); + } else { + router.push('/dashboard'); + } } else { - router.push('/dashboard'); + showToast(result.message || 'Login failed', 'error'); } -} else { - showToast(result.message || 'Login failed', 'error'); -} } catch (error) { showToast('An error occurred. Please try again.', 'error'); @@ -149,14 +152,14 @@ if (result.success) { console.log('Google login result:', result); // 2 Suspension check - if (result.suspended) { - showSuspendedPopup( - result.message, - result.suspensionDetails, - () => console.log('User closed suspension popup') - ); - return; // stop here - } + if (result.suspended) { + showSuspendedPopup( + result.message, + result.suspensionDetails, + () => console.log('User closed suspension popup') + ); + return; // stop here + } if (result.success) { // Cancel any remaining Google prompts to prevent additional popups @@ -196,6 +199,11 @@ if (result.success) { showToast(error, 'error'); }; + // Toggle password visibility + const togglePasswordVisibility = () => { + setShowPassword(!showPassword); + }; + // Show loading state while checking auth status if (authLoading) { return ( @@ -273,14 +281,62 @@ if (result.success) { + {errors.password && (

{errors.password}

@@ -351,6 +407,22 @@ if (result.success) { + + ); }; diff --git a/src/app/register/page.tsx b/src/app/register/page.tsx index 4e0f14f3..b8e042dc 100644 --- a/src/app/register/page.tsx +++ b/src/app/register/page.tsx @@ -8,10 +8,6 @@ import { useAuth } from "@/lib/context/AuthContext"; import { useToast } from "@/lib/context/ToastContext"; import { handleSuspensionApiResponse } from '@/components/ui/SuspendedPopup' - - - - interface FormErrors { firstName?: string; lastName?: string; @@ -41,6 +37,10 @@ const Register = () => { const [errors, setErrors] = useState({}); const [isLoading, setIsLoading] = useState(false); const [agreeToTerms, setAgreeToTerms] = useState(false); + + // Password visibility states + const [showPassword, setShowPassword] = useState(false); + const [showConfirmPassword, setShowConfirmPassword] = useState(false); const validateForm = () => { const newErrors: FormErrors = {}; @@ -150,9 +150,6 @@ const Register = () => { try { const result = await register(formData); - - - // Check if the response indicates the user is suspended if (handleSuspensionApiResponse(result)) { // User is suspended, popup has been shown @@ -192,6 +189,16 @@ const Register = () => { } }; + // Toggle password visibility + const togglePasswordVisibility = () => { + setShowPassword(!showPassword); + }; + + // Toggle confirm password visibility + const toggleConfirmPasswordVisibility = () => { + setShowConfirmPassword(!showConfirmPassword); + }; + return (
@@ -357,19 +364,69 @@ const Register = () => { > Password - +
+ + +
{errors.password && (

{errors.password} @@ -384,19 +441,69 @@ const Register = () => { > Confirm Password - +

+ + +
{errors.confirmPassword && (

{

+ + ); }; -export default Register; +export default Register; \ No newline at end of file