diff --git a/src/ProtectedRoute.tsx b/src/ProtectedRoute.tsx index 55e2d26..5d8d12f 100644 --- a/src/ProtectedRoute.tsx +++ b/src/ProtectedRoute.tsx @@ -3,12 +3,21 @@ import useAuth from "./hooks/useAuth"; import Navbar from "./components/navbar/Navbar"; import Sidebar from "./components/sidebar/Sidebar"; import { Box } from "@mui/material"; +import { store } from "./redux/store"; +import { fetchFavorites } from "./redux/slices/favoritesSlice"; +import { fetchMeetings } from "./redux/slices/meetingsAndUserStatusSlice"; +import { fetchUsers } from "./redux/slices/usersSlice"; const ProtectedRoute = () => { const auth = useAuth(); const location = useLocation(); /* Temporary data */ + if (auth?.isLoggedIn != undefined && auth?.isLoggedIn == true) { + store.dispatch(fetchMeetings(auth?.uuid)); + store.dispatch(fetchUsers(auth?.uuid)); + store.dispatch(fetchFavorites(auth?.uuid)); + } return auth?.isLoggedIn ? ( <> diff --git a/src/components/home/MeetingsPanel.tsx b/src/components/home/MeetingsPanel.tsx index 0daadb7..bc3ad0e 100644 --- a/src/components/home/MeetingsPanel.tsx +++ b/src/components/home/MeetingsPanel.tsx @@ -29,7 +29,11 @@ const MeetingsPanel: React.FC = () => { // ); // participants.push(userLite); // }); + const [currentDate, setCurrentDate] = useState(new Date()); + useEffect(() => { + setInterval(() => setCurrentDate(new Date()), 1000); + }, []); return (
@@ -59,10 +63,6 @@ const MeetingsPanel: React.FC = () => { const startDatemil = startDate.getTime(); const endDatemil = startDatemil + meeting.duration * 60000; const endDate = new Date(endDatemil); - const [currentDate, setCurrentDate] = useState(new Date()); - useEffect(() => { - setInterval(() => setCurrentDate(new Date()), 1000); - }, []); const currentDatemil = currentDate.getTime(); diff --git a/src/components/login/Login.tsx b/src/components/login/Login.tsx index e286d13..36bfd79 100644 --- a/src/components/login/Login.tsx +++ b/src/components/login/Login.tsx @@ -8,10 +8,6 @@ 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"; -import { store } from "../../redux/store"; -import { fetchFavorites } from "../../redux/slices/favoritesSlice"; -import { fetchMeetings } from "../../redux/slices/meetingsAndUserStatusSlice"; -import { fetchUsers } from "../../redux/slices/usersSlice"; import axios from "../../api/axios"; interface LocationState { @@ -27,7 +23,6 @@ const Login: React.FC = () => { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); - const [logedInUser, setLogedInUser] = useState(""); // const [errMsg, setErrMsg] = useState(''); // const userRef = useRef(); @@ -41,16 +36,12 @@ const Login: React.FC = () => { // setErrMsg(''); // }, [user, pwd]) - store.dispatch(fetchMeetings("1")); // temp fix - store.dispatch(fetchUsers("1")); // temp fix - store.dispatch(fetchFavorites("1")); // temp fix - const handleLogin = async(e: React.SyntheticEvent) => { e.preventDefault(); try { if (email === "" && password === "") { - setAuth["email"] = email; + setAuth["uuid"] = ""; setAuth["isLoggedIn"] = true; navigate(from, { replace: true }); } @@ -69,9 +60,8 @@ const Login: React.FC = () => { console.log(response?.data); if (logedInUserId != undefined) { - setAuth["email"] = email; + setAuth["uuid"] = logedInUserId; setAuth["isLoggedIn"] = true; - // setLogedInUser(logedInUserId); navigate(from, { replace: true }); } } catch (error) { diff --git a/src/context/AuthProvider.tsx b/src/context/AuthProvider.tsx index 6accd02..793946c 100644 --- a/src/context/AuthProvider.tsx +++ b/src/context/AuthProvider.tsx @@ -1,17 +1,17 @@ import { createContext, useState } from "react"; interface loginInfo { - email: string; + uuid: string; isLoggedIn: boolean; } const AuthContext = createContext({ - email: "", + uuid: "", isLoggedIn: false, }); export const AuthProvider = ({ children }: { children: React.ReactNode }) => { - const [auth] = useState({ email: "", isLoggedIn: false }); + const [auth] = useState({ uuid: "", isLoggedIn: false }); return {children}; }; diff --git a/src/hooks/useAuth.tsx b/src/hooks/useAuth.tsx index af7ffe0..17bf4f8 100644 --- a/src/hooks/useAuth.tsx +++ b/src/hooks/useAuth.tsx @@ -2,7 +2,7 @@ import { useContext } from "react"; import AuthContext from "../context/AuthProvider"; interface loginInfo { - email: string; + uuid: string; isLoggedIn: boolean; }