diff --git a/src/components/AppBar/AppBar.tsx b/src/components/AppBar/AppBar.tsx index a38d2bd..57c190a 100644 --- a/src/components/AppBar/AppBar.tsx +++ b/src/components/AppBar/AppBar.tsx @@ -5,18 +5,23 @@ import Profile from "./Profile"; import Box from "@mui/material/Box"; import NavigationToggle from "./NavigationToggle"; import { I18nProvider } from "@/i18n"; +import { authOptions } from "@/config/authConfig"; +import { getServerSession } from "next-auth"; export interface AppBarProps { avatarImageSrc?: string; profileName: string; } -const AppBar: React.FC = ({ avatarImageSrc, profileName }) => { +const AppBar: React.FC = async ({ avatarImageSrc, profileName }) => { + const session = await getServerSession(authOptions) as any; + const abilities: string[] = session.abilities + console.log(abilities) return ( - + diff --git a/src/components/AppBar/NavigationToggle.tsx b/src/components/AppBar/NavigationToggle.tsx index 9f61753..f704267 100644 --- a/src/components/AppBar/NavigationToggle.tsx +++ b/src/components/AppBar/NavigationToggle.tsx @@ -4,8 +4,18 @@ import MenuIcon from "@mui/icons-material/Menu"; import NavigationContent from "../NavigationContent"; import React from "react"; import Drawer from "@mui/material/Drawer"; +import { Session } from "inspector"; +import { authOptions } from "@/config/authConfig"; +import { getServerSession } from "next-auth"; +export interface SessionWithAbilities extends Session { + abilities?: string[] +} -const NavigationToggle: React.FC = () => { +interface Props { + abilities?: string[] +} + +const NavigationToggle: React.FC = ({ abilities }) => { const [isOpened, setIsOpened] = React.useState(false); const openNavigation = () => { @@ -18,7 +28,7 @@ const NavigationToggle: React.FC = () => { return ( <> - + { keepMounted: true, }} > - + , label: "User Workspace", path: "/home" }, - { - icon: , - label: "Dashboard", - path: "", - children: [ - { - icon: , - label: "Financial Summary", - path: "/dashboard/ProjectFinancialSummary", - }, - { - icon: , - label: "Company / Team Cash Flow", - path: "/dashboard/CompanyTeamCashFlow", - }, - { - icon: , - label: "Project Cash Flow", - path: "/dashboard/ProjectCashFlow", - }, - { - icon: , - label: "Project Status by Client", - path: "/dashboard/ProjectStatusByClient", - }, - { - icon: , - label: "Project Status by Team", - path: "/dashboard/ProjectStatusByTeam", - }, - { - icon: , - label: "Staff Utilization", - path: "/dashboard/StaffUtilization", - }, - { - icon: , - label: "Project Resource Summary", - path: "/dashboard/ProjectResourceSummary", - } - ], - }, - { - icon: , - label: "Staff Reimbursement", - path: "/staffReimbursement", - children: [ - { - icon: , - label: "Claim Approval", - path: "/staffReimbursement/ClaimApproval", - }, - { - icon: , - label: "Claim Summary", - path: "/staffReimbursement/ClaimSummary", - }, - ], - }, - { icon: , label: "Project Management", path: "/projects" }, - { icon: , label: "Task Template", path: "/tasks" }, - { icon: , label: "Invoice", path: "/invoice" }, - { icon: , label: "Analysis Report", path: "", - children: [ - {icon: , label:"Late Start Report", path: "/analytics/LateStartReport"}, - {icon: , label:"Delay Report", path: "/analytics/DelayReport"}, - {icon: , label:"Resource Overconsumption Report", path: "/analytics/ResourceOverconsumptionReport"}, - {icon: , label:"Cost and Expense Report", path: "/analytics/CostandExpenseReport"}, - {icon: , label:"Completion Report", path: "/analytics/ProjectCompletionReport"}, - {icon: , label:"Completion Report with Outstanding Un-billed Hours Report", path: "/analytics/ProjectCompletionReportWO"}, - {icon: , label:"Project Claims Report", path: "/analytics/ProjectClaimsReport"}, - {icon: , label:"Project P&L Report", path: "/analytics/ProjectPLReport"}, - {icon: , label:"Financial Status Report", path: "/analytics/FinancialStatusReport"}, - {icon: , label:"Project Cash Flow Report", path: "/analytics/ProjectCashFlowReport"}, - ], -}, - { - icon: , label: "Setting", path: "", - children: [ - { icon: , label: "Client", path: "/settings/customer" }, - { icon: , label: "Subsidiary", path: "/settings/subsidiary" }, - { icon: , label: "Staff", path: "/settings/staff" }, - { icon: , label: "Company", path: "/settings/company" }, - { icon: , label: "Skill", path: "/settings/skill" }, - { icon: , label: "Department", path: "/settings/department" }, - { icon: , label: "Position", path: "/settings/position" }, - { icon: , label: "Salary", path: "/settings/salary" }, - { icon: , label: "Team", path: "/settings/team" }, - { icon: , label: "User", path: "/settings/user" }, - { icon: , label: "Holiday", path: "/settings/holiday" }, +interface Props { + abilities?: string[] +} + +const NavigationContent: React.FC = ({ abilities }) => { + const navigationItems: NavigationItem[] = [ + { icon: , label: "User Workspace", path: "/home" }, + { + icon: , + label: "Dashboard", + path: "", + children: [ + { + icon: , + label: "Financial Summary", + path: "/dashboard/ProjectFinancialSummary", + }, + { + icon: , + label: "Company / Team Cash Flow", + path: "/dashboard/CompanyTeamCashFlow", + }, + { + icon: , + label: "Project Cash Flow", + path: "/dashboard/ProjectCashFlow", + }, + { + icon: , + label: "Project Status by Client", + path: "/dashboard/ProjectStatusByClient", + }, + { + icon: , + label: "Project Status by Team", + path: "/dashboard/ProjectStatusByTeam", + }, + { + icon: , + label: "Staff Utilization", + path: "/dashboard/StaffUtilization", + }, + { + icon: , + label: "Project Resource Summary", + path: "/dashboard/ProjectResourceSummary", + } + ], + }, + { + icon: , + label: "Staff Reimbursement", + path: "/staffReimbursement", + children: [ + { + icon: , + label: "Claim Approval", + path: "/staffReimbursement/ClaimApproval", + }, + { + icon: , + label: "Claim Summary", + path: "/staffReimbursement/ClaimSummary", + }, + ], + }, + { icon: , label: "Project Management", path: "/projects" }, + { icon: , label: "Task Template", path: "/tasks" }, + { icon: , label: "Invoice", path: "/invoice" }, + { icon: , label: "Analysis Report", path: "", isHidden: ![GENERATE_REPORTS].some((ability) => abilities!!.includes(ability)), + children: [ + {icon: , label:"Late Start Report", path: "/analytics/LateStartReport"}, + {icon: , label:"Delay Report", path: "/analytics/DelayReport"}, + {icon: , label:"Resource Overconsumption Report", path: "/analytics/ResourceOverconsumptionReport"}, + {icon: , label:"Cost and Expense Report", path: "/analytics/CostandExpenseReport"}, + {icon: , label:"Completion Report", path: "/analytics/ProjectCompletionReport"}, + {icon: , label:"Completion Report with Outstanding Un-billed Hours Report", path: "/analytics/ProjectCompletionReportWO"}, + {icon: , label:"Project Claims Report", path: "/analytics/ProjectClaimsReport"}, + {icon: , label:"Project P&L Report", path: "/analytics/ProjectPLReport"}, + {icon: , label:"Financial Status Report", path: "/analytics/FinancialStatusReport"}, + {icon: , label:"EX02 - Project Cash Flow Report", path: "/analytics/EX02ProjectCashFlowReport"}, ], }, -]; + { + icon: , label: "Setting", path: "", isHidden: ![VIEW_MASTERDATA, MAINTAIN_MASTERDATA].some((ability) => abilities!!.includes(ability)), + children: [ + { icon: , label: "Client", path: "/settings/customer" }, + { icon: , label: "Subsidiary", path: "/settings/subsidiary" }, + { icon: , label: "Staff", path: "/settings/staff" }, + { icon: , label: "Company", path: "/settings/company" }, + { icon: , label: "Skill", path: "/settings/skill" }, + { icon: , label: "Department", path: "/settings/department" }, + { icon: , label: "Position", path: "/settings/position" }, + { icon: , label: "Salary", path: "/settings/salary" }, + { icon: , label: "Team", path: "/settings/team" }, + { icon: , label: "User", path: "/settings/user" }, + { icon: , label: "Holiday", path: "/settings/holiday" }, + ], + }, + ]; -const NavigationContent: React.FC = () => { const { t } = useTranslation("common"); const pathname = usePathname(); - const [openItems, setOpenItems] = React.useState([]); const toggleItem = (label: string) => { setOpenItems((prevOpenItems) => @@ -188,7 +195,7 @@ const NavigationContent: React.FC = () => { - {navigationItems.map((item) => renderNavigationItem(item))} + {navigationItems.filter(item => item.isHidden !== true).map((item) => renderNavigationItem(item))} {/* {navigationItems.map(({ icon, label, path }, index) => { return ( { let isAuth = Boolean(token); + if (!Boolean(token)) { + return Boolean(token) + } if (req.nextUrl.pathname.startsWith('/settings')) { isAuth = [VIEW_MASTERDATA, MAINTAIN_MASTERDATA].some((ability) => abilities.includes(ability)); }