Files
Checkmate/client/src/Components/v1/Sidebar/index.jsx
T

154 lines
4.4 KiB
React
Raw Normal View History

2025-07-31 12:47:36 -07:00
import Stack from "@mui/material/Stack";
2025-07-31 15:37:40 -07:00
2025-07-31 12:47:36 -07:00
import List from "@mui/material/List";
2025-09-27 14:54:55 -07:00
import Logo from "./components/logo.jsx";
import CollapseButton from "./components/collapseButton.jsx";
2025-07-31 15:37:40 -07:00
import Divider from "@mui/material/Divider";
2025-09-27 14:54:55 -07:00
import NavItem from "./components/navItem.jsx";
import AuthFooter from "./components/authFooter.jsx";
2025-07-31 12:47:36 -07:00
2025-09-27 14:54:55 -07:00
import StarPrompt from "../StarPrompt/index.jsx";
import Icon from "../Icon";
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-07-31 15:37:40 -07:00
import { useSelector } from "react-redux";
2025-07-31 12:47:36 -07:00
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router";
2025-02-06 12:07:39 -08:00
2025-07-31 15:37:40 -07:00
const URL_MAP = {
support: "https://discord.com/invite/NAb6H3UTjK",
discussions: "https://github.com/bluewave-labs/checkmate/discussions",
docs: "https://bluewavelabs.gitbook.io/checkmate",
changelog: "https://github.com/bluewave-labs/checkmate/releases",
};
2025-05-09 14:40:07 -04:00
const getMenu = (t) => [
{ name: t("menu.uptime"), path: "uptime", icon: <Icon name="Globe" /> },
{ name: t("menu.pagespeed"), path: "pagespeed", icon: <Icon name="Gauge" /> },
{ name: t("menu.infrastructure"), path: "infrastructure", icon: <Icon name="Link" /> },
2025-06-09 12:52:52 +08:00
{
name: t("menu.notifications"),
path: "notifications",
icon: <Icon name="Bell" />,
2025-06-09 12:52:52 +08:00
},
{ name: t("menu.checks"), path: "checks", icon: <Icon name="FileText" /> },
{ name: t("menu.incidents"), path: "incidents", icon: <Icon name="AlertTriangle" /> },
{ name: t("menu.statusPages"), path: "status", icon: <Icon name="Wifi" /> },
{ name: t("menu.maintenance"), path: "maintenance", icon: <Icon name="Wrench" /> },
{ name: t("menu.logs"), path: "logs", icon: <Icon name="Database" /> },
2024-12-23 09:51:41 -05:00
{
2025-05-09 14:40:07 -04:00
name: t("menu.settings"),
icon: <Icon name="Settings" />,
2024-12-23 09:51:41 -05:00
path: "settings",
},
2025-03-02 09:13:30 +05:30
];
2025-07-31 15:37:40 -07:00
const getOtherMenuItems = (t) => [
{ name: t("menu.support"), path: "support", icon: <Icon name="HelpCircle" /> },
2025-07-31 15:37:40 -07:00
{
name: t("menu.discussions"),
path: "discussions",
icon: <Icon name="MessageCircle" />,
2025-07-31 15:37:40 -07:00
},
{ name: t("menu.docs"), path: "docs", icon: <Icon name="FileText" /> },
{ name: t("menu.changelog"), path: "changelog", icon: <Icon name="Code" /> },
2025-07-31 15:37:40 -07:00
];
const getAccountMenuItems = (t) => [
{ name: t("menu.profile"), path: "account/profile", icon: <Icon name="User" /> },
{ name: t("menu.password"), path: "account/password", icon: <Icon name="Lock" /> },
{ name: t("menu.team"), path: "account/team", icon: <Icon name="Users" /> },
2025-07-31 15:37:40 -07:00
];
2025-07-31 12:47:36 -07:00
const Sidebar = () => {
const theme = useTheme();
2025-05-12 10:28:40 -04:00
const { t } = useTranslation();
2025-07-31 12:47:36 -07:00
const navigate = useNavigate();
// Redux state
2026-01-15 17:30:15 -05:00
const collapsed = useSelector((state) => state.ui.sidebar?.collapsed ?? false);
2024-09-06 11:10:08 -07:00
2025-07-31 12:47:36 -07:00
const menu = getMenu(t);
2025-07-31 15:37:40 -07:00
const otherMenuItems = getOtherMenuItems(t);
const accountMenuItems = getAccountMenuItems(t);
return (
<Stack
2025-08-01 15:14:03 -07:00
height="100vh"
width={
collapsed
? "var(--env-var-side-bar-collapsed-width)"
: "var(--env-var-side-bar-width)"
}
component="aside"
2025-08-01 15:14:03 -07:00
position="sticky"
top={0}
2025-07-31 12:47:36 -07:00
borderRight={`1px solid ${theme.palette.primary.lowContrast}`}
2025-07-31 15:37:40 -07:00
paddingTop={theme.spacing(6)}
paddingBottom={theme.spacing(6)}
gap={theme.spacing(6)}
sx={{
transition: "width 650ms cubic-bezier(0.36, -0.01, 0, 0.77)",
}}
>
2025-08-01 14:10:20 -07:00
<CollapseButton collapsed={collapsed} />
2025-07-31 15:37:40 -07:00
<Logo collapsed={collapsed} />
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={{
px: theme.spacing(6),
height: "100%",
}}
2025-03-02 09:13:30 +05:30
>
2025-07-31 12:47:36 -07:00
{menu.map((item) => {
2025-07-31 15:37:40 -07:00
const selected = location.pathname.startsWith(`/${item.path}`);
return (
<NavItem
2025-03-02 09:13:30 +05:30
key={item.path}
2025-07-31 15:37:40 -07:00
item={item}
collapsed={collapsed}
selected={selected}
onClick={() => navigate(`/${item.path}`)}
/>
);
})}
</List>
{!collapsed && <StarPrompt />}
<List
component="nav"
disablePadding
sx={{ px: theme.spacing(6) }}
>
{otherMenuItems.map((item) => {
const selected = location.pathname.startsWith(`/${item.path}`);
return (
<NavItem
key={item.path}
item={item}
collapsed={collapsed}
selected={selected}
onClick={() => {
const url = URL_MAP[item.path];
if (url) {
window.open(url, "_blank", "noreferrer");
} else {
navigate(`/${item.path}`);
2025-03-02 09:13:30 +05:30
}
2025-07-31 15:37:40 -07:00
}}
/>
);
2025-03-02 09:13:30 +05:30
})}
</List>
2025-07-31 15:37:40 -07:00
<Divider sx={{ mt: "auto", borderColor: theme.palette.primary.lowContrast }} />
<AuthFooter
collapsed={collapsed}
accountMenuItems={accountMenuItems}
/>
</Stack>
);
2025-07-31 12:47:36 -07:00
};
2024-07-26 12:39:18 -04:00
export default Sidebar;