From 15985710902e6f01dee2b89e30b89482afa51c85 Mon Sep 17 00:00:00 2001 From: Saurabh Salunke Date: Tue, 21 May 2024 20:32:13 +0530 Subject: [PATCH] Fixes: #83 Login and signup Form Validation fixed --- src/Pages/Login.jsx | 66 +++++++++++++++++------ src/Pages/Signup.jsx | 123 ++++++++++++++++++++++++++++++++----------- 2 files changed, 141 insertions(+), 48 deletions(-) diff --git a/src/Pages/Login.jsx b/src/Pages/Login.jsx index 590ba95..3f579bf 100644 --- a/src/Pages/Login.jsx +++ b/src/Pages/Login.jsx @@ -1,6 +1,8 @@ import React, { useEffect, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import google from '../assets/google.png' +import { IoEyeOutline, IoEyeOffOutline } from "react-icons/io5"; + const Login = () => { const [active, setActive] = useState(true); const [email, setEmail] = useState(""); @@ -9,6 +11,7 @@ const Login = () => { const [isPasswordValid, setIsPasswordValid] = useState(false); const [isEmailFocused, setIsEmailFocused] = useState(false); const [isPasswordFocused, setIsPasswordFocused] = useState(false); + const [isPasswordVisible, setIsPasswordVisible] = useState(false); const navigate = useNavigate(); const handleLogin = async (e) => { e.preventDefault(); @@ -48,23 +51,52 @@ const Login = () => { * Password is not valid )} - { - setPassword(e.target.value); - setIsPasswordValid( - e.target.value.trim().length > 0 && - e.target.value.trim().length >= 8 - ); +
{ - setIsEmailFocused(false); - setIsPasswordFocused(true); - }} - /> + > + { + setPassword(e.target.value); + setIsPasswordValid( + e.target.value.trim().length > 0 && + e.target.value.trim().length >= 8 + ); + }} + onFocus={() => { + setIsEmailFocused(false); + setIsPasswordFocused(true); + }} + /> +
setIsPasswordVisible(!isPasswordVisible)} + > + {!isPasswordVisible ? ( + + ) : ( + + )} +
+
-

+

{"Don't have an account?"} { const navigate = useNavigate(); const [email, setEmail] = useState(""); @@ -11,6 +12,8 @@ const Signup = () => { const [isPasswordFocused, setIsPasswordFocused] = useState(false); const [isConfirmPasswordValid,setIsConfirmPasswordValid] = useState(false) const [isConfirmPasswordFocused,setIsConfirmPasswordFocused]=useState(false) + const [isPasswordVisible, setIsPasswordVisible] = useState(false); + const [isConfirmPasswordVisible, setConfirmIsPasswordVisible] = useState(false); const handleSignUp = async (e) => { e.preventDefault(); console.log(email, " ", password," ",confirmPassword); @@ -53,45 +56,103 @@ const Signup = () => { * Password is not valid )} - { - setPassword(e.target.value); - setIsPasswordValid( - e.target.value.trim().length > 0 && - e.target.value.trim().length >= 8 - ); +

{ - setIsEmailFocused(false); - setIsPasswordFocused(true); - setIsConfirmPasswordFocused(false); - }} - /> + > + { + setPassword(e.target.value); + setIsPasswordValid( + e.target.value.trim().length > 0 && + e.target.value.trim().length >= 8 + ); + }} + onFocus={() => { + setIsEmailFocused(false); + setIsPasswordFocused(true); + setIsConfirmPasswordFocused(false); + }} + /> +
setIsPasswordVisible(!isPasswordVisible)} + > + {!isPasswordVisible ? ( + + ) : ( + + )} +
+
{isConfirmPasswordFocused && !isConfirmPasswordValid && (
* Password doesn't match
)} - { - setConfirmPassword(e.target.value); - setIsConfirmPasswordValid(e.target.value === password); +
{ - setIsEmailFocused(false); - setIsPasswordFocused(false); - setIsConfirmPasswordFocused(true); - }} - /> + > + { + setConfirmPassword(e.target.value); + setIsConfirmPasswordValid(e.target.value === password); + }} + onFocus={() => { + setIsEmailFocused(false); + setIsPasswordFocused(false); + setIsConfirmPasswordFocused(true); + }} + /> +
+ setConfirmIsPasswordVisible(!isConfirmPasswordVisible) + } + > + {!isConfirmPasswordVisible ? ( + + ) : ( + + )} +
+