import { ChevronRight, Code, People, Person, SyncAlt } from "@mui/icons-material"; import ChevronLeft from "@mui/icons-material/ChevronLeft"; import { darken, Divider, Grid2 as Grid, IconButton, lighten, List, ListItemButton, ListItemIcon, ListItemText, SwipeableDrawer, Theme, Toolbar, Tooltip, useTheme } from "@mui/material"; import classNames from "classnames"; import { useMobile, useWidth } from "../hooks/useWidth"; import { makeStyles } from "@mui/styles"; import BindaptIcon from "../products/Bindapt/BindaptIcon"; import { useLocation, useNavigate } from "react-router-dom"; import BinsIcon from "products/Bindapt/BinsIcon"; import { useGlobalState } from "providers"; import { IsAdaptiveAgriculture, // hasTutorialPlaylist, IsAdCon, // isBXT, IsMiVent, IsOmniAir, } from "services/whiteLabel"; import MiningIcon from "products/ventilation/MiningIcon"; import { useAuth0 } from "@auth0/auth0-react"; import FieldsIcon from "products/AgIcons/FieldsIcon"; import PlaneIcon from "products/AviationIcons/PlaneIcon"; import AirportMapIcon from "products/AviationIcons/AirportMapIcon"; import JobsiteIcon from "products/Construction/JobSiteIcon"; import { getThemeType } from "theme"; import ObjectHeaterIcon from "products/Construction/ObjectHeaterIcon"; import TasksIcon from "products/Construction/TasksIcon"; import CableIcon from "products/Bindapt/CableIcon"; import FieldListIcon from "products/AgIcons/FieldList"; import MarketplaceIcon from "products/CommonIcons/marketplaceIcon"; import DataDuckIcon from "products/Bindapt/DataDuckIcon"; const drawerWidth = 230; const useStyles = makeStyles((theme: Theme) => ({ sideMenu: { position: "fixed", height: "100%", width: drawerWidth, flexShrink: 0, whiteSpace: "nowrap", background: theme.palette.background.default }, sideMenuOpened: { zIndex: theme.zIndex.drawer + 2, width: drawerWidth, transition: theme.transitions.create(["width"], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.enteringScreen }) }, sideMenuOnClosed: { transition: theme.transitions.create(["width", "z-index", "opacity"], { easing: theme.transitions.easing.sharp, duration: theme.transitions.duration.leavingScreen }), overflowX: "hidden", width: theme.spacing(7), zIndex: theme.zIndex.drawer, opacity: 0, [theme.breakpoints.up("md")]: { width: theme.spacing(9), opacity: 1 } }, list: { paddingTop: 0 }, listItem: { paddingLeft: theme.spacing(2), paddingRight: theme.spacing(2), [theme.breakpoints.up("md")]: { paddingLeft: theme.spacing(3), paddingRight: theme.spacing(3) }, }, activeItem: theme.palette.mode === "light" ? { background: darken(theme.palette.background.default, 0.25), "&:hover": { background: darken(theme.palette.background.default, 0.25) } } : { background: lighten(theme.palette.background.default, 0.25), "&:hover": { background: lighten(theme.palette.background.default, 0.25) } } })) interface Props { open: boolean; onOpen: () => void; onClose: () => void; } export default function SideNavigator(props: Props) { const { open, onOpen, onClose } = props; const { isAuthenticated } = useAuth0() const theme = useTheme(); const width = useWidth(); const classes = useStyles(); const location = useLocation(); const [{ user }] = useGlobalState() const isMobile = useMobile(); const navigate = useNavigate(); const getClasses = (page: string) => { if (page === "/device") { if (location.pathname.startsWith("/device") || location.pathname.startsWith("/group")) { return ({ root: `${classes.listItem} ${classes.activeItem}` }) } } if (location.pathname.startsWith(page)) { return ({ root: `${classes.listItem} ${classes.activeItem}` }) } return ({ root: `${classes.listItem}` }) } const goTo = (url: string) => { onClose(); navigate(url) } const authenticatedSideMenu = () => { const isMiVent = IsMiVent(); const isAg = IsAdaptiveAgriculture() const isMiPCA = IsOmniAir() const isAdCon = IsAdCon() return ( {(isAg || user.hasFeature("admin")) && ( goTo("/bins")} classes={getClasses("/bin")} > {open && } )} {(isMiPCA || user.hasFeature("admin")) && ( goTo("/terminals")} classes={getClasses("/terminal")} > {open && } )} goTo("/devices")} classes={getClasses("/device")} > {open && } {(isMiVent || user.hasFeature("admin")) && ( goTo("/mines")} classes={getClasses("/mine")} > {open && } )} goTo("/teams")} classes={getClasses("/team")} > {open && } goTo("/users")} classes={getClasses("/user")} > {open && } {(isAg || user.hasFeature("admin")) && ( goTo("/visualFarm")} classes={getClasses("/visualFarm")} > {open && } )} {(isAg || user.hasFeature("admin")) && ( goTo("/fields")} classes={getClasses("/fields")} > {open && } )} {(isMiPCA || user.hasFeature("admin")) && ( goTo("/aviationMap")} classes={getClasses("/aviationMap")} > {open && } )} {(isAdCon || user.hasFeature("admin")) && ( goTo("/constructionMap")} classes={getClasses("/constructionMap")} > {open && } )} {(isAdCon || user.hasFeature("admin")) && ( goTo("/jobsites")} classes={getClasses("/jobsites")} > {open && } )} {(isAdCon || user.hasFeature("admin")) && ( goTo("/heaters")} classes={getClasses("/heaters")} > {open && } )} goTo("/tasks")} classes={getClasses("/tasks")} > {open && } goTo("/transactions")} classes={getClasses("/transactions")} > {open && } {(user.hasFeature("installer") && isAg || user.hasFeature("admin")) && goTo("/cableEstimate")} classes={getClasses("/cableEstimate")} > {open && } } {user.hasFeature("developer") && goTo("/api")} classes={getClasses("/api")} > {open && } } {user.hasFeature("admin") && goTo("/logs")} classes={getClasses("/logs")} > {open && } } goTo("/marketplace")} classes={getClasses("/marketplace")} > {open && } ) } return ( {theme.direction === "rtl" ? : } {/* {isAuthenticated || isOffline() ? authenticatedSideMenu() : unauthenticatedSideMenu()} */} {isAuthenticated && authenticatedSideMenu()} ); }