From 67478837d8dc3315c168b7665513fe82aea40f47 Mon Sep 17 00:00:00 2001 From: princekumarofficial Date: Thu, 20 Jun 2024 12:02:44 +0530 Subject: [PATCH 1/2] 1. Logout function Added 2. Login page buttons structure --- src/components/NavButtonGroup.tsx | 89 +++++++++++++++---------- src/components/Sidebar.tsx | 32 ++++----- src/components/loginForms/loginForm.tsx | 6 +- 3 files changed, 71 insertions(+), 56 deletions(-) diff --git a/src/components/NavButtonGroup.tsx b/src/components/NavButtonGroup.tsx index 7566d180..ff73e092 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,65 @@ const NavLink = ({ href }: LinkProps) => { ); }; -const NavButtonGroup = () => { +const LogoutButton = () => { + const context = useContext(ToggleContext); + + const logOut = () => { + Cookies.remove("user"); + 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 - - +
+ + +
From 4e81641dcab5cb574f26d9d69e02f9ef80e6e656 Mon Sep 17 00:00:00 2001 From: Prince Kumar Date: Thu, 20 Jun 2024 14:56:45 +0530 Subject: [PATCH 2/2] Update src/components/NavButtonGroup.tsx Co-authored-by: AryanGKulkarni <95529889+AryanGKulkarni@users.noreply.github.com> --- src/components/NavButtonGroup.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/NavButtonGroup.tsx b/src/components/NavButtonGroup.tsx index ff73e092..d585e3eb 100644 --- a/src/components/NavButtonGroup.tsx +++ b/src/components/NavButtonGroup.tsx @@ -94,6 +94,7 @@ const LogoutButton = () => { const logOut = () => { Cookies.remove("user"); + Cookies.remove("accessToken"); window.location.reload(); };