add v2 sidebar
This commit is contained in:
1 parent
fc9018e314
commit
3ae2f857d4
10 files changed
+279
-6
No files matched your search
@@ -0,0 +1,16 @@
|
|||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
|
||||||
|
export const BottomControls = ({}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
height={50}
|
||||||
|
py={theme.spacing(4)}
|
||||||
|
px={theme.spacing(8)}
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
></Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import Notifications from "@/assets/icons/notifications.svg?react";
|
||||||
|
import Monitors from "@/assets/icons/monitors.svg?react";
|
||||||
|
import PageSpeed from "@/assets/icons/page-speed.svg?react";
|
||||||
|
import Integrations from "@/assets/icons/integrations.svg?react";
|
||||||
|
import Incidents from "@/assets/icons/incidents.svg?react";
|
||||||
|
import StatusPages from "@/assets/icons/status-pages.svg?react";
|
||||||
|
import Maintenance from "@/assets/icons/maintenance.svg?react";
|
||||||
|
import Logs from "@/assets/icons/logs.svg?react";
|
||||||
|
import Settings from "@/assets/icons/settings.svg?react";
|
||||||
|
import Support from "@/assets/icons/support.svg?react";
|
||||||
|
import Discussions from "@/assets/icons/discussions.svg?react";
|
||||||
|
import Docs from "@/assets/icons/docs.svg?react";
|
||||||
|
import ChangeLog from "@/assets/icons/changeLog.svg?react";
|
||||||
|
|
||||||
|
export const getMenu = (t: Function) => [
|
||||||
|
{ name: t("menu.uptime"), path: "v2/uptime", icon: <Monitors /> },
|
||||||
|
{ name: t("menu.pagespeed"), path: "pagespeed", icon: <PageSpeed /> },
|
||||||
|
|
||||||
|
{ name: t("menu.infrastructure"), path: "infrastructure", icon: <Integrations /> },
|
||||||
|
{
|
||||||
|
name: t("menu.notifications"),
|
||||||
|
path: "notifications",
|
||||||
|
icon: <Notifications />,
|
||||||
|
},
|
||||||
|
{ name: t("menu.incidents"), path: "incidents", icon: <Incidents /> },
|
||||||
|
|
||||||
|
{ name: t("menu.statusPages"), path: "status", icon: <StatusPages /> },
|
||||||
|
{ name: t("menu.maintenance"), path: "maintenance", icon: <Maintenance /> },
|
||||||
|
{ name: t("menu.logs"), path: "logs", icon: <Logs /> },
|
||||||
|
|
||||||
|
{
|
||||||
|
name: t("menu.settings"),
|
||||||
|
icon: <Settings />,
|
||||||
|
path: "settings",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const getBottomMenu = (t: Function) => [
|
||||||
|
{ name: t("menu.support"), path: "support", icon: <Support />, url: "invite" },
|
||||||
|
{
|
||||||
|
name: t("menu.discussions"),
|
||||||
|
path: "discussions",
|
||||||
|
icon: <Discussions />,
|
||||||
|
url: "https://github.com/bluewave-labs/checkmate/discussions",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: t("menu.docs"),
|
||||||
|
path: "docs",
|
||||||
|
icon: <Docs />,
|
||||||
|
url: "https://bluewavelabs.gitbook.io/checkmate",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: t("menu.changelog"),
|
||||||
|
path: "changelog",
|
||||||
|
icon: <ChangeLog />,
|
||||||
|
url: "https://github.com/bluewave-labs/checkmate/releases",
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import Tooltip from "@mui/material/Tooltip";
|
||||||
|
import ListItemButton from "@mui/material/ListItemButton";
|
||||||
|
import ListItemIcon from "@mui/material/ListItemIcon";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
|
||||||
|
export interface NavData {
|
||||||
|
name: string;
|
||||||
|
icon: JSX.Element;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const NavItem = ({
|
||||||
|
item,
|
||||||
|
collapsed,
|
||||||
|
selected,
|
||||||
|
onClick,
|
||||||
|
}: {
|
||||||
|
item: NavData;
|
||||||
|
collapsed: boolean;
|
||||||
|
selected: boolean;
|
||||||
|
onClick: (event: React.MouseEvent) => void;
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const iconStroke = selected
|
||||||
|
? theme.palette.primary.contrastText
|
||||||
|
: theme.palette.primary.contrastTextTertiary;
|
||||||
|
|
||||||
|
const buttonBgColor = selected ? theme.palette.secondary.main : "transparent";
|
||||||
|
const buttonBgHoverColor = selected
|
||||||
|
? theme.palette.secondary.main
|
||||||
|
: theme.palette.tertiary.main;
|
||||||
|
const fontWeight = selected ? 600 : 400;
|
||||||
|
return (
|
||||||
|
<Tooltip
|
||||||
|
placement="right"
|
||||||
|
title={collapsed ? item.name : ""}
|
||||||
|
slotProps={{
|
||||||
|
popper: {
|
||||||
|
modifiers: [
|
||||||
|
{
|
||||||
|
name: "offset",
|
||||||
|
options: {
|
||||||
|
offset: [0, -16],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
disableInteractive
|
||||||
|
>
|
||||||
|
<ListItemButton
|
||||||
|
sx={{
|
||||||
|
backgroundColor: buttonBgColor,
|
||||||
|
"&:hover": {
|
||||||
|
backgroundColor: buttonBgHoverColor,
|
||||||
|
},
|
||||||
|
height: 37,
|
||||||
|
gap: theme.spacing(4),
|
||||||
|
borderRadius: theme.shape.borderRadius,
|
||||||
|
px: theme.spacing(4),
|
||||||
|
pl: theme.spacing(5),
|
||||||
|
}}
|
||||||
|
onClick={onClick}
|
||||||
|
>
|
||||||
|
<ListItemIcon
|
||||||
|
sx={{
|
||||||
|
minWidth: 0,
|
||||||
|
"& svg": {
|
||||||
|
height: 20,
|
||||||
|
width: 20,
|
||||||
|
opacity: 0.81,
|
||||||
|
},
|
||||||
|
"& svg path": {
|
||||||
|
stroke: iconStroke,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.icon}
|
||||||
|
</ListItemIcon>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
overflow: "hidden",
|
||||||
|
transition: "opacity 900ms ease",
|
||||||
|
opacity: collapsed ? 0 : 1,
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
sx={{
|
||||||
|
fontWeight: fontWeight,
|
||||||
|
opacity: 0.9,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{item.name}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</ListItemButton>
|
||||||
|
</Tooltip>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -3,10 +3,17 @@ import { useSelector, useDispatch } from "react-redux";
|
|||||||
import { setCollapsed } from "@/Features/UI/uiSlice";
|
import { setCollapsed } from "@/Features/UI/uiSlice";
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useNavigate, useLocation } from "react-router-dom";
|
||||||
|
|
||||||
import { CollapseButton } from "@/Components/v2/Layouts/Sidebar/CollapseButton";
|
import { CollapseButton } from "@/Components/v2/Layouts/Sidebar/CollapseButton";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
|
import List from "@mui/material/List";
|
||||||
|
import Divider from "@mui/material/Divider";
|
||||||
import { Logo } from "@/Components/v2/Layouts/Sidebar/Logo";
|
import { Logo } from "@/Components/v2/Layouts/Sidebar/Logo";
|
||||||
|
import { getMenu, getBottomMenu } from "@/Components/v2/Layouts/Sidebar/Menu";
|
||||||
|
import { NavItem } from "@/Components/v2/Layouts/Sidebar/NavItem";
|
||||||
|
import { BottomControls } from "@/Components/v2/Layouts/Sidebar/BottomControls";
|
||||||
|
|
||||||
export const COLLAPSED_WIDTH = 64;
|
export const COLLAPSED_WIDTH = 64;
|
||||||
export const EXPANDED_WIDTH = 250;
|
export const EXPANDED_WIDTH = 250;
|
||||||
@@ -16,6 +23,11 @@ export const SideBar = () => {
|
|||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const collapsed = useSelector((state: any) => state.ui.sidebar.collapsed);
|
const collapsed = useSelector((state: any) => state.ui.sidebar.collapsed);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
const menu = getMenu(t);
|
||||||
|
const bottomMenu = getBottomMenu(t);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(setCollapsed({ collapsed: isSmall }));
|
dispatch(setCollapsed({ collapsed: isSmall }));
|
||||||
@@ -23,6 +35,7 @@ export const SideBar = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
|
component="aside"
|
||||||
position="sticky"
|
position="sticky"
|
||||||
paddingTop={theme.spacing(6)}
|
paddingTop={theme.spacing(6)}
|
||||||
paddingBottom={theme.spacing(6)}
|
paddingBottom={theme.spacing(6)}
|
||||||
@@ -30,11 +43,61 @@ export const SideBar = () => {
|
|||||||
borderRight={`1px solid ${theme.palette.primary.lowContrast}`}
|
borderRight={`1px solid ${theme.palette.primary.lowContrast}`}
|
||||||
width={collapsed ? COLLAPSED_WIDTH : EXPANDED_WIDTH}
|
width={collapsed ? COLLAPSED_WIDTH : EXPANDED_WIDTH}
|
||||||
sx={{
|
sx={{
|
||||||
transition: "width 0.3s ease",
|
transition: "width 650ms cubic-bezier(0.36, -0.01, 0, 0.77)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CollapseButton collapsed={collapsed} />
|
<CollapseButton collapsed={collapsed} />
|
||||||
<Logo collapsed={collapsed} />
|
<Logo collapsed={collapsed} />
|
||||||
|
<List
|
||||||
|
component="nav"
|
||||||
|
disablePadding
|
||||||
|
sx={{
|
||||||
|
px: theme.spacing(6),
|
||||||
|
height: "100%",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{menu.map((item) => {
|
||||||
|
const selected = location.pathname.startsWith(`/${item.path}`);
|
||||||
|
return (
|
||||||
|
<NavItem
|
||||||
|
key={item.path}
|
||||||
|
item={item}
|
||||||
|
collapsed={collapsed}
|
||||||
|
selected={selected}
|
||||||
|
onClick={() => navigate(`/${item.path}`)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
|
<List
|
||||||
|
component="nav"
|
||||||
|
disablePadding
|
||||||
|
sx={{
|
||||||
|
px: theme.spacing(6),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{bottomMenu.map((item) => {
|
||||||
|
const selected = location.pathname.startsWith(`/${item.path}`);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NavItem
|
||||||
|
key={item.path}
|
||||||
|
item={item}
|
||||||
|
collapsed={collapsed}
|
||||||
|
selected={selected}
|
||||||
|
onClick={() => {
|
||||||
|
if (item.url) {
|
||||||
|
window.open(item.url, "_blank", "noreferrer");
|
||||||
|
} else {
|
||||||
|
navigate(`/${item.path}`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
|
<Divider sx={{ mt: "auto", borderColor: theme.palette.primary.lowContrast }} />
|
||||||
|
<BottomControls />
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { createSlice } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
isAuthenticated: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
const v2AuthSlice = createSlice({
|
||||||
|
name: "v2Auth",
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
setIsAuthenticated: (state, action) => {
|
||||||
|
const { authenticated } = action.payload;
|
||||||
|
state.isAuthenticated = authenticated;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default v2AuthSlice.reducer;
|
||||||
|
export const { setIsAuthenticated } = v2AuthSlice.actions;
|
||||||
@@ -3,7 +3,9 @@ import { z } from "zod";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, Controller } from "react-hook-form";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { useDispatch } from "react-redux";
|
||||||
|
import { setIsAuthenticated } from "@/Features/Auth/v2AuthSlice";
|
||||||
|
import { useNavigate } from "react-router";
|
||||||
import { TextInput } from "@/Components/v2/Inputs/TextInput";
|
import { TextInput } from "@/Components/v2/Inputs/TextInput";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
@@ -19,8 +21,10 @@ type FormData = z.infer<typeof schema>;
|
|||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const dispatch = useDispatch();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { post, loading, error } = usePost<FormData, ApiResponse>("/auth/login");
|
const { post, loading, error } = usePost<FormData, ApiResponse>("/auth/login");
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
@@ -37,9 +41,10 @@ const Login = () => {
|
|||||||
const onSubmit = async (data: FormData) => {
|
const onSubmit = async (data: FormData) => {
|
||||||
const result = await post(data);
|
const result = await post(data);
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log(result.message);
|
dispatch(setIsAuthenticated({ authenticated: true }));
|
||||||
|
navigate("/v2/uptime");
|
||||||
} else {
|
} else {
|
||||||
console.error("Login failed:", error);
|
dispatch(setIsAuthenticated({ authenticated: false }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,11 @@ const V2Routes = ({ mode = "light" }) => {
|
|||||||
element={<RootLayout />}
|
element={<RootLayout />}
|
||||||
>
|
>
|
||||||
<Route
|
<Route
|
||||||
path="test"
|
index
|
||||||
|
element={<h1>Uptime</h1>}
|
||||||
|
/>
|
||||||
|
<Route
|
||||||
|
path="uptime"
|
||||||
element={<h1>Test Page</h1>}
|
element={<h1>Test Page</h1>}
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export const lightPalette = {
|
|||||||
main: colors.offWhite,
|
main: colors.offWhite,
|
||||||
contrastText: colors.blueGray800,
|
contrastText: colors.blueGray800,
|
||||||
contrastTextSecondary: colors.blueGray600,
|
contrastTextSecondary: colors.blueGray600,
|
||||||
|
contrastTextTertiary: colors.blueGray500,
|
||||||
lowContrast: colors.gray250,
|
lowContrast: colors.gray250,
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
@@ -78,6 +79,7 @@ export const darkPalette = {
|
|||||||
main: colors.offBlack,
|
main: colors.offBlack,
|
||||||
contrastText: colors.blueGray50,
|
contrastText: colors.blueGray50,
|
||||||
contrastTextSecondary: colors.gray200,
|
contrastTextSecondary: colors.gray200,
|
||||||
|
contrastTextTertiary: colors.gray500,
|
||||||
lowContrast: colors.blueGray600,
|
lowContrast: colors.blueGray600,
|
||||||
},
|
},
|
||||||
secondary: {
|
secondary: {
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
import authReducer from "./Features/Auth/authSlice";
|
import authReducer from "./Features/Auth/authSlice";
|
||||||
|
import v2AuthReducer from "./Features/Auth/v2AuthSlice";
|
||||||
import uiReducer from "./Features/UI/uiSlice";
|
import uiReducer from "./Features/UI/uiSlice";
|
||||||
import storage from "redux-persist/lib/storage";
|
import storage from "redux-persist/lib/storage";
|
||||||
import { persistReducer, persistStore, createTransform } from "redux-persist";
|
import { persistReducer, persistStore, createTransform } from "redux-persist";
|
||||||
@@ -19,12 +20,13 @@ const authTransform = createTransform(
|
|||||||
const persistConfig = {
|
const persistConfig = {
|
||||||
key: "root",
|
key: "root",
|
||||||
storage,
|
storage,
|
||||||
whitelist: ["auth", "ui"],
|
whitelist: ["auth", "v2Auth", "ui"],
|
||||||
transforms: [authTransform],
|
transforms: [authTransform],
|
||||||
};
|
};
|
||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
auth: authReducer,
|
auth: authReducer,
|
||||||
|
v2Auth: v2AuthReducer,
|
||||||
ui: uiReducer,
|
ui: uiReducer,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
@@ -12,6 +12,7 @@ declare module "@mui/material/styles" {
|
|||||||
|
|
||||||
interface PaletteColor {
|
interface PaletteColor {
|
||||||
contrastTextSecondary?: string;
|
contrastTextSecondary?: string;
|
||||||
|
contrastTextTertiary?: string;
|
||||||
lowContrast?: string;
|
lowContrast?: string;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user