diff --git a/src/Pages/Login.tsx b/src/Pages/Login.tsx index 8670ecf..9db1596 100644 --- a/src/Pages/Login.tsx +++ b/src/Pages/Login.tsx @@ -1,45 +1,45 @@ -import { Center, HStack, Image, Input, Text, VStack } from "@chakra-ui/react"; -import axios from "axios"; -import { useContext, useState } from "react"; -import { useForm } from "react-hook-form"; -import { useDispatch } from "react-redux"; -import GlobalStateContext from "../Contexts/GlobalStateContext"; -import { setToken } from "../Redux/Service/authSlice"; -import logo from "../assets/logo.svg"; -import { Button } from "../components/ui/button"; -import { Field } from "../components/ui/field"; -import { Toaster } from "../components/ui/toaster"; -import { PasswordInput } from "../components/ui/password-input"; -import { useNavigate } from "react-router-dom"; +import { Center, HStack, Image, Input, Text, VStack } from "@chakra-ui/react" +import axios from "axios" +import { useContext, useState } from "react" +import { useForm } from "react-hook-form" +import { useDispatch } from "react-redux" +import GlobalStateContext from "../Contexts/GlobalStateContext" +import { setToken } from "../Redux/Service/authSlice" +import logo from '../assets/logo.svg' +import { Button } from "../components/ui/button" +import { Field } from "../components/ui/field" +import { Toaster } from "../components/ui/toaster" +import { PasswordInput } from "../components/ui/password-input" +import { useNavigate } from "react-router-dom" interface FormValues { - mobileNumber: number; - password: string; + mobileNumber: number + password: string } const Login = () => { - const navigate = useNavigate(); - const dispatch = useDispatch(); - const [isLoading, setIsLoading] = useState(false); + const navigate = useNavigate() + const dispatch = useDispatch() + const [isLoading, setIsLoading] = useState(false) const context = useContext(GlobalStateContext); if (!context) { - throw new Error("App must be used within a GlobalStateProvider"); + throw new Error('App must be used within a GlobalStateProvider'); } const { setIsAuthenticate } = context; const { register, handleSubmit, formState: { errors }, - } = useForm(); + } = useForm() const onSubmit = handleSubmit(async (data) => { setIsLoading(true); - + // Encode Basic Auth Credentials - const username = import.meta.env.VITE_USER_NAME || ""; // Replace with actual username - const password = import.meta.env.VITE_PASSWORD || ""; // Replace with actual password + const username = import.meta.env.VITE_USER_NAME||''; // Replace with actual username + const password = import.meta.env.VITE_PASSWORD||''; // Replace with actual password const basicAuth = `${username} : ${password}`; // Encode to Base64 - + try { const res = await axios.post( `${import.meta.env.VITE_API_URL}/login`, @@ -56,139 +56,84 @@ const Login = () => { ); if (res.data) { - setIsAuthenticate(true); - console.log("===================================="); + setIsAuthenticate(true) + console.log('===================================='); console.log(res.data?.data); - console.log("===================================="); - navigate("/"); + console.log('===================================='); + navigate('/') dispatch(setToken(String(res.data?.data["access-token"]))); } else { + console.log("===================================="); console.log(res); console.log("===================================="); + } + } catch (error) { if (error) { + console.error("Login failed", error); - setIsLoading(false); + setIsLoading(false) + } } }); + + + return ( - - + + + + + + - -
+ + + + + + +
-
- - - LOGIN - - -
-
- - - LOGIN - - - - - {/* Forget password */} + + +
+ + LOGIN + + + + + {/* Forget password */} - - - {/* Forget password */} + + + {/* Forget password */} - + Forgot password + +
- ); -}; + ) +} -export default Login; +export default Login \ No newline at end of file diff --git a/src/main.tsx b/src/main.tsx index 5bc746e..c983e7f 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,23 +1,27 @@ -import React from 'react' -import ReactDOM from 'react-dom/client' -import App from './App' +import React from "react"; +import ReactDOM from "react-dom/client"; +import App from "./App"; import { Provider as ReduxProvider } from "react-redux"; -import { Provider } from './components/ui/provider' -import GlobalStateProvider from './Contexts/GlobalStateProvider' -import './index.css' -import { Theme } from '@chakra-ui/react' -import { store } from './Redux/Store' +import { Provider } from "./components/ui/provider"; +import GlobalStateProvider from "./Contexts/GlobalStateProvider"; +import "./index.css"; +import { Theme } from "@chakra-ui/react"; +import { store } from "./Redux/Store"; -ReactDOM.createRoot(document.getElementById('root')!).render( - - {/* ✅ Wrap with Redux Provider */} +ReactDOM.createRoot(document.getElementById("root")!).render( + + + {" "} + {/* ✅ Wrap with Redux Provider */} - {/* ✅ Wrap with Provider */} - - + + {" "} + {/* ✅ Wrap with Provider */} + + -) \ No newline at end of file +);