From 8104f94b9e6d5956a5b9f5beb08503517fdc4c5f Mon Sep 17 00:00:00 2001 From: Yasiu1376 Date: Wed, 19 Jul 2023 14:39:34 +0330 Subject: [PATCH] sidebar_permission --- public/locales/fa/app.json | 8 +++-- src/core/components/Datatable.jsx | 1 - src/core/data/sidebarMenu.jsx | 13 +++++--- .../dashboardLayouts/sidebar/SidebarList.jsx | 31 ++++++++++--------- .../sidebar/SidebarListItem.jsx | 12 ++++++- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/public/locales/fa/app.json b/public/locales/fa/app.json index 7437875..2c923be 100644 --- a/public/locales/fa/app.json +++ b/public/locales/fa/app.json @@ -19,14 +19,18 @@ }, "sidebar": { "dashboard": "داشبورد", - "passenger-office": "اداره مسافر (توزیع درخواست)", + "passenger-office": "اداره مسافر", "machinary-office": "ماشین آلات", - "passenger-boss": "رئیس مسافر (کارگروه استانی)", + "passenger-boss": "رئیس مسافر ", "transportation-assistance": "معاونت حمل و نقل", "manager": "مدیر کل", "change-password": "تغییر رمز عبور", "edit-profile": "ویرایش پروفایل" }, + "secondary": { + "passenger-office": "توزیع درخواست", + "passenger-boss": "کارگروه استانی" + }, "Authorization": { "typography_your_login_is_valid_and_you_do_not_need_to_login_again": "شما دسترسی لازم به این صفحه را دارید نیاز به ورود مجدد نیست.", "typography_your_access_to_this_page_has_expired_Please_login_again": "دسترسی شما منقضی شده است لطفا دوباره ورود نمایید.", diff --git a/src/core/components/Datatable.jsx b/src/core/components/Datatable.jsx index 04be089..2d34ece 100644 --- a/src/core/components/Datatable.jsx +++ b/src/core/components/Datatable.jsx @@ -44,7 +44,6 @@ const DataTable = (props) => { const [sorting, setSorting] = useState([]); const [pagination, setPagination] = useState({ pageIndex: 0, pageSize: 10 }); const [rowCount, setRowCount] = useState(0); - console.log(moment()); const [updateTime, setupdateTime] = useState( moment().format("HH:mm | jYYYY/jM/jD") ); diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index cf2aacb..26fa92b 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -13,14 +13,16 @@ const sidebarMenu = [ route: "/dashboard", icon: , selected: false, + role: "all", }, { key: "sidebar.passenger-office", + secondary: "secondary.passenger-office", type: "page", route: "/dashboard/passenger-office", icon: , selected: false, - role: "passenger-office", + role: "passenger_office_chief", }, { key: "sidebar.machinary-office", @@ -28,15 +30,16 @@ const sidebarMenu = [ route: "/dashboard/machinary-office", icon: , selected: false, - role: "machinary-office", + role: "machinery_expert", }, { key: "sidebar.passenger-boss", + secondary: "secondary.passenger-boss", type: "page", route: "/dashboard/passenger-boss", icon: , selected: false, - role: "passenger-boss", + role: "passenger_office_chief", }, { key: "sidebar.transportation-assistance", @@ -44,7 +47,7 @@ const sidebarMenu = [ route: "/dashboard/transportation-assistance", icon: , selected: false, - role: "transportation-assistance", + role: "transportation_assistant", }, { key: "sidebar.manager", @@ -52,7 +55,7 @@ const sidebarMenu = [ route: "/dashboard/manager", icon: , selected: false, - role: "manager", + role: "province_manager", }, ], ]; diff --git a/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx b/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx index 79dd93e..c47cf2b 100644 --- a/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx +++ b/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx @@ -1,8 +1,9 @@ import { Divider, List } from "@mui/material"; -import { Fragment, useEffect, useReducer } from "react"; +import { useEffect, useReducer } from "react"; import SidebarListItem from "./SidebarListItem"; import sidebarMenu from "@/core/data/sidebarMenu"; import { useRouter } from "next/router"; +import useUser from "@/lib/app/hooks/useUser"; function reducer(state, action) { switch (action.type) { @@ -29,28 +30,28 @@ function reducer(state, action) { export default function SidebarList({ handleDrawerToggle }) { const [itemMenu, dispatch] = useReducer(reducer, sidebarMenu); - - // activate current page in menu + const { user } = useUser(); const router = useRouter(); + useEffect(() => { dispatch({ type: "SELECTED", route: router.pathname }); }, [router.pathname]); + const filteredItemMenu = itemMenu[0].filter( + (item) => user.role.includes(item.role) || item.role === "all" + ); + return ( - {itemMenu.map((itemArr, index) => ( - - {itemArr.map((item) => ( - - ))} - - + {filteredItemMenu.map((item, index) => ( + ))} + {filteredItemMenu.length > 0 && } ); } diff --git a/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx b/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx index ba270a5..8d56ad0 100644 --- a/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx +++ b/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx @@ -6,6 +6,7 @@ import { ListItemButton, ListItemIcon, ListItemText, + Typography, } from "@mui/material"; import { useTranslations } from "next-intl"; import { Fragment } from "react"; @@ -45,7 +46,16 @@ const SidebarListItem = ({ item, dispatch, handleDrawerToggle }) => { > {item.icon} - + + {t(item.secondary)} + + ) : null + } + /> {item.type == "menu" && (item.showSubItem ? : )}