update
This commit is contained in:
10
src/app/(withAuth)/dashboard/inquiry_privacy/fencing/page.js
Normal file
10
src/app/(withAuth)/dashboard/inquiry_privacy/fencing/page.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import InquiryPrivacyFencingPage from "@/components/dashboard/inquiryPrivacyFencing";
|
||||
|
||||
const Page = () => {
|
||||
|
||||
return (
|
||||
<InquiryPrivacyFencingPage />
|
||||
);
|
||||
};
|
||||
|
||||
export default Page;
|
||||
@@ -1,9 +1,8 @@
|
||||
import { Box, Stack } from "@mui/material";
|
||||
import HeaderWithLogo from "@/components/layouts/dashboard/headerWithLogo";
|
||||
import HeaderWithSidebar from "@/components/layouts/dashboard/headerWithSidebar";
|
||||
import "react-toastify/dist/ReactToastify.css";
|
||||
import { Box, Stack } from "@mui/material";
|
||||
|
||||
const Template = ({ children }) => {
|
||||
const Layout = ({ children }) => {
|
||||
return (
|
||||
<Stack>
|
||||
<HeaderWithLogo />
|
||||
@@ -12,6 +11,5 @@ const Template = ({ children }) => {
|
||||
</Box>
|
||||
</Stack>
|
||||
);
|
||||
};
|
||||
|
||||
export default Template;
|
||||
}
|
||||
export default Layout;
|
||||
@@ -1,5 +1,3 @@
|
||||
"use client";
|
||||
|
||||
const Page = () => {
|
||||
|
||||
return (
|
||||
|
||||
4
src/components/dashboard/inquiryPrivacyFencing/index.jsx
Normal file
4
src/components/dashboard/inquiryPrivacyFencing/index.jsx
Normal file
@@ -0,0 +1,4 @@
|
||||
const InquiryPrivacyFencingPage = () => {
|
||||
return <></>
|
||||
}
|
||||
export default InquiryPrivacyFencingPage
|
||||
@@ -7,11 +7,29 @@ import { useEffect, useReducer, useState } from "react";
|
||||
import { filterMenuItems } from "../utils/filterMenuItems";
|
||||
import { pageMenu } from "../utils/pageMenu";
|
||||
|
||||
function selectPage(item, route) {
|
||||
if (item.type === "page") {
|
||||
return {
|
||||
...item,
|
||||
selected: item.route === route,
|
||||
showSubitems: item.route === route,
|
||||
};
|
||||
} else if (item.Subitems && Array.isArray(item.Subitems)) {
|
||||
const updatedSubitems = item.Subitems.map(subitem => selectPage(subitem, route));
|
||||
return {
|
||||
...item,
|
||||
Subitems: updatedSubitems,
|
||||
showSubitems: updatedSubitems.some(subitem => subitem.showSubitems || subitem.route === route),
|
||||
};
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case "UPDATE_MENU":
|
||||
const _permissions = action.permissions || []
|
||||
const filteredPageMenu = filterMenuItems(pageMenu, ['all', ..._permissions])
|
||||
const filteredPageMenu = filterMenuItems(state, ['all', ..._permissions])
|
||||
return filteredPageMenu
|
||||
case "COLLAPSE_MENU":
|
||||
return state.map((item) =>
|
||||
@@ -62,40 +80,7 @@ function reducer(state, action) {
|
||||
: item;
|
||||
});
|
||||
case "SELECTED":
|
||||
return state.map((item) => {
|
||||
return item.type === "page"
|
||||
? {
|
||||
...item,
|
||||
selected: action.route === item.route,
|
||||
showSubitems: item.route === action.route,
|
||||
}
|
||||
: item.Subitems && Array.isArray(item.Subitems)
|
||||
? {
|
||||
...item,
|
||||
Subitems: item.Subitems.map((subitem) => {
|
||||
return subitem.type === "page"
|
||||
? {
|
||||
...subitem,
|
||||
selected: action.route === subitem.route,
|
||||
showSubitems: subitem.route === action.route,
|
||||
}
|
||||
: subitem.Subitems && Array.isArray(subitem.Subitems)
|
||||
? {
|
||||
...subitem,
|
||||
Subitems: subitem.Subitems.map((secondSubItem) => ({
|
||||
...secondSubItem,
|
||||
selected: secondSubItem.route === action.route,
|
||||
})),
|
||||
showSubitems: subitem.Subitems.some(
|
||||
(secondSubItem) => secondSubItem.route === action.route
|
||||
),
|
||||
}
|
||||
: subitem;
|
||||
}),
|
||||
showSubitems: item.Subitems.some((subitem) => subitem.showSubitems),
|
||||
}
|
||||
: item;
|
||||
});
|
||||
return state.map(item => selectPage(item, action.route));
|
||||
|
||||
default:
|
||||
throw new Error();
|
||||
@@ -109,13 +94,15 @@ const SidebarMenu = () => {
|
||||
const [selectedKey, setSelectedKey] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch({ type: "SELECTED", route: pathname });
|
||||
setSelectedKey(pathname);
|
||||
}, [userPermissions, pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!userPermissions) return
|
||||
dispatch({ type: 'UPDATE_MENU', permissions: userPermissions });
|
||||
}, [userPermissions])
|
||||
|
||||
useEffect(() => {
|
||||
dispatch({ type: "SELECTED", route: pathname });
|
||||
setSelectedKey(pathname);
|
||||
}, [pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
selectedKey &&
|
||||
@@ -126,11 +113,13 @@ const SidebarMenu = () => {
|
||||
}, [selectedKey]);
|
||||
|
||||
return (
|
||||
<List disablePadding dense>
|
||||
{menuItems.map((menuItem) => {
|
||||
return <SidebarListItems dispatch={dispatch} key={menuItem.id} menuItem={menuItem} />;
|
||||
})}
|
||||
</List>
|
||||
userPermissions && (
|
||||
<List disablePadding dense>
|
||||
{menuItems.map((menuItem) => {
|
||||
return <SidebarListItems dispatch={dispatch} key={menuItem.id} menuItem={menuItem} />;
|
||||
})}
|
||||
</List>
|
||||
)
|
||||
);
|
||||
};
|
||||
export default SidebarMenu;
|
||||
|
||||
@@ -195,6 +195,36 @@ export const pageMenu = [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "inquiryPrivacyManagment",
|
||||
label: "استعلام حریم راه",
|
||||
type: "menu",
|
||||
icon: <Security sx={{ width: "inherit", height: "inherit" }} />,
|
||||
hasSubitems: true,
|
||||
Subitems: [
|
||||
{
|
||||
id: "inquiryPrivacyManagmentFencing",
|
||||
label: "احداث و بهره برداری دیوارکشی و مستحدثات",
|
||||
type: "page",
|
||||
route: prefix + "/dashboard/inquiry_privacy/fencing",
|
||||
permissions: ['all']
|
||||
},
|
||||
{
|
||||
id: "inquiryPrivacyManagmentRoad",
|
||||
label: "احداث راه دسترسی اختصاصی",
|
||||
type: "page",
|
||||
route: prefix + "/dashboard/inquiry_privacy/road",
|
||||
permissions: ['all']
|
||||
},
|
||||
{
|
||||
id: "inquiryPrivacyManagmentInfrastructure",
|
||||
label: "احداث و بهره برداری تاسیسات زیربنایی",
|
||||
type: "page",
|
||||
route: prefix + "/dashboard/inquiry_privacy/infrastructure",
|
||||
permissions: ['all']
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
id: "safetyAndPrivacyManagment",
|
||||
label: "نگهداری حریم راه",
|
||||
|
||||
Reference in New Issue
Block a user