useNotification init
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ const sidebarMenu = [
|
||||
route: "/dashboard",
|
||||
icon: <SpaceDashboardIcon/>,
|
||||
selected: false,
|
||||
role: "all",
|
||||
permission: "all",
|
||||
},
|
||||
{
|
||||
key: "sidebar.passenger-office-chief",
|
||||
@@ -27,7 +27,7 @@ const sidebarMenu = [
|
||||
route: "/dashboard/passenger-office-chief",
|
||||
icon: <AirlineSeatReclineNormalIcon/>,
|
||||
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: <DirectionsCarFilledIcon/>,
|
||||
selected: false,
|
||||
role: "machinery_expert",
|
||||
permission: "machinery_expert",
|
||||
},
|
||||
{
|
||||
key: "sidebar.passenger-boss",
|
||||
@@ -44,7 +44,7 @@ const sidebarMenu = [
|
||||
route: "/dashboard/passenger-boss",
|
||||
icon: <AssignmentIndIcon/>,
|
||||
selected: false,
|
||||
role: "passenger_office_chief",
|
||||
permission: "passenger_office_chief",
|
||||
},
|
||||
|
||||
{
|
||||
@@ -53,7 +53,7 @@ const sidebarMenu = [
|
||||
route: "/dashboard/transportation-assistant",
|
||||
icon: <DirectionsRailwayIcon/>,
|
||||
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: <DesktopWindowsIcon/>,
|
||||
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: <GavelIcon/>,
|
||||
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: <GradingIcon/>,
|
||||
selected: false,
|
||||
role: "inspector_expert",
|
||||
permission: "inspector_expert",
|
||||
},
|
||||
{
|
||||
key: "sidebar.commercial-chief",
|
||||
@@ -86,7 +86,7 @@ const sidebarMenu = [
|
||||
route: "/dashboard/commercial-chief",
|
||||
icon: <BusinessCenterIcon/>,
|
||||
selected: false,
|
||||
role: "commercial_chief",
|
||||
permission: "commercial_chief",
|
||||
},
|
||||
{
|
||||
key: "sidebar.development-assistant",
|
||||
@@ -94,7 +94,7 @@ const sidebarMenu = [
|
||||
route: "/dashboard/development-assistant",
|
||||
icon: <Diversity3Icon/>,
|
||||
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: <SupervisedUserCircleIcon/>,
|
||||
selected: false,
|
||||
role: "province_manager",
|
||||
permission: "province_manager",
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
<Fragment key={item.key}>
|
||||
<ListItem disablePadding secondaryAction={
|
||||
<IconButton>
|
||||
<Badge
|
||||
badgeContent="56"
|
||||
badgeContent={item.permission}
|
||||
color="error"
|
||||
variant="standard"
|
||||
anchorOrigin={{
|
||||
|
||||
26
src/lib/app/hooks/useNotification.jsx
Normal file
26
src/lib/app/hooks/useNotification.jsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import useSWR from 'swr'
|
||||
import {GET_SIDEBAR_NOTIFICATION} from "@/core/data/apiRoutes";
|
||||
import useRequest from "@/lib/app/hooks/useRequest";
|
||||
|
||||
const useNotification = () => {
|
||||
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
|
||||
Reference in New Issue
Block a user