From 7a7f327a0b5f1fc82c23cdaf221ac771b0b73f11 Mon Sep 17 00:00:00 2001 From: Rohitha Pudu Date: Tue, 18 Jun 2024 20:10:59 +0530 Subject: [PATCH] add password visibility toggle in login and signup --- src/app/login/page.tsx | 64 ++++++++++------- src/app/sign-up/page.tsx | 146 +++++++++++++++++++++++---------------- 2 files changed, 126 insertions(+), 84 deletions(-) diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index d952a77..82dc140 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -3,33 +3,35 @@ import React, { useState } from "react"; import Navbar from "../Components/Navbar"; import { toast } from "react-toastify"; -import { AiOutlineLoading3Quarters } from "react-icons/ai"; +import { AiOutlineLoading3Quarters, AiFillEye, AiFillEyeInvisible } from "react-icons/ai"; import { useRouter } from "next/navigation"; import { Auth } from "../api/apiCall"; import Link from "next/link"; const Page = () => { const router = useRouter(); - const [isLoading, setisLoading] = useState(false); + const [isLoading, setIsLoading] = useState(false); const [User, setUser] = useState({ UserName: "", Password: "", }); - const handleChange = (event: React.ChangeEvent) => { + const [showPassword, setShowPassword] = useState(false); // State for password visibility + + const handleChange = (event) => { setUser({ ...User, [event.target.name]: event.target.value, }); }; - const handleSubmit = async (event: React.FormEvent) => { + const handleSubmit = async (event) => { event.preventDefault(); - setisLoading(true); + setIsLoading(true); const res = await Auth(User); - setisLoading(false); - if (res.data?.status != "Failed") { - localStorage.setItem('UserId',res.data.response.data._id) - toast("Organization Submitted !", { + setIsLoading(false); + if (res.data?.status !== "Failed") { + localStorage.setItem('UserId', res.data.response.data._id); + toast("Login Successful!", { position: "top-right", autoClose: 5000, hideProgressBar: false, @@ -41,7 +43,7 @@ const Page = () => { }); router.push("/dashboard"); } else { - toast.error("Failed to Login !", { + toast.error("Failed to Login!", { position: "top-right", autoClose: 5000, hideProgressBar: false, @@ -53,6 +55,11 @@ const Page = () => { }); } }; + + const togglePasswordVisibility = () => { + setShowPassword(!showPassword); + }; + return ( <> @@ -78,16 +85,28 @@ const Page = () => {
- +
+ + +
{isLoading ? ( - ) : ( - - )} -

Already Have Account Login

- - + + + {isLoading ? ( + + ) : ( + + )} +

+ Already Have an Account?{" "} + + Login + +

+ + ); };