diff --git a/src/Pages/Signup/Signup.scss b/src/Pages/Signup/Signup.scss index 537191e..c4ce7f9 100644 --- a/src/Pages/Signup/Signup.scss +++ b/src/Pages/Signup/Signup.scss @@ -76,6 +76,7 @@ input { width: 100%; border: 2px solid $border-color; + height: 30px; } input::placeholder { color: grey; @@ -94,10 +95,25 @@ } } } - - .btn { + .seller-checkbox{ + + height: 30px; + margin-bottom: 10px; + display: flex; + justify-content: space-between; + align-items: center; + box-shadow: 1px 1px 2px 2px $primary-color; + border-radius: 5px; + padding: 4px; + } + .signup-buttons{ + display: flex; + justify-content: space-between; + height: 45px; + .btn { display: block; - width: 100%; + width: 46%; + height: 40px; padding: $btn-padding; margin: 0; font-size: $btn-font-size; @@ -117,14 +133,15 @@ display: flex; align-items: center; justify-content: center; - width: 100%; + width: 46%; + height: 40px; padding: $btn-padding; margin: 0; font-size: $btn-font-size; color: #fff; // background-color: $primary-color; border: none; - border-radius: 4px; + // border-radius: 4px; cursor: pointer; text-align: center; @@ -163,7 +180,9 @@ text-decoration: underline; } } + } } + .text-right { text-align: right; diff --git a/src/Pages/Signup/Signup.tsx b/src/Pages/Signup/Signup.tsx index ae84a42..30af728 100644 --- a/src/Pages/Signup/Signup.tsx +++ b/src/Pages/Signup/Signup.tsx @@ -1,19 +1,17 @@ -import React, { - useState, ChangeEvent, FormEvent, useEffect, -} from 'react'; -import { useDispatch, useSelector } from 'react-redux'; -import axios from 'axios'; -import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { ThunkDispatch } from '@reduxjs/toolkit'; -import { useGoogleLogin } from '@react-oauth/google'; -import { AnyAction } from 'redux'; -import { RootState } from '../../redux/store'; -import { signupUser } from '../../redux/slices/SignupSlice'; -import { googleLoginUser } from '../../redux/slices/googleLoginSlice'; -import './Signup.scss'; -import Spinner from '../../components/Spinner/Spinner'; -import Toast from '../../components/Toast/Toast'; +import React, { useState, ChangeEvent, FormEvent, useEffect } from "react"; +import { useDispatch, useSelector } from "react-redux"; +import axios from "axios"; +import { faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { ThunkDispatch } from "@reduxjs/toolkit"; +import { useGoogleLogin } from "@react-oauth/google"; +import { AnyAction } from "redux"; +import { RootState } from "../../redux/store"; +import { signupUser } from "../../redux/slices/SignupSlice"; +import { googleLoginUser } from "../../redux/slices/googleLoginSlice"; +import "./Signup.scss"; +import Spinner from "../../components/Spinner/Spinner"; +import Toast from "../../components/Toast/Toast"; interface FormData { firstName: string; @@ -21,32 +19,36 @@ interface FormData { email: string; password: string; confirmPassword: string; + isSeller: boolean; } const validatePassword = (password: string): boolean => { - const passwordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; + const passwordRegex = + /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; return passwordRegex.test(password); }; const Signup: React.FC = () => { const dispatch: ThunkDispatch = useDispatch(); - const { - loading, isSucceeded, userInfo, error, - } = useSelector( - (state: RootState) => state.signup, + const { loading, isSucceeded, userInfo, error } = useSelector( + (state: RootState) => state.signup ); + const [isChecked, setIsChecked] = useState(false); + const handleCheckboxChange = () => { + setIsChecked(!isChecked); + setFormData({ ...formData, isSeller: !isChecked }); +}; const [formData, setFormData] = useState({ - firstName: '', - lastName: '', - email: '', - password: '', - confirmPassword: '', + firstName: "", + lastName: "", + email: "", + password: "", + confirmPassword: "", + isSeller:false }); const [formErrors, setFormErrors] = useState>({}); - const { - firstName, lastName, email, password, confirmPassword, - } = formData; + const { firstName, lastName, email, password, confirmPassword,isSeller } = formData; const [showPassword, setShowPassword] = useState(false); const handleChange = (e: ChangeEvent) => { @@ -55,11 +57,13 @@ const Signup: React.FC = () => { const validateForm = () => { const errors: Partial = {}; - if (!firstName.trim()) errors.firstName = 'First name is required'; - if (!lastName.trim()) errors.lastName = 'Last name is required'; - if (!password.trim()) errors.password = 'Password is required'; - else if (!validatePassword(password)) errors.password = 'Password is not strong'; - if (password !== confirmPassword) errors.confirmPassword = 'Passwords do not match'; + if (!firstName.trim()) errors.firstName = "First name is required"; + if (!lastName.trim()) errors.lastName = "Last name is required"; + if (!password.trim()) errors.password = "Password is required"; + else if (!validatePassword(password)) + errors.password = "Password is not strong"; + if (password !== confirmPassword) + errors.confirmPassword = "Passwords do not match"; return errors; }; @@ -71,39 +75,51 @@ const Signup: React.FC = () => { return; } setFormErrors({}); - dispatch(signupUser({ - firstName, lastName, email, password, - })); + dispatch( + signupUser({ + firstName, + lastName, + email, + password, + isSeller + }) + + ); }; useEffect(() => { if (isSucceeded) { setFormData({ - firstName: '', - lastName: '', - email: '', - password: '', - confirmPassword: '', + firstName: "", + lastName: "", + email: "", + password: "", + confirmPassword: "", + isSeller:false }); + setIsChecked(false) } }, [isSucceeded]); const loginViaGoogle = useGoogleLogin({ onSuccess: async (tokenResponse) => { try { - const userInfo = await axios.get('https://www.googleapis.com/oauth2/v1/userinfo', { - headers: { - Authorization: `Bearer ${tokenResponse.access_token}`, - }, - }); + const userInfo = await axios.get( + "https://www.googleapis.com/oauth2/v1/userinfo", + { + headers: { + Authorization: `Bearer ${tokenResponse.access_token}`, + }, + } + ); dispatch(googleLoginUser(userInfo.data)); } catch (error) { - console.error('Error fetching user info:', error); + console.error("Error fetching user info:", error); } }, onError: (errorResponse) => { - console.error('Google login failure:', errorResponse); + console.error("Google login failure:", errorResponse); }, }); @@ -130,7 +146,7 @@ const Signup: React.FC = () => { placeholder="First Name" onChange={handleChange} className={`form-control ${ - formErrors.firstName ? 'is-invalid' : '' + formErrors.firstName ? "is-invalid" : "" }`} required /> @@ -148,7 +164,7 @@ const Signup: React.FC = () => { placeholder="Last Name" onChange={handleChange} className={`form-control ${ - formErrors.lastName ? 'is-invalid' : '' + formErrors.lastName ? "is-invalid" : "" }`} required /> @@ -168,20 +184,19 @@ const Signup: React.FC = () => { className="form-control" required /> -
@@ -199,14 +214,14 @@ const Signup: React.FC = () => {
@@ -220,36 +235,57 @@ const Signup: React.FC = () => { {formErrors.confirmPassword} )}
- -
+
+

Or

-
-
+ {/*
*/} +

- Already have an account? - {' '} - Login + Already have an account? Login

{loading && } - {!loading - && (isSucceeded ? ( - + {!loading && + (isSucceeded ? ( + ) : ( error && ))} diff --git a/src/redux/slices/SignupSlice.ts b/src/redux/slices/SignupSlice.ts index a9ce775..a5cc5a6 100644 --- a/src/redux/slices/SignupSlice.ts +++ b/src/redux/slices/SignupSlice.ts @@ -7,6 +7,7 @@ interface UserData { lastName: string; email: string; password: string; + isSeller:boolean } interface UserInfoInterface extends UserData {