diff --git a/src/components/NavButtonGroup.tsx b/src/components/NavButtonGroup.tsx index 7566d180..d585e3eb 100644 --- a/src/components/NavButtonGroup.tsx +++ b/src/components/NavButtonGroup.tsx @@ -8,6 +8,7 @@ import Link, { LinkProps } from "next/link"; import { usePathname } from "next/navigation"; import { ToggleContext } from "@/contextProviders/ToggleProvider"; import { motion } from "framer-motion"; +import Cookies from "js-cookie"; const NavLink = ({ href }: LinkProps) => { const path = usePathname(); @@ -88,49 +89,66 @@ const NavLink = ({ href }: LinkProps) => { ); }; -const NavButtonGroup = () => { +const LogoutButton = () => { + const context = useContext(ToggleContext); + + const logOut = () => { + Cookies.remove("user"); + Cookies.remove("accessToken"); + window.location.reload(); + }; + + return ( +
+
+
+ + + + + +
+ + Logout + +
+
+ ); +}; + +const NavButtonGroup = (params: { loggedIn: boolean }) => { const context = useContext(ToggleContext); return (
- -
-
-
- - - - - -
- - Logout - -
-
+ {!params.loggedIn && } + {params.loggedIn && }
); }; -export default NavButtonGroup; \ No newline at end of file +export default NavButtonGroup; diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index 5a777893..6eaf94fb 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -10,7 +10,6 @@ import AdminDashboard from "./SideBar/Roles/admin"; import StudentDashboard from "./SideBar/Roles/student"; import RecruiterDashboard from "./SideBar/Roles/recruiter"; - interface Framework { value: string; label: string; @@ -31,21 +30,24 @@ interface Props { } const Sidebar = () => { - const isSmallScreen = useMediaQuery({ query: "(max-width: 768px)" }); const context = useContext(ToggleContext); const [isAdmin, setIsAdmin] = useState(false); const [isRecruiter, setIsRecruiter] = useState(false); const [isStudent, setIsStudent] = useState(false); + const [isLoggedIn, setLoggedIn] = useState(false); -useEffect(()=>{ + useEffect(() => { const userString = Cookies.get("user"); const user = userString ? JSON.parse(userString) : null; - setIsAdmin(user?.role === "ADMIN") - setIsRecruiter(user?.role === "RECRUITER") - setIsStudent(user?.role === "STUDENT") - }, []) + if (user) { + setLoggedIn(true); + } + setIsAdmin(user?.role === "ADMIN"); + setIsRecruiter(user?.role === "RECRUITER"); + setIsStudent(user?.role === "STUDENT"); + }, []); return ( { {/* */}
- + - {isAdmin && ( - - )} - {isStudent && ( - - )} - {isRecruiter&& ( - - )} + {isAdmin && } + {isStudent && } + {isRecruiter && }
); }; -export default Sidebar; \ No newline at end of file +export default Sidebar; diff --git a/src/components/loginForms/loginForm.tsx b/src/components/loginForms/loginForm.tsx index 49f4fe31..aa61b814 100644 --- a/src/components/loginForms/loginForm.tsx +++ b/src/components/loginForms/loginForm.tsx @@ -97,8 +97,10 @@ const LoginForm = () => { > Request Access - - +
+ + +