diff --git a/src/App.tsx b/src/App.tsx
index 638d685..1151917 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -2,11 +2,13 @@ import React, { useState } from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import "./styles.css";
+import Login from "./components/login/Login";
import Home from "./components/home/Home";
import Contacts from "./components/contacts/Contacts";
import Calendar from "./components/calendar/Calendar";
import Navbar from "./components/navbar/Navbar";
import { ThemeProvider } from "@emotion/react";
+import ProtectedRoute from "./ProtectedRoute";
import Theme from "./Theme";
@@ -47,9 +49,12 @@ const App: React.FC = () => {
- } />
- } />
- } />
+ } />
+ }>
+ } />
+ } />
+ } />
+
diff --git a/src/ProtectedRoute.tsx b/src/ProtectedRoute.tsx
new file mode 100644
index 0000000..927eb13
--- /dev/null
+++ b/src/ProtectedRoute.tsx
@@ -0,0 +1,12 @@
+import { useLocation, Outlet, Navigate } from "react-router-dom";
+import useAuth from "./hooks/useAuth";
+
+const ProtectedRoute = () => {
+ const { auth }: any = useAuth();
+ const location = useLocation();
+ return (
+ auth?.isLoggedIn ? :
+ );
+}
+
+export default ProtectedRoute;
\ No newline at end of file
diff --git a/src/components/login/Login.tsx b/src/components/login/Login.tsx
index cb3f046..c63160c 100644
--- a/src/components/login/Login.tsx
+++ b/src/components/login/Login.tsx
@@ -1,3 +1,5 @@
+import { useRef, useState, useEffect, useContext } from 'react';
+import { useLocation, Link, useNavigate } from "react-router-dom";
import { Stack } from "@mui/material";
import Container from "@mui/material/Container";
import TextField from "@mui/material/TextField";
@@ -5,17 +7,50 @@ import Button from "@mui/material/Button";
import hsbcLogo from "../../assets/logo-png.png";
import zoomLogo from "../../assets/zoom.png";
import LoginIcon from '@mui/icons-material/Login';
+import useAuth from "../../hooks/useAuth";
const Login: React.FC = () => {
+
+ const { setAuth }: any = useAuth();
+
+ const navigate = useNavigate();
+ const location: any = useLocation();
+ const from = location.state?.from?.pathname || "/";
+
+ const [username, setUsername] = useState('');
+ const [password, setPassword] = useState('');
+ // const [errMsg, setErrMsg] = useState('');
+
+ // const userRef = useRef();
+ // const errRef = useRef();
+
+ // useEffect(() => {
+ // userRef.current.focus();
+ // }, [])
+
+ // useEffect(() => {
+ // setErrMsg('');
+ // }, [user, pwd])
+
+ const handleLogin = () => {
+ if (username === "" && password === "") {
+ setAuth({username: username, isLoggedIn: true});
+ navigate(from, {replace: true});
+ }
+ setUsername("");
+ setPassword("");
+ };
+
return (
-
-
+ {/* {errMsg}
*/}
+ {setUsername(event.target.value)}}/>
+ {setPassword(event.target.value)}}/>
Forgotten Your Password?
- } className="login-btn" href="#" variant="contained">Login
+ } className="login-btn" variant="contained" type="submit" onClick={handleLogin}>Login
diff --git a/src/context/AuthProvider.tsx b/src/context/AuthProvider.tsx
new file mode 100644
index 0000000..cb661da
--- /dev/null
+++ b/src/context/AuthProvider.tsx
@@ -0,0 +1,15 @@
+import { createContext, useState } from "react";
+
+const AuthContext = createContext({});
+
+export const AuthProvider = ({ children }: {children: any}) => {
+ const [auth, setAuth] = useState({});
+
+ return (
+
+ {children}
+
+ )
+}
+
+export default AuthContext;
\ No newline at end of file
diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx
new file mode 100644
index 0000000..d1fb072
--- /dev/null
+++ b/src/hooks/useAuth.tsx
@@ -0,0 +1,8 @@
+import { useContext } from "react";
+import AuthContext from "../context/AuthProvider";
+
+const useAuth = () => {
+ return useContext(AuthContext);
+}
+
+export default useAuth;
\ No newline at end of file
diff --git a/src/index.tsx b/src/index.tsx
index 615fc79..d8f9587 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,9 +1,14 @@
import ReactDOM from "react-dom";
import App from "./App";
import "./style/App.css";
+import { AuthProvider } from './context/AuthProvider';
const Index:React.FC = () => {
- return ;
+ return (
+
+
+
+ );
};
ReactDOM.render(, document.getElementById("root"));