From 674613e765257274cbdfbc5fcc41c6e9b99fbc73 Mon Sep 17 00:00:00 2001 From: Amin Ghasempoor Date: Mon, 14 Aug 2023 13:44:43 +0330 Subject: [PATCH] useNotification init --- src/core/data/apiRoutes.js | 5 ++++ src/core/data/sidebarMenu.jsx | 22 ++++++++-------- .../dashboardLayouts/sidebar/SidebarList.jsx | 2 +- .../sidebar/SidebarListItem.jsx | 5 +++- src/lib/app/hooks/useNotification.jsx | 26 +++++++++++++++++++ 5 files changed, 47 insertions(+), 13 deletions(-) create mode 100644 src/lib/app/hooks/useNotification.jsx diff --git a/src/core/data/apiRoutes.js b/src/core/data/apiRoutes.js index 684d30c..e430c68 100644 --- a/src/core/data/apiRoutes.js +++ b/src/core/data/apiRoutes.js @@ -128,3 +128,8 @@ export const REVISE_PROVINCE_HEAD_EXPERT = BASE_URL + "/dashboard/province_head_expert/revise"; //province head expert +//sidebar notification +export const GET_SIDEBAR_NOTIFICATION = + BASE_URL + "/dashboard/notification" +//sidebar notification + diff --git a/src/core/data/sidebarMenu.jsx b/src/core/data/sidebarMenu.jsx index 7b1b20f..2c1965a 100644 --- a/src/core/data/sidebarMenu.jsx +++ b/src/core/data/sidebarMenu.jsx @@ -18,7 +18,7 @@ const sidebarMenu = [ route: "/dashboard", icon: , selected: false, - role: "all", + permission: "all", }, { key: "sidebar.passenger-office-chief", @@ -27,7 +27,7 @@ const sidebarMenu = [ route: "/dashboard/passenger-office-chief", icon: , selected: false, - role: "passenger_office_chief", + permission: "passenger_office_chief", }, { key: "sidebar.machinery-expert", @@ -35,7 +35,7 @@ const sidebarMenu = [ route: "/dashboard/machinery-expert", icon: , selected: false, - role: "machinery_expert", + permission: "machinery_expert", }, { key: "sidebar.passenger-boss", @@ -44,7 +44,7 @@ const sidebarMenu = [ route: "/dashboard/passenger-boss", icon: , selected: false, - role: "passenger_office_chief", + permission: "passenger_office_chief", }, { @@ -53,7 +53,7 @@ const sidebarMenu = [ route: "/dashboard/transportation-assistant", icon: , selected: false, - role: "transportation_assistant", + permission: "transportation_assistant", }, { key: "sidebar.navgan-province-manager", @@ -62,7 +62,7 @@ const sidebarMenu = [ route: "/dashboard/navgan-province-manager", icon: , selected: false, - role: "province_manager", + permission: "province_manager", }, { key: "sidebar.province-head-expert", @@ -70,7 +70,7 @@ const sidebarMenu = [ route: "/dashboard/province-head-expert", icon: , selected: false, - role: "province_head_expert", + permission: "province_head_expert", }, { key: "sidebar.inspector-expert", @@ -78,7 +78,7 @@ const sidebarMenu = [ route: "/dashboard/inspector-expert", icon: , selected: false, - role: "inspector_expert", + permission: "inspector_expert", }, { key: "sidebar.commercial-chief", @@ -86,7 +86,7 @@ const sidebarMenu = [ route: "/dashboard/commercial-chief", icon: , selected: false, - role: "commercial_chief", + permission: "commercial_chief", }, { key: "sidebar.development-assistant", @@ -94,7 +94,7 @@ const sidebarMenu = [ route: "/dashboard/development-assistant", icon: , selected: false, - role: "development_assistant", + permission: "development_assistant", }, { key: "sidebar.refahi-province-manager", @@ -103,7 +103,7 @@ const sidebarMenu = [ route: "/dashboard/refahi-province-manager", icon: , selected: false, - role: "province_manager", + permission: "province_manager", }, ], ]; diff --git a/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx b/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx index dffd844..38ff5f2 100644 --- a/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx +++ b/src/layouts/dashboardLayouts/sidebar/SidebarList.jsx @@ -38,7 +38,7 @@ export default function SidebarList({handleDrawerToggle}) { }, [router.pathname]); const filteredItemMenu = itemMenu[0].filter( - (item) => user.role.includes(item.role) || item.role === "all" + (item) => user.role.includes(item.permission) || item.permission === "all" ); return ( diff --git a/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx b/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx index 616ecb5..c0c3037 100644 --- a/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx +++ b/src/layouts/dashboardLayouts/sidebar/SidebarListItem.jsx @@ -5,16 +5,19 @@ import {Badge, IconButton, ListItem, ListItemButton, ListItemIcon, ListItemText, import {useTranslations} from "next-intl"; import {Fragment} from "react"; import SidebarListSubItem from "./SidebarListSubItem"; +import useNotification from "@/lib/app/hooks/useNotification"; const SidebarListItem = ({item, dispatch, handleDrawerToggle}) => { const t = useTranslations(); + const {notification_count} = useNotification() + console.log(notification_count) return ( { + const requestServer = useRequest({auth: true}) + + //swr config + const fetcher = (...args) => { + return requestServer(args, 'get', { + pending: false, + success: {notification: {show: false}} + }).then((response) => { + return response.data.data; + }).catch(() => { + }) + }; + + const {data} = useSWR(GET_SIDEBAR_NOTIFICATION, fetcher) + const notification_count = data + //swr config + + // render data + return {notification_count} +} +export default useNotification \ No newline at end of file