|
3 | 3 | import { NavContext } from "@/hooks/contexts/useNavCtx"; |
4 | 4 | import { useContext, useEffect, useState } from "react"; |
5 | 5 | import Sidebar from "../../components/dashboard-componenets/sidebar/Sidebar"; |
6 | | -import { admin , landfillManager, stsManager, unassigned } from "@/data/roles"; |
| 6 | +import { admin, landfillManager, stsManager, unassigned } from "@/data/roles"; |
7 | 7 | import MainSection from "../../components/dashboard-componenets/mainContent/mainSection"; |
8 | 8 | import { useRouter } from "next/navigation"; |
9 | 9 | import { getCookie } from "@/lib/cookieFunctions"; |
10 | | -import { curActive, role } from "@/data/cookieNames"; |
| 10 | +import { curActive, role, stsId, username, landfillId } from "@/data/cookieNames"; |
11 | 11 | import { set } from "react-hook-form"; |
| 12 | +import AppLogo from "../auth/login/AppLogo"; |
12 | 13 |
|
13 | 14 | export default function Dashboard() { |
14 | | - |
15 | 15 | const [curRole, setCurrentRole] = useState(""); |
16 | 16 | const [currentActive, setCurrentActive] = useState(""); |
17 | 17 | const router = useRouter(); |
18 | | - |
| 18 | + |
19 | 19 | useEffect(() => { |
20 | 20 | setCurrentRole(getCookie(role)); |
21 | 21 | setCurrentActive(getCookie(curActive)); |
22 | 22 | }, []); |
23 | 23 |
|
24 | 24 | //console.log('Role: ' + curRole + ' Current Active: ' + currentActive); |
25 | | - |
| 25 | + |
26 | 26 | return ( |
27 | | - <div className="grid min-h-screen w-full md:grid-cols-[220px_1fr] lg:grid-cols-[280px_1fr]"> |
28 | | - <NavContext.Provider value={{currentActive, setCurrentActive}}> |
29 | | - <Sidebar role={curRole}/> |
30 | | - <MainSection role={curRole}/> |
31 | | - </ NavContext.Provider> |
| 27 | + <div className="grid min-h-screen w-full md:grid-cols-[220px_1fr] lg:grid-cols-[280px_1fr]"> |
| 28 | + <NavContext.Provider value={{ currentActive, setCurrentActive }}> |
| 29 | + {(curRole === stsManager && getCookie(stsId) === "") || (curRole === landfillManager && getCookie(landfillId) === "") ? ( |
| 30 | + <> |
| 31 | + <div className="w-screen h-screen flex flex-col justify-center items-center text gap-4"> |
| 32 | + <div className="h-24 w-24 only:md:h-32 md:w-32 mb-4"> |
| 33 | + <AppLogo /> |
| 34 | + </div> |
| 35 | + <h1 className="text-xl sm:text-xl lg:text-3xl font-semibold"> |
| 36 | + Welcome {getCookie(username)} |
| 37 | + </h1> |
| 38 | + <h1 className="text-2xl sm:text-3xl lg:text-5xl font-bold"> |
| 39 | + You are not assigned to any {curRole === stsManager ? "STS" : "Landfill"} |
| 40 | + </h1> |
| 41 | + <h1 className="text-md sm:text-lg lg:text-2xl"> |
| 42 | + Contact admin for being assigned to a {curRole === stsManager ? "STS" : "Landfill"} |
| 43 | + </h1> |
| 44 | + <button |
| 45 | + onClick={() => router.push("/auth/login")} |
| 46 | + className="bg-[#1A4D2E] text-white font-semibold px-4 py-2 rounded-md" |
| 47 | + > |
| 48 | + Logout |
| 49 | + </button> |
| 50 | + </div> |
| 51 | + </> |
| 52 | + ) : ( |
| 53 | + <> |
| 54 | + <Sidebar role={curRole} /> |
| 55 | + <MainSection role={curRole} /> |
| 56 | + </> |
| 57 | + )} |
| 58 | + |
| 59 | + </NavContext.Provider> |
32 | 60 | </div> |
33 | 61 | ); |
34 | 62 | } |
0 commit comments