98 lines
2.4 KiB
TypeScript
98 lines
2.4 KiB
TypeScript
import List from "@mui/material/List";
|
|
import ListItem from "@mui/material/ListItem";
|
|
import ListItemButton from "@mui/material/ListItemButton";
|
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
import ListItemText from "@mui/material/ListItemText";
|
|
import Stack from "@mui/material/Stack";
|
|
import HomeRoundedIcon from "@mui/icons-material/HomeRounded";
|
|
import AnalyticsRoundedIcon from "@mui/icons-material/AnalyticsRounded";
|
|
import FormatListBulletedIcon from "@mui/icons-material/FormatListBulleted";
|
|
import { Link, useLocation } from "react-router-dom";
|
|
import { useSelector } from "react-redux";
|
|
import { RootState } from "../../redux/store/store";
|
|
|
|
const baseMenuItems = [
|
|
{
|
|
text: "Home",
|
|
icon: <HomeRoundedIcon />,
|
|
url: "/panel/dashboard",
|
|
},
|
|
{
|
|
text: "Vehicles",
|
|
icon: <AnalyticsRoundedIcon />,
|
|
url: "/panel/vehicles",
|
|
},
|
|
//created by Eknnor and Jaanvi
|
|
];
|
|
|
|
//Eknoor singh and Jaanvi
|
|
//date:- 12-Feb-2025
|
|
//Made a different variable for super admin to access all the details.
|
|
|
|
const superAdminOnlyItems = [
|
|
{
|
|
text: "Admin List",
|
|
icon: <FormatListBulletedIcon />,
|
|
url: "/panel/adminlist",
|
|
},
|
|
];
|
|
|
|
type PropType = {
|
|
hidden: boolean;
|
|
};
|
|
|
|
export default function MenuContent({ hidden }: PropType) {
|
|
const location = useLocation();
|
|
const userRole = useSelector(
|
|
(state: RootState) => state.profileReducer.user?.role
|
|
);
|
|
|
|
const mainListItems = [
|
|
...baseMenuItems,
|
|
...(userRole === "superadmin" ? superAdminOnlyItems : []),
|
|
];
|
|
|
|
return (
|
|
<Stack sx={{ flexGrow: 1, p: 1, justifyContent: "space-between" }}>
|
|
<List dense>
|
|
{mainListItems.map((item, index) => (
|
|
<ListItem
|
|
key={index}
|
|
disablePadding
|
|
sx={{ display: "block", py: 1 }}
|
|
>
|
|
{/* Wrap ListItemButton with Link to enable routing */}
|
|
<ListItemButton
|
|
component={Link}
|
|
to={item.url}
|
|
selected={item.url === location.pathname}
|
|
sx={{ alignItems: "center", columnGap: 1 }}
|
|
>
|
|
<ListItemIcon
|
|
sx={{
|
|
minWidth: "fit-content",
|
|
".MuiSvgIcon-root": {
|
|
fontSize: 24,
|
|
},
|
|
}}
|
|
>
|
|
{item.icon}
|
|
</ListItemIcon>
|
|
<ListItemText
|
|
sx={{
|
|
display: !hidden ? "none" : "",
|
|
transition: "all 0.5s ease",
|
|
".MuiListItemText-primary": {
|
|
fontSize: "16px",
|
|
},
|
|
}}
|
|
primary={item.text}
|
|
/>
|
|
</ListItemButton>
|
|
</ListItem>
|
|
))}
|
|
</List>
|
|
</Stack>
|
|
);
|
|
}
|