diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 437efda..e6e0351 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -5,6 +5,7 @@ import { motion, AnimatePresence, useScroll } from "framer-motion"; import { IoClose } from "react-icons/io5"; import { GiHamburgerMenu } from "react-icons/gi"; import { ThemeContext } from '../themeContext'; + const Navbar = () => { const { theme, toggleTheme } = useContext(ThemeContext); const [isOpen, setIsOpen] = useState(false); @@ -16,109 +17,90 @@ const Navbar = () => { return ( <> - + ); }; @@ -135,11 +117,11 @@ const NavItem = ({ icon, to, children }) => { }; const MobileNavItem = ({ to, children }) => { - let classname = "z-[2] text-gray-300 text-center hover:text-white block px-3 py-2 rounded-md text-xl font-medium "; + const classname = "z-[2] text-gray-300 text-center hover:text-white block px-3 py-2 rounded-md text-xl font-medium "; return ( {children} @@ -152,6 +134,4 @@ const IconAbout = () => ℹī¸; const IconNews = () => 📰; const IconRateUs = () => ⭐; - export default Navbar; - diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index 9767f7e..00ef4d4 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -1,25 +1,23 @@ - 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 Loader from "../components/Loader/Loader"; +import Loader from "../components/Loader/Loader"; // Ensure this path is correct import { useAuth } from "../authContext"; + function Login() { const [formData, setFormData] = useState({ email: "", - accountType : "", + accountType: "", password: "", }); const { checkAuthentication } = useAuth(); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); - const [rememberMe, setRememberMe] = useState(false); + const [rememberMe, setRememberMe] = useState(false); const navigate = useNavigate(); @@ -41,43 +39,38 @@ function Login() { })); } - function rememberMeHandler(event) { setRememberMe(event.target.checked); + if (!event.target.checked) { + localStorage.removeItem("rememberedEmail"); + } } async function submitHandler(event) { event.preventDefault(); + setLoading(true); - - if(formData.accountType === "User"){ - - 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") - }); + if (rememberMe) { + localStorage.setItem("rememberedEmail", formData.email); } - else{ + const apiUrl = + formData.accountType === "User" + ? `${process.env.REACT_APP_BASE_URL}/studentLogin` + : `${process.env.REACT_APP_BASE_URL}/canteenLogin`; - const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenLogin`; - - axios.post(apiUrl , formData) - .then((response)=>{ - toast.success("User Logged in "); + try { + const response = await axios.post(apiUrl, formData); + toast.success("User Logged in"); + if (formData.accountType === "User") { + navigate("/home"); + } else { navigate(`/section/${response.data.cantId}`); - }) - .catch((error)=>{ - toast.error("Failed to login") - }); - + } + } catch (error) { + toast.error("Failed to login"); + } finally { + setLoading(false); } } @@ -89,9 +82,7 @@ function Login() {
- @@ -108,55 +99,10 @@ function Login() {
- -
- -
- -
- logo -

Connecting You to Your College Canteens

-
- -
-
-
-
- -
- -
- -
- -

Hello Again!

-

Welcome Back

- -
- -
- -
- -

- Hello Again! -

-

- Welcome Back -

- + +

Hello Again!

+

Welcome Back

-
-
setShowPassword((prev) => !prev)} > {showPassword ? ( - - ) : ( + ) : ( + )}
-
-

Forgot Password ?

-
- -
- - setShowPassword((prev) => !prev)} - > - {showPassword ? : } - + Login + + + + Don't have an account? Sign Up + + +
- - - - - Don't have an account? Sign Up - - - - -
- -
+
+ )} + ); } export default Login; - diff --git a/src/pages/Signup.jsx b/src/pages/Signup.jsx index afb10d0..4f1076a 100644 --- a/src/pages/Signup.jsx +++ b/src/pages/Signup.jsx @@ -3,10 +3,10 @@ import { Link, useNavigate } from "react-router-dom"; import { AiOutlineEye, AiOutlineEyeInvisible } from "react-icons/ai"; import { toast } from "react-hot-toast"; import axios from "axios"; -import logo from "../assets/logo2.png" +import logo from "../assets/logo2.png"; import Icon from 'react-icons-kit'; -import { arrows_circle_check } from 'react-icons-kit/linea/arrows_circle_check' -import { arrows_exclamation } from 'react-icons-kit/linea/arrows_exclamation' +import { arrows_circle_check } from 'react-icons-kit/linea/arrows_circle_check'; +import { arrows_exclamation } from 'react-icons-kit/linea/arrows_exclamation'; function Signup() { const [formData, setFormData] = useState({ @@ -19,14 +19,13 @@ function Signup() { }); const [showconfirmPassword, setshowconfirmPassword] = useState(false); - const [showPassword, setShowPassword] = useState(false); const [lowerValidated, setLowerValidated] = useState(false); const [upperValidated, setUpperValidated] = useState(false); const [numberValidated, setNumberValidated] = useState(false); const [specialValidated, setSpecialValidated] = useState(false); const [lengthValidated, setLengthValidated] = useState(false); - + const [loading, setLoading] = useState(false); const navigate = useNavigate(); @@ -34,44 +33,19 @@ function Signup() { const lower = new RegExp('(?=.*[a-z])'); const upper = new RegExp('(?=.*[A-Z])'); const number = new RegExp('(?=.*[0-9])'); - const special = new RegExp('(?=.*[!@#\$%\^&\*])'); - const length = new RegExp('(?=.{8,})') + const special = new RegExp('(?=.*[!@#\\$%\\^&\\*])'); + const length = new RegExp('(?=.{8,})'); const value = event.target.value; - if (lower.test(value)) { - setLowerValidated(true); - } - else { - setLowerValidated(false); - } - if (upper.test(value)) { - setUpperValidated(true); - } - else { - setUpperValidated(false); - } - if (number.test(value)) { - setNumberValidated(true); - } - else { - setNumberValidated(false); - } - if (special.test(value)) { - setSpecialValidated(true); - } - else { - setSpecialValidated(false); - } - if (length.test(value)) { - setLengthValidated(true); - } - else { - setLengthValidated(false); - } + setLowerValidated(lower.test(value)); + setUpperValidated(upper.test(value)); + setNumberValidated(number.test(value)); + setSpecialValidated(special.test(value)); + setLengthValidated(length.test(value)); setFormData((prevData) => ({ ...prevData, - [event.target.name]: event.target.value, + [event.target.name]: value, })); } @@ -82,52 +56,36 @@ function Signup() { })); } - function submitHandler(event) { + async function submitHandler(event) { event.preventDefault(); - console.log("ENV FILE",process.env.REACT_APP_BASE_URL); + console.log("ENV FILE", process.env.REACT_APP_BASE_URL); if (lowerValidated && upperValidated && numberValidated && specialValidated && lengthValidated) { - if (formData.accountType === "User") { + const apiUrl = formData.accountType === "User" + ? `${process.env.REACT_APP_BASE_URL}/studentSignup` + : `${process.env.REACT_APP_BASE_URL}/canteenSignup`; - const apiUrl = `${process.env.REACT_APP_BASE_URL}/studentSignup`; - // const apiUrl = `http://localhost:3000/api/v1/studentSignUp`; - try { - setLoading(true); + try { + setLoading(true); - const response = await axios.post(apiUrl, formData); + const response = await axios.post(apiUrl, formData); - toast.success("Account Created Successfully!"); - navigate("/"); - } catch (error) { - const errorMessage = - error.response?.data?.message || - "Failed to login. Please try again."; - toast.error(errorMessage); - console.log("This is our error ", error); - } finally { - setLoading(false); - } - } else { - const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenSignup`; - // const apiUrl = `${process.env.REACT_APP_BASE_URL}/canteenSignup`; - - try { - setLoading(true); - - const response = await axios.post(apiUrl, formData); + if (formData.accountType === "Canteen") { const token = response.data.token; - localStorage.setItem("token", token); localStorage.setItem("canteenId", response.data.cantId); - toast.success("Account Created Successfully!"); navigate(`/section/${response.data.cantId}`); - } catch (error) { - toast.error("Failed To Create Account. Please try again."); - console.error(error); - } finally { - setLoading(false); + } else { + navigate("/"); } + toast.success("Account Created Successfully!"); + } catch (error) { + const errorMessage = error.response?.data?.message || "Failed to create account. Please try again."; + toast.error(errorMessage); + console.error("Error:", error); + } finally { + setLoading(false); } } else { toast.error("Password must pass all the criteria"); @@ -135,15 +93,12 @@ function Signup() { } return ( -
+
logo -

- Connecting You to Your College Canteens -

+

Connecting You to Your College Canteens

-
@@ -151,16 +106,9 @@ function Signup() {
-
-

- Hello There! -

-

- Create an Account -

+ +

Hello There!

+

Create an Account

- @@ -224,146 +172,97 @@ function Signup() { value={formData.password} onChange={PasswordChecker} /> + setShowPassword((prev) => !prev)}> + {showPassword ? : } + +
+ +
+ setShowPassword((prev) => !prev)} + onClick={() => setshowconfirmPassword((prev) => !prev)} > - {showPassword ? ( - - ) : ( - - )} + {showconfirmPassword ? : }
- -
- - setshowconfirmPassword((prev) => !prev)} - > - {showconfirmPassword ? ( - - ) : ( - - )} - -
- - + - Already have an account? Login + + Already have an account? Login + - {/* - - Validation Checks for password - - */} - -
+
- {lowerValidated ? ( - - - - ) : ( - - - - )} + + + At least one lowercase letter
- {upperValidated ? ( - - - - ) : ( - - - - )} + + + At least one uppercase letter
- {numberValidated ? ( - - - - ) : ( - - - - )} + + + At least one number
- {specialValidated ? ( - - - - ) : ( - - - - )} + + + At least one special character
- {lengthValidated ? ( - - - - ) : ( - - - - )} + + + At least 8 characters
-
+
);