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

171 lines
5.1 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-08-01 15:01:30 -07:00
import Logo from "./components/logo";
import CollapseButton from "./components/collapseButton";
2025-07-31 15:37:40 -07:00
import Divider from "@mui/material/Divider";
import NavItem from "./components/navItem";
import AuthFooter from "./components/authFooter";
2025-07-31 12:47:36 -07:00
2025-03-03 11:27:43 -05:00
import StarPrompt from "../StarPrompt";
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";
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-10-12 23:49:39 +05:30
import ChangeLog from "../../assets/icons/changeLog.svg?react";
import Docs from "../../assets/icons/docs.svg?react";
import StatusPages from "../../assets/icons/status-pages.svg?react";
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-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: <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 15:37:40 -07:00
const getOtherMenuItems = (t) => [
{ name: t("menu.support"), path: "support", icon: <Support /> },
{
name: t("menu.discussions"),
path: "discussions",
icon: <Discussions />,
},
{ name: t("menu.docs"), path: "docs", icon: <Docs /> },
{ name: t("menu.changelog"), path: "changelog", icon: <ChangeLog /> },
];
const getAccountMenuItems = (t) => [
{ name: t("menu.profile"), path: "account/profile", icon: <UserSvg /> },
{ name: t("menu.password"), path: "account/password", icon: <LockSvg /> },
{ name: t("menu.team"), path: "account/team", icon: <TeamSvg /> },
];
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
const collapsed = useSelector((state) => state.ui.sidebar.collapsed);
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;