From 70ef099b68407254a8b92dd88f1fe1a52a02d962 Mon Sep 17 00:00:00 2001 From: "Aditya_Parmar@dev" <105008414+Adityajparmar37@users.noreply.github.com> Date: Fri, 31 May 2024 16:27:16 +0530 Subject: [PATCH 01/19] Sign up and sign in will work as well as loader added to sign up and sign in page --- src/pages/Login.jsx | 281 +++++++++++++++++++++---------------- src/pages/Signup.jsx | 319 +++++++++++++++++++++++++++++-------------- 2 files changed, 381 insertions(+), 219 deletions(-) diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index b359ecd..8f62b85 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -1,18 +1,29 @@ -import React, { useState, useEffect } from "react"; -import { AiOutlineEye, AiOutlineEyeInvisible } from "react-icons/ai"; -import { Link, useNavigate } from "react-router-dom"; +import React, { + useState, + useEffect, +} from "react"; +import { + AiOutlineEye, + AiOutlineEyeInvisible, +} from "react-icons/ai"; +import { + Link, + useNavigate, +} from "react-router-dom"; import { toast } from "react-hot-toast"; import axios from "axios"; -import logo from "../assets/logo2.png" - +import logo from "../assets/logo2.png"; +import Loader from "../components/Loader/Loader"; function Login() { const [formData, setFormData] = useState({ email: "", - accountType : "", + accountType: "", password: "", }); - const [showPassword, setShowPassword] = useState(false); + const [showPassword, setShowPassword] = + useState(false); + const [loading, setLoading] = useState(false); const navigate = useNavigate(); function changeHandler(event) { @@ -22,127 +33,169 @@ function Login() { })); } - function submitHandler(event) { - - event.preventDefault(); - - - if(formData.accountType === "User"){ + if (formData.accountType === "User") { + //Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown + setLoading(true); const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentLogin`; - // const apiUrl = `http://localhost:4000/api/v1/studentLogin`; - - axios.post(apiUrl , formData) - .then((response)=>{ - toast.success("User Logged in "); - navigate("/home"); - }) - .catch((error)=>{ - toast.error("Failed to login") - }); - } - - else{ - + //const apiUrl = `http://localhost:4000/api/v1/studentLogin`; + + axios + .post(apiUrl, formData) + .then((response) => { + setLoading(false); + toast.success("User Logged in "); + navigate("/home"); + }) + .catch((error) => { + //Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown + setLoading(false); + toast.error("Failed to login"); + }); + } else { + //Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenLogin`; - - axios.post(apiUrl , formData) - .then((response)=>{ - toast.success("User Logged in "); - navigate(`/section/${response.data.cantId}`); - }) - .catch((error)=>{ - toast.error("Failed to login") - }); + setLoading(true); + + axios + .post(apiUrl, formData) + .then((response) => { + setLoading(false); + toast.success("User Logged in "); + navigate( + `/section/${response.data.cantId}` + ); + }) + .catch((error) => { + //Loader will show till the api fetching is done as show as promise is resolved the loader will be not shown + setLoading(false); + toast.error("Failed to login"); + }); } } return ( -
Connecting You to Your College Canteens
-