2025-07-31 12:47:36 -07:00
|
|
|
import IconButton from "@mui/material/IconButton";
|
|
|
|
|
import Stack from "@mui/material/Stack";
|
|
|
|
|
import ArrowRight from "../../assets/icons/right-arrow.svg?react";
|
|
|
|
|
import ArrowLeft from "../../assets/icons/left-arrow.svg?react";
|
|
|
|
|
import List from "@mui/material/List";
|
|
|
|
|
import ListItemButton from "@mui/material/ListItemButton";
|
|
|
|
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
|
|
|
|
import ListItemText from "@mui/material/ListItemText";
|
|
|
|
|
import Tooltip from "@mui/material/Tooltip";
|
|
|
|
|
import Logo from "./logo";
|
|
|
|
|
|
2024-12-16 14:16:58 +08:00
|
|
|
import ThemeSwitch from "../ThemeSwitch";
|
2024-08-13 20:17:18 -04:00
|
|
|
import Avatar from "../Avatar";
|
2025-03-03 11:27:43 -05:00
|
|
|
import StarPrompt from "../StarPrompt";
|
2024-08-13 20:17:18 -04:00
|
|
|
import LockSvg from "../../assets/icons/lock.svg?react";
|
|
|
|
|
import UserSvg from "../../assets/icons/user.svg?react";
|
|
|
|
|
import TeamSvg from "../../assets/icons/user-two.svg?react";
|
|
|
|
|
import LogoutSvg from "../../assets/icons/logout.svg?react";
|
2024-07-26 12:39:18 -04:00
|
|
|
import Support from "../../assets/icons/support.svg?react";
|
|
|
|
|
import Maintenance from "../../assets/icons/maintenance.svg?react";
|
|
|
|
|
import Monitors from "../../assets/icons/monitors.svg?react";
|
|
|
|
|
import Incidents from "../../assets/icons/incidents.svg?react";
|
|
|
|
|
import Integrations from "../../assets/icons/integrations.svg?react";
|
|
|
|
|
import PageSpeed from "../../assets/icons/page-speed.svg?react";
|
|
|
|
|
import Settings from "../../assets/icons/settings.svg?react";
|
2024-08-16 12:13:05 -04:00
|
|
|
import ArrowDown from "../../assets/icons/down-arrow.svg?react";
|
|
|
|
|
import ArrowUp from "../../assets/icons/up-arrow.svg?react";
|
2024-08-28 22:14:55 -04:00
|
|
|
import DotsVertical from "../../assets/icons/dots-vertical.svg?react";
|
2024-10-12 23:49:39 +05:30
|
|
|
import ChangeLog from "../../assets/icons/changeLog.svg?react";
|
|
|
|
|
import Docs from "../../assets/icons/docs.svg?react";
|
2024-11-26 16:10:55 -05:00
|
|
|
import StatusPages from "../../assets/icons/status-pages.svg?react";
|
2025-02-25 10:23:59 -05:00
|
|
|
import Discussions from "../../assets/icons/discussions.svg?react";
|
2025-06-10 11:22:24 +08:00
|
|
|
import Notifications from "../../assets/icons/notifications.svg?react";
|
2025-06-23 11:07:12 +08:00
|
|
|
import Logs from "../../assets/icons/logs.svg?react";
|
2025-06-09 12:52:52 +08:00
|
|
|
|
2025-02-06 12:07:39 -08:00
|
|
|
// Utils
|
2025-07-31 12:47:36 -07:00
|
|
|
import { useTheme } from "@mui/material/styles";
|
2025-02-06 12:07:39 -08:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { toggleSidebar } from "../../Features/UI/uiSlice";
|
2025-07-31 12:47:36 -07:00
|
|
|
import { useState } from "react";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import { useNavigate } from "react-router";
|
2025-02-06 12:07:39 -08:00
|
|
|
|
2025-05-09 14:40:07 -04:00
|
|
|
const getMenu = (t) => [
|
|
|
|
|
{ name: t("menu.uptime"), path: "uptime", icon: <Monitors /> },
|
|
|
|
|
{ name: t("menu.pagespeed"), path: "pagespeed", icon: <PageSpeed /> },
|
2025-06-09 10:17:09 +08:00
|
|
|
|
2025-06-09 12:52:52 +08:00
|
|
|
{ name: t("menu.infrastructure"), path: "infrastructure", icon: <Integrations /> },
|
|
|
|
|
{
|
|
|
|
|
name: t("menu.notifications"),
|
|
|
|
|
path: "notifications",
|
2025-06-10 11:22:24 +08:00
|
|
|
icon: <Notifications />,
|
2025-06-09 12:52:52 +08:00
|
|
|
},
|
2025-05-09 14:40:07 -04:00
|
|
|
{ name: t("menu.incidents"), path: "incidents", icon: <Incidents /> },
|
2024-12-13 15:58:24 -05:00
|
|
|
|
2025-05-09 14:40:07 -04:00
|
|
|
{ name: t("menu.statusPages"), path: "status", icon: <StatusPages /> },
|
|
|
|
|
{ name: t("menu.maintenance"), path: "maintenance", icon: <Maintenance /> },
|
2025-06-23 11:07:12 +08:00
|
|
|
{ name: t("menu.logs"), path: "logs", icon: <Logs /> },
|
2025-06-09 12:52:52 +08:00
|
|
|
|
2024-12-23 09:51:41 -05:00
|
|
|
{
|
2025-05-09 14:40:07 -04:00
|
|
|
name: t("menu.settings"),
|
2024-12-23 09:51:41 -05:00
|
|
|
icon: <Settings />,
|
|
|
|
|
path: "settings",
|
|
|
|
|
},
|
2025-03-02 09:13:30 +05:30
|
|
|
];
|
|
|
|
|
|
2025-07-31 12:47:36 -07:00
|
|
|
const Sidebar = () => {
|
2024-10-17 12:05:06 +08:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const dispatch = useDispatch();
|
2025-05-12 10:28:40 -04:00
|
|
|
const { t } = useTranslation();
|
2025-07-31 12:47:36 -07:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
// Redux state
|
2024-10-17 12:05:06 +08:00
|
|
|
const collapsed = useSelector((state) => state.ui.sidebar.collapsed);
|
2024-09-06 11:10:08 -07:00
|
|
|
|
2025-07-31 12:47:36 -07:00
|
|
|
// Local state
|
|
|
|
|
const [open, setOpen] = useState({ Dashboard: false, Account: false, Other: false });
|
2024-11-08 18:36:43 -05:00
|
|
|
|
2025-07-31 12:47:36 -07:00
|
|
|
const menu = getMenu(t);
|
|
|
|
|
console.log(collapsed);
|
2024-10-17 12:05:06 +08:00
|
|
|
return (
|
|
|
|
|
<Stack
|
2025-07-31 12:47:36 -07:00
|
|
|
width={collapsed ? "64px" : "var(--env-var-side-bar-width)"}
|
2024-10-17 12:05:06 +08:00
|
|
|
component="aside"
|
2025-07-31 12:47:36 -07:00
|
|
|
position="relative"
|
|
|
|
|
borderRight={`1px solid ${theme.palette.primary.lowContrast}`}
|
2024-10-17 12:05:06 +08:00
|
|
|
>
|
2025-01-11 11:49:02 -05:00
|
|
|
<IconButton
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
/* TODO 60 is a magic number. if logo chnges size this might break */
|
|
|
|
|
top: 60,
|
|
|
|
|
right: 0,
|
|
|
|
|
transform: `translate(50%, 0)`,
|
|
|
|
|
backgroundColor: theme.palette.tertiary.main,
|
|
|
|
|
border: 1,
|
|
|
|
|
borderColor: theme.palette.primary.lowContrast,
|
|
|
|
|
p: theme.spacing(2.5),
|
|
|
|
|
"& svg": {
|
|
|
|
|
width: theme.spacing(8),
|
|
|
|
|
height: theme.spacing(8),
|
|
|
|
|
"& path": {
|
2025-01-12 09:39:31 -05:00
|
|
|
stroke: theme.palette.primary.contrastTextSecondary,
|
2025-01-11 11:49:02 -05:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
"&:focus": { outline: "none" },
|
|
|
|
|
"&:hover": {
|
|
|
|
|
backgroundColor: theme.palette.primary.lowContrast,
|
|
|
|
|
borderColor: theme.palette.primary.lowContrast,
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setOpen((prev) =>
|
|
|
|
|
Object.fromEntries(Object.keys(prev).map((key) => [key, false]))
|
|
|
|
|
);
|
|
|
|
|
dispatch(toggleSidebar());
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{collapsed ? <ArrowRight /> : <ArrowLeft />}
|
|
|
|
|
</IconButton>
|
2025-07-31 12:47:36 -07:00
|
|
|
<Logo />
|
2025-03-02 09:13:30 +05:30
|
|
|
<List
|
|
|
|
|
component="nav"
|
2025-07-31 12:47:36 -07:00
|
|
|
aria-labelledby="nested-menu-subheader"
|
2025-03-02 09:13:30 +05:30
|
|
|
disablePadding
|
2025-07-31 12:47:36 -07:00
|
|
|
sx={{
|
|
|
|
|
mt: theme.spacing(12),
|
|
|
|
|
px: theme.spacing(6),
|
|
|
|
|
height: "100%",
|
|
|
|
|
/* overflow: "hidden", */
|
|
|
|
|
}}
|
2025-03-02 09:13:30 +05:30
|
|
|
>
|
2025-07-31 12:47:36 -07:00
|
|
|
{menu.map((item) => {
|
2025-03-02 09:13:30 +05:30
|
|
|
return item.path ? (
|
2025-07-31 12:47:36 -07:00
|
|
|
/* If item has a path */
|
2025-03-02 09:13:30 +05:30
|
|
|
<Tooltip
|
|
|
|
|
key={item.path}
|
|
|
|
|
placement="right"
|
|
|
|
|
title={collapsed ? item.name : ""}
|
|
|
|
|
slotProps={{
|
|
|
|
|
popper: {
|
|
|
|
|
modifiers: [
|
|
|
|
|
{
|
|
|
|
|
name: "offset",
|
|
|
|
|
options: {
|
|
|
|
|
offset: [0, -16],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}}
|
|
|
|
|
disableInteractive
|
|
|
|
|
>
|
|
|
|
|
<ListItemButton
|
|
|
|
|
className={
|
2025-03-03 14:51:03 +05:30
|
|
|
location.pathname.startsWith(`/${item.path}`) ? "selected-path" : ""
|
2025-03-02 09:13:30 +05:30
|
|
|
}
|
2025-07-31 12:47:36 -07:00
|
|
|
onClick={() => navigate(`/${item.path}`)}
|
2025-03-02 09:13:30 +05:30
|
|
|
sx={{
|
|
|
|
|
height: "37px",
|
|
|
|
|
gap: theme.spacing(4),
|
|
|
|
|
borderRadius: theme.shape.borderRadius,
|
|
|
|
|
px: theme.spacing(4),
|
2025-03-25 15:58:26 -04:00
|
|
|
pl: theme.spacing(5),
|
2025-03-02 09:13:30 +05:30
|
|
|
}}
|
|
|
|
|
>
|
2025-07-31 12:47:36 -07:00
|
|
|
<ListItemIcon sx={{ minWidth: 0 }}>{item.icon}</ListItemIcon>
|
|
|
|
|
{!collapsed && <ListItemText>{item.name}</ListItemText>}
|
2025-03-02 09:13:30 +05:30
|
|
|
</ListItemButton>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
) : null;
|
|
|
|
|
})}
|
|
|
|
|
</List>
|
2024-10-17 12:05:06 +08:00
|
|
|
</Stack>
|
|
|
|
|
);
|
2025-07-31 12:47:36 -07:00
|
|
|
};
|
2024-07-26 12:39:18 -04:00
|
|
|
|
|
|
|
|
export default Sidebar;
|