fixed bug sidebar
This commit is contained in:
@@ -9,15 +9,12 @@ function reducer(state, action) {
|
|||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case "COLLAPSE_MENU":
|
case "COLLAPSE_MENU":
|
||||||
return state.map((itemsArr) => itemsArr.map((item) => action.key === item.key ? {
|
return state.map((itemsArr) => itemsArr.map((item) => action.key === item.key ? {
|
||||||
...item,
|
...item, showSubItem: !item.showSubItem
|
||||||
showSubItem: !item.showSubItem
|
|
||||||
} : item));
|
} : item));
|
||||||
case "SELECTED":
|
case "SELECTED":
|
||||||
return state.map((itemsArr) => itemsArr.map((item) => {
|
return state.map((itemsArr) => itemsArr.map((item) => {
|
||||||
return item.type === "page" ? {
|
return item.type === "page" ? {
|
||||||
...item,
|
...item, selected: action.route === item.route, routing: false
|
||||||
selected: action.route === item.route,
|
|
||||||
routing: false
|
|
||||||
} : item.subItem && Array.isArray(item.subItem) ? {
|
} : item.subItem && Array.isArray(item.subItem) ? {
|
||||||
...item, subItem: item.subItem.map((subitem) => ({
|
...item, subItem: item.subItem.map((subitem) => ({
|
||||||
...subitem, selected: subitem.route === action.route, routing: false
|
...subitem, selected: subitem.route === action.route, routing: false
|
||||||
@@ -27,9 +24,7 @@ function reducer(state, action) {
|
|||||||
case "SELECTING":
|
case "SELECTING":
|
||||||
return state.map((itemsArr) => itemsArr.map((item) => {
|
return state.map((itemsArr) => itemsArr.map((item) => {
|
||||||
return item.type === "page" ? {
|
return item.type === "page" ? {
|
||||||
...item,
|
...item, selected: action.route === item.route, routing: action.route === item.route
|
||||||
selected: action.route === item.route,
|
|
||||||
routing: action.route === item.route
|
|
||||||
} : item.subItem && Array.isArray(item.subItem) ? {
|
} : item.subItem && Array.isArray(item.subItem) ? {
|
||||||
...item, subItem: item.subItem.map((subitem) => ({
|
...item, subItem: item.subItem.map((subitem) => ({
|
||||||
...subitem, selected: subitem.route === action.route, routing: subitem.route === action.route
|
...subitem, selected: subitem.route === action.route, routing: subitem.route === action.route
|
||||||
@@ -70,15 +65,16 @@ export default function SidebarList({handleDrawerToggle}) {
|
|||||||
|
|
||||||
return (<List dense={true} sx={{overflow: "scroll", p: 0}}>
|
return (<List dense={true} sx={{overflow: "scroll", p: 0}}>
|
||||||
{itemMenu.map((itemArr, index) => (<Fragment key={index}>
|
{itemMenu.map((itemArr, index) => (<Fragment key={index}>
|
||||||
{itemArr.map((item) => <Fragment key={item.key}>
|
{itemArr.map((item) => <Fragment key={item.key}>
|
||||||
{(user?.permissions?.includes(item.permission) || item.permission === "all") && <SidebarListItem
|
{(item.permissions.some((permission) => user?.permissions?.includes(permission)) || item.permissions.includes('all')) &&
|
||||||
|
<SidebarListItem
|
||||||
item={item}
|
item={item}
|
||||||
dispatch={dispatch}
|
dispatch={dispatch}
|
||||||
handleDrawerToggle={handleDrawerToggle}
|
handleDrawerToggle={handleDrawerToggle}
|
||||||
/>}
|
/>}
|
||||||
</Fragment>)}
|
</Fragment>)}
|
||||||
<Divider/>
|
<Divider/>
|
||||||
</Fragment>))}
|
</Fragment>))}
|
||||||
</List>
|
</List>
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard",
|
route: "/dashboard",
|
||||||
icon: <SpaceDashboardIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <SpaceDashboardIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "all",
|
permissions: ["all"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.reports",
|
key: "sidebar.reports",
|
||||||
@@ -33,7 +33,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/reports",
|
route: "/dashboard/reports",
|
||||||
icon: <AssessmentIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <AssessmentIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "view_reports_navgan",
|
permissions: ["view_reports_navgan"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.loan-history",
|
key: "sidebar.loan-history",
|
||||||
@@ -42,16 +42,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/loan-history",
|
route: "/dashboard/loan-history",
|
||||||
icon: <SecurityIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <SecurityIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "view_navgan_loans",
|
permissions: ["view_navgan_loans", "view_navgan_loans_province"],
|
||||||
},
|
|
||||||
{
|
|
||||||
key: "sidebar.loan-history-province",
|
|
||||||
name: "loan-history",
|
|
||||||
type: "page",
|
|
||||||
route: "/dashboard/loan-history",
|
|
||||||
icon: <SecurityIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
|
||||||
selected: false,
|
|
||||||
permission: "view_navgan_loans_province",
|
|
||||||
},
|
},
|
||||||
], [
|
], [
|
||||||
{
|
{
|
||||||
@@ -62,7 +53,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/passenger-office-chief",
|
route: "/dashboard/passenger-office-chief",
|
||||||
icon: <AirlineSeatReclineNormalIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <AirlineSeatReclineNormalIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_passenger_office_navgan",
|
permissions: ["manage_passenger_office_navgan"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.machinery-expert",
|
key: "sidebar.machinery-expert",
|
||||||
@@ -72,7 +63,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/machinery-expert",
|
route: "/dashboard/machinery-expert",
|
||||||
icon: <DirectionsCarFilledIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <DirectionsCarFilledIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_machinery_navgan",
|
permissions: ["manage_machinery_navgan"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.passenger-boss",
|
key: "sidebar.passenger-boss",
|
||||||
@@ -82,7 +73,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/passenger-boss",
|
route: "/dashboard/passenger-boss",
|
||||||
icon: <AssignmentIndIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <AssignmentIndIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_province_working_group_navgan",
|
permissions: ["manage_province_working_group_navgan"],
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -93,7 +84,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/transportation-assistant",
|
route: "/dashboard/transportation-assistant",
|
||||||
icon: <DirectionsRailwayIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <DirectionsRailwayIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_transportation_navgan",
|
permissions: ["manage_transportation_navgan"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.navgan-province-manager",
|
key: "sidebar.navgan-province-manager",
|
||||||
@@ -103,7 +94,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/navgan-province-manager",
|
route: "/dashboard/navgan-province-manager",
|
||||||
icon: <DesktopWindowsIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <DesktopWindowsIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_province_affairs_navgan",
|
permissions: ["manage_province_affairs_navgan"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.navgan-loan-management",
|
key: "sidebar.navgan-loan-management",
|
||||||
@@ -113,7 +104,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/navgan-loan-management",
|
route: "/dashboard/navgan-loan-management",
|
||||||
icon: <PaidIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <PaidIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_navgan_loan",
|
permissions: ["manage_navgan_loan"],
|
||||||
},
|
},
|
||||||
], [
|
], [
|
||||||
{
|
{
|
||||||
@@ -124,7 +115,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/province-head-expert",
|
route: "/dashboard/province-head-expert",
|
||||||
icon: <GavelIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <GavelIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_province_headquarter_refahi",
|
permissions: ["manage_province_headquarter_refahi"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.inspector-expert",
|
key: "sidebar.inspector-expert",
|
||||||
@@ -134,7 +125,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/inspector-expert",
|
route: "/dashboard/inspector-expert",
|
||||||
icon: <GradingIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <GradingIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_inspector_refahi",
|
permissions: ["manage_inspector_refahi"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.commercial-chief",
|
key: "sidebar.commercial-chief",
|
||||||
@@ -144,7 +135,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/commercial-chief",
|
route: "/dashboard/commercial-chief",
|
||||||
icon: <BusinessCenterIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <BusinessCenterIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_commercial_refahi",
|
permissions: ["manage_commercial_refahi"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.development-assistant",
|
key: "sidebar.development-assistant",
|
||||||
@@ -154,7 +145,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/development-assistant",
|
route: "/dashboard/development-assistant",
|
||||||
icon: <Diversity3Icon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <Diversity3Icon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_development_refahi",
|
permissions: ["manage_development_refahi"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.refahi-province-manager",
|
key: "sidebar.refahi-province-manager",
|
||||||
@@ -164,7 +155,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/refahi-province-manager",
|
route: "/dashboard/refahi-province-manager",
|
||||||
icon: <SupervisedUserCircleIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <SupervisedUserCircleIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_province_affairs_refahi",
|
permissions: ["manage_province_affairs_refahi"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.refahi-loan-management",
|
key: "sidebar.refahi-loan-management",
|
||||||
@@ -174,7 +165,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/refahi-loan-management",
|
route: "/dashboard/refahi-loan-management",
|
||||||
icon: <PaidIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <PaidIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_refahi_loan",
|
permissions: ["manage_refahi_loan"],
|
||||||
},
|
},
|
||||||
], [
|
], [
|
||||||
{
|
{
|
||||||
@@ -185,7 +176,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/expert-management",
|
route: "/dashboard/expert-management",
|
||||||
icon: <ManageAccountsIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <ManageAccountsIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_experts",
|
permissions: ["manage_experts"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.user-management",
|
key: "sidebar.user-management",
|
||||||
@@ -195,7 +186,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/user-management",
|
route: "/dashboard/user-management",
|
||||||
icon: <PersonIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <PersonIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_users",
|
permissions: ["manage_users"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "sidebar.role-management",
|
key: "sidebar.role-management",
|
||||||
@@ -205,7 +196,7 @@ const sidebarMenu = [
|
|||||||
route: "/dashboard/role-management",
|
route: "/dashboard/role-management",
|
||||||
icon: <AccessibilityIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
icon: <AccessibilityIcon sx={{width: 'inherit', height: 'inherit'}}/>,
|
||||||
selected: false,
|
selected: false,
|
||||||
permission: "manage_roles",
|
permissions: ["manage_roles"],
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user