From a0ca0c783847bfa33b937bdec7c25d144e80e270 Mon Sep 17 00:00:00 2001 From: Ayush Chugh Date: Fri, 7 Jun 2024 23:19:41 +0530 Subject: [PATCH] fix: :lock: removed `env` link from console --- src/pages/Signup.jsx | 724 ++++++++++++++++++++----------------------- 1 file changed, 338 insertions(+), 386 deletions(-) diff --git a/src/pages/Signup.jsx b/src/pages/Signup.jsx index 3d62a48..7ba0dd4 100644 --- a/src/pages/Signup.jsx +++ b/src/pages/Signup.jsx @@ -1,12 +1,6 @@ import React, { useState } from "react"; -import { - Link, - useNavigate, -} from "react-router-dom"; -import { - AiOutlineEye, - AiOutlineEyeInvisible, -} from "react-icons/ai"; +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"; @@ -16,413 +10,371 @@ import { arrows_exclamation } from "react-icons-kit/linea/arrows_exclamation"; import Loader from "../components/Loader/Loader"; function Signup() { - const [formData, setFormData] = useState({ - name: "", - email: "", - collegeName: "", - accountType: "", - password: "", - }); + const [formData, setFormData] = useState({ + name: "", + email: "", + collegeName: "", + accountType: "", + password: "", + }); - 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 [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(); - const navigate = useNavigate(); + function PasswordChecker(event) { + 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 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); + } - function PasswordChecker(event) { - 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 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); - } + setFormData(prevData => ({ + ...prevData, + [event.target.name]: event.target.value, + })); + } - setFormData((prevData) => ({ - ...prevData, - [event.target.name]: event.target.value, - })); - } + function changeHandler(event) { + setFormData(prevData => ({ + ...prevData, + [event.target.name]: event.target.value, + })); + } - function changeHandler(event) { - setFormData((prevData) => ({ - ...prevData, - [event.target.name]: event.target.value, - })); - } + async function submitHandler(event) { + event.preventDefault(); - async function submitHandler(event) { - event.preventDefault(); - console.log( - "ENV FILE", - process.env.REACT_APP_BASE_URL - ); + if ( + lowerValidated && + upperValidated && + numberValidated && + specialValidated && + lengthValidated + ) { + if (formData.accountType === "User") { + // const apiUrl = `http://localhost:8000/api/v1/studentSignup`; + const apiUrl = `http://localhost:8000/api/v1/studentSignup`; + try { + setLoading(true); - if ( - lowerValidated && - upperValidated && - numberValidated && - specialValidated && - lengthValidated - ) { - if (formData.accountType === "User") { - // const apiUrl = `http://localhost:8000/api/v1/studentSignup`; - const apiUrl = `http://localhost:8000/api/v1/studentSignup`; - try { - setLoading(true); - - const response = await axios.post(apiUrl, formData); - - toast.success("Account Created Successfully!"); - navigate("/home"); - } catch (error) { - toast.error("Failed To Create Account. Please try again."); - console.error(error); - } finally { - setLoading(false); - } - } else { - const apiUrl = `http://localhost:8000/api/v1/canteenSignup` - // const apiUrl = `http://localhost:8000/api/v1/canteenSignup`; - try { - setLoading(true); - - const response = await axios.post(apiUrl, formData); - 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); - } + const response = await axios.post(apiUrl, formData); - } - } else { - toast.error( - "Password must pass all the criteria" - ); - } - } + toast.success("Account Created Successfully!"); + navigate("/home"); + } catch (error) { + toast.error("Failed To Create Account. Please try again."); + console.error(error); + } finally { + setLoading(false); + } + } else { + const apiUrl = `http://localhost:8000/api/v1/canteenSignup`; + // const apiUrl = `http://localhost:8000/api/v1/canteenSignup`; + try { + setLoading(true); - return ( - <> - { - loading ? ( - - ) : ( - <> -
-
-
- logo -

- Connecting You to Your College - Canteens -

-
+ const response = await axios.post(apiUrl, formData); + 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 { + toast.error("Password must pass all the criteria"); + } + } -
-
-

- Hello There! -

-

- Create an Account -

+ return ( + <> + {loading ? ( + + ) : ( + <> +
+
+
+ logo +

+ Connecting You to Your College Canteens +

+
-
- -
+
+
+
+
+
-
- -
+
+ +

+ Hello There! +

+

+ Create an Account +

-
- -
+
+ +
-
- -
+
+ +
-
- - - setShowPassword((prev) => !prev) - }> - {showPassword ? ( - - ) : ( - - )} - -
+
+ +
- +
+ + setShowPassword(prev => !prev)} + > + {showPassword ? ( + + ) : ( + + )} + +
- - - 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 -
-
- -
- -
- ); - - ) - } - - ) + .list-icon.green { + color: #006400; + } + `} + +
+ ); + + )} + + ); } export default Signup;