14 files changed
+149
-560
No files matched your search
@@ -1,9 +0,0 @@
|
|||||||
.alert {
|
|
||||||
margin: 0;
|
|
||||||
width: fit-content;
|
|
||||||
}
|
|
||||||
.alert,
|
|
||||||
.alert button,
|
|
||||||
.alert .MuiTypography-root {
|
|
||||||
font-size: var(--env-var-font-size-medium);
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
import PropTypes from "prop-types";
|
|
||||||
import { useTheme } from "@emotion/react";
|
|
||||||
import { Box, Button, IconButton, Stack, Typography } from "@mui/material";
|
|
||||||
import Icon from "../Icon";
|
|
||||||
import "./index.css";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Icons mapping for different alert variants.
|
|
||||||
* @type {Object<string, JSX.Element>}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const icons = {
|
|
||||||
info: (
|
|
||||||
<Icon
|
|
||||||
name="Info"
|
|
||||||
size={24}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
error: (
|
|
||||||
<Icon
|
|
||||||
name="AlertCircle"
|
|
||||||
size={24}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
warning: (
|
|
||||||
<Icon
|
|
||||||
name="AlertTriangle"
|
|
||||||
size={24}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param {Object} props
|
|
||||||
* @param {'info' | 'error' | 'warning'} props.variant - The type of alert.
|
|
||||||
* @param {string} [props.title] - The title of the alert.
|
|
||||||
* @param {string} [props.body] - The body text of the alert.
|
|
||||||
* @param {boolean} [props.isToast] - Indicates if the alert is used as a toast notification.
|
|
||||||
* @param {boolean} [props.hasIcon] - Whether to display an icon in the alert.
|
|
||||||
* @param {function} props.onClick - Toast dismiss function.
|
|
||||||
* @returns {JSX.Element}
|
|
||||||
*/
|
|
||||||
|
|
||||||
const Alert = ({ variant, title, body, isToast, hasIcon = true, onClick }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
/* TODO
|
|
||||||
Do we need other variants for alert?
|
|
||||||
*/
|
|
||||||
|
|
||||||
const text = theme.palette.secondary.contrastText;
|
|
||||||
const border = theme.palette.alert.contrastText;
|
|
||||||
const bg = theme.palette.alert.main;
|
|
||||||
const icon = icons[variant];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-start"
|
|
||||||
alignItems={hasIcon ? "" : "center"}
|
|
||||||
className="alert row-stack"
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
sx={{
|
|
||||||
padding: hasIcon ? theme.spacing(8) : `${theme.spacing(4)} ${theme.spacing(8)}`,
|
|
||||||
backgroundColor: bg,
|
|
||||||
border: `solid 1px ${border}`,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{hasIcon && <Box sx={{ color: text }}>{icon}</Box>}
|
|
||||||
<Stack
|
|
||||||
direction="column"
|
|
||||||
gap="2px"
|
|
||||||
sx={{ flex: 1 }}
|
|
||||||
>
|
|
||||||
{title && (
|
|
||||||
<Typography sx={{ fontWeight: "700", color: `${text}` }}>{title}</Typography>
|
|
||||||
)}
|
|
||||||
{body && (
|
|
||||||
<Typography sx={{ fontWeight: "400", color: `${text}` }}>{body}</Typography>
|
|
||||||
)}
|
|
||||||
{hasIcon && isToast && (
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={onClick}
|
|
||||||
sx={{
|
|
||||||
fontWeight: "600",
|
|
||||||
width: "fit-content",
|
|
||||||
mt: theme.spacing(4),
|
|
||||||
padding: 0,
|
|
||||||
minWidth: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Dismiss
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
{isToast && (
|
|
||||||
<IconButton
|
|
||||||
onClick={onClick}
|
|
||||||
sx={{
|
|
||||||
alignSelf: "flex-start",
|
|
||||||
ml: "auto",
|
|
||||||
mr: "-5px",
|
|
||||||
mt: hasIcon ? "-5px" : 0,
|
|
||||||
padding: "5px",
|
|
||||||
"&:focus": {
|
|
||||||
outline: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
name="X"
|
|
||||||
size={20}
|
|
||||||
/>
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Alert.propTypes = {
|
|
||||||
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
|
|
||||||
title: PropTypes.string,
|
|
||||||
body: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
||||||
isToast: PropTypes.bool,
|
|
||||||
hasIcon: PropTypes.bool,
|
|
||||||
onClick: function (props, propName, componentName) {
|
|
||||||
if (props.isToast && !props[propName]) {
|
|
||||||
return new Error(
|
|
||||||
`Prop '${propName}' is required when 'isToast' is true in '${componentName}'.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Alert;
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
import { useEffect, useState } from "react";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
|
|
||||||
import { logger } from "../../../Utils/Logger.js";
|
|
||||||
import { useLazyGet } from "@/Hooks/UseApi";
|
|
||||||
|
|
||||||
const withAdminCheck = (WrappedComponent) => {
|
|
||||||
const WithAdminCheck = (props) => {
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const [superAdminExists, setSuperAdminExists] = useState(false);
|
|
||||||
const [hasChecked, setHasChecked] = useState(false);
|
|
||||||
const { get: checkSuperAdmin, loading: isChecking } = useLazyGet();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
checkSuperAdmin("/auth/users/superadmin")
|
|
||||||
.then((response) => {
|
|
||||||
if (response?.data === true) {
|
|
||||||
navigate("/login");
|
|
||||||
} else {
|
|
||||||
setSuperAdminExists(false);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
logger.error(error);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setHasChecked(true);
|
|
||||||
});
|
|
||||||
}, [navigate, checkSuperAdmin]);
|
|
||||||
|
|
||||||
if (!hasChecked || isChecking) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<WrappedComponent
|
|
||||||
{...props}
|
|
||||||
superAdminExists={superAdminExists}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
const wrappedComponentName =
|
|
||||||
WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
||||||
WithAdminCheck.displayName = `WithAdminCheck(${wrappedComponentName})`;
|
|
||||||
|
|
||||||
return WithAdminCheck;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default withAdminCheck;
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import { Navigate } from "react-router-dom";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ProtectedRoute is a wrapper component that ensures only authenticated users
|
|
||||||
* can access the wrapped content. It checks authentication status (e.g., from Redux or Context).
|
|
||||||
* If the user is authenticated, it renders the children; otherwise, it redirects to the login page.
|
|
||||||
*
|
|
||||||
* @param {Object} props - The props passed to the ProtectedRoute component.
|
|
||||||
* @param {React.ReactNode} props.children - The children to render if the user is authenticated.
|
|
||||||
* @returns {React.ReactElement} The children wrapped in a protected route or a redirect to the login page.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const ProtectedRoute = ({ children }) => {
|
|
||||||
const authState = useSelector((state) => state.auth);
|
|
||||||
|
|
||||||
return authState.authToken ? (
|
|
||||||
children
|
|
||||||
) : (
|
|
||||||
<Navigate
|
|
||||||
to="/login"
|
|
||||||
replace
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
ProtectedRoute.propTypes = {
|
|
||||||
children: PropTypes.element.isRequired,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ProtectedRoute;
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import { Navigate } from "react-router-dom";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import PropTypes from "prop-types";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ProtectedRoute is a wrapper component that ensures only authenticated users
|
|
||||||
* can access the wrapped content. It checks authentication status (e.g., from Redux or Context).
|
|
||||||
* If the user is authenticated, it renders the children; otherwise, it redirects to the login page.
|
|
||||||
*
|
|
||||||
* @param {Object} props - The props passed to the ProtectedRoute component.
|
|
||||||
* @param {React.ReactNode} props.children - The children to render if the user is authenticated.
|
|
||||||
* @returns {React.ReactElement} The children wrapped in a protected route or a redirect to the login page.
|
|
||||||
*/
|
|
||||||
|
|
||||||
const RoleProtectedRoute = ({ roles, children }) => {
|
|
||||||
const authState = useSelector((state) => state.auth);
|
|
||||||
const userRoles = authState?.user?.role || [];
|
|
||||||
const canAccess = userRoles.some((role) => roles.includes(role));
|
|
||||||
|
|
||||||
return canAccess ? (
|
|
||||||
children
|
|
||||||
) : (
|
|
||||||
<Navigate
|
|
||||||
to="/uptime"
|
|
||||||
replace
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
RoleProtectedRoute.propTypes = {
|
|
||||||
children: PropTypes.element.isRequired,
|
|
||||||
roles: PropTypes.array,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RoleProtectedRoute;
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
import { useTheme } from "@mui/material";
|
|
||||||
import "./index.css";
|
|
||||||
|
|
||||||
const SunAndMoonIcon = () => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<svg
|
|
||||||
className="sun-and-moon"
|
|
||||||
aria-hidden="true"
|
|
||||||
width="24"
|
|
||||||
height="24"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
>
|
|
||||||
<mask
|
|
||||||
className="moon"
|
|
||||||
id="moon-mask"
|
|
||||||
>
|
|
||||||
<rect
|
|
||||||
x="0"
|
|
||||||
y="0"
|
|
||||||
width="100%"
|
|
||||||
height="100%"
|
|
||||||
fill="#fff"
|
|
||||||
/>
|
|
||||||
<circle
|
|
||||||
cx="24"
|
|
||||||
cy="10"
|
|
||||||
r="6"
|
|
||||||
fill="#000"
|
|
||||||
/>
|
|
||||||
</mask>
|
|
||||||
<circle
|
|
||||||
className="sun"
|
|
||||||
cx="12"
|
|
||||||
cy="12"
|
|
||||||
r="6"
|
|
||||||
fill={theme.palette.primary.contrastTextSecondary}
|
|
||||||
mask="url(#moon-mask)"
|
|
||||||
/>
|
|
||||||
<g
|
|
||||||
className="sun-beams"
|
|
||||||
stroke={theme.palette.primary.contrastTextSecondary}
|
|
||||||
>
|
|
||||||
<line
|
|
||||||
x1="12"
|
|
||||||
y1="1"
|
|
||||||
x2="12"
|
|
||||||
y2="3"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="12"
|
|
||||||
y1="21"
|
|
||||||
x2="12"
|
|
||||||
y2="23"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="4.22"
|
|
||||||
y1="4.22"
|
|
||||||
x2="5.64"
|
|
||||||
y2="5.64"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="18.36"
|
|
||||||
y1="18.36"
|
|
||||||
x2="19.78"
|
|
||||||
y2="19.78"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="1"
|
|
||||||
y1="12"
|
|
||||||
x2="3"
|
|
||||||
y2="12"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="21"
|
|
||||||
y1="12"
|
|
||||||
x2="23"
|
|
||||||
y2="12"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="4.22"
|
|
||||||
y1="19.78"
|
|
||||||
x2="5.64"
|
|
||||||
y2="18.36"
|
|
||||||
/>
|
|
||||||
<line
|
|
||||||
x1="18.36"
|
|
||||||
y1="5.64"
|
|
||||||
x2="19.78"
|
|
||||||
y2="4.22"
|
|
||||||
/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default SunAndMoonIcon;
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
.sun-and-moon > :is(.moon, .sun, .sun-beams) {
|
|
||||||
transform-origin: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-toggle .sun-and-moon > .sun-beams {
|
|
||||||
stroke-width: 2px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-dark .sun-and-moon > .sun {
|
|
||||||
transform: scale(1.75);
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-dark .sun-and-moon > .sun-beams {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-dark .sun-and-moon > .moon > circle {
|
|
||||||
transform: translateX(-7px);
|
|
||||||
}
|
|
||||||
|
|
||||||
@supports (cx: 1) {
|
|
||||||
.theme-dark .sun-and-moon > .moon > circle {
|
|
||||||
cx: 17;
|
|
||||||
transform: translateX(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (prefers-reduced-motion: no-preference) {
|
|
||||||
.sun-and-moon > .sun {
|
|
||||||
transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55);
|
|
||||||
}
|
|
||||||
|
|
||||||
.sun-and-moon > .sun-beams {
|
|
||||||
transition:
|
|
||||||
transform 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55),
|
|
||||||
opacity 0.5s cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.sun-and-moon .moon > circle {
|
|
||||||
transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@supports (cx: 1) {
|
|
||||||
.sun-and-moon .moon > circle {
|
|
||||||
transition: cx 0.25s cubic-bezier(0.4, 0, 0.2, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-dark .sun-and-moon > .sun {
|
|
||||||
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
||||||
transition-duration: 0.25s;
|
|
||||||
transform: scale(1.75);
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-dark .sun-and-moon > .sun-beams {
|
|
||||||
transition-duration: 0.15s;
|
|
||||||
transform: rotateZ(-25deg);
|
|
||||||
}
|
|
||||||
|
|
||||||
.theme-dark .sun-and-moon > .moon > circle {
|
|
||||||
transition-duration: 0.5s;
|
|
||||||
transition-delay: 0.25s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/**
|
|
||||||
* ThemeSwitch Component
|
|
||||||
* Dark and Light Theme Switch
|
|
||||||
* Original Code: https://web.dev/patterns/theming/theme-switch
|
|
||||||
* License: Apache License 2.0
|
|
||||||
* Copyright © Google LLC
|
|
||||||
*
|
|
||||||
* This code has been adapted for use in this project.
|
|
||||||
* Apache License: https://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { IconButton } from "@mui/material";
|
|
||||||
import SunAndMoonIcon from "./SunAndMoonIcon.jsx";
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
|
||||||
import { setMode } from "../../../Features/UI/uiSlice.js";
|
|
||||||
import "./index.css";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const ThemeSwitch = ({ width = 48, height = 48, color }) => {
|
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const toggleTheme = () => {
|
|
||||||
dispatch(setMode(mode === "light" ? "dark" : "light"));
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<IconButton
|
|
||||||
id="theme-toggle"
|
|
||||||
title={t("common.buttons.toggleTheme")}
|
|
||||||
className={`theme-${mode}`}
|
|
||||||
aria-label="auto"
|
|
||||||
aria-live="polite"
|
|
||||||
onClick={toggleTheme}
|
|
||||||
sx={{
|
|
||||||
width,
|
|
||||||
height,
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
"& svg >:is(circle, g)": {
|
|
||||||
fill: color,
|
|
||||||
stroke: color,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SunAndMoonIcon />
|
|
||||||
</IconButton>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ThemeSwitch;
|
|
||||||
@@ -31,6 +31,7 @@ export const Avatar = ({ src, small, sx, onClick = () => {} }: AvatarProps) => {
|
|||||||
alt={`${user?.firstName} ${user?.lastName}`}
|
alt={`${user?.firstName} ${user?.lastName}`}
|
||||||
src={src ? src : user?.avatarImage ? image : undefined}
|
src={src ? src : user?.avatarImage ? image : undefined}
|
||||||
sx={{
|
sx={{
|
||||||
|
color: theme.palette.primary.contrastText,
|
||||||
fontSize: small ? "16px" : "22px",
|
fontSize: small ? "16px" : "22px",
|
||||||
fontWeight: 400,
|
fontWeight: 400,
|
||||||
backgroundColor: theme.palette.primary.main,
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { Navigate } from "react-router-dom";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import type { RootState } from "@/Types/state";
|
||||||
|
import type { UserRole } from "@/Types/User";
|
||||||
|
|
||||||
|
interface ProtectedRouteProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
|
||||||
|
const authState = useSelector((state: RootState) => state.auth);
|
||||||
|
|
||||||
|
return authState.authToken ? (
|
||||||
|
children
|
||||||
|
) : (
|
||||||
|
<Navigate
|
||||||
|
to="/login"
|
||||||
|
replace
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface RoleProtectedRouteProps {
|
||||||
|
roles: UserRole[];
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RoleProtectedRoute = ({ roles, children }: RoleProtectedRouteProps) => {
|
||||||
|
const authState = useSelector((state: RootState) => state.auth);
|
||||||
|
const userRoles = authState?.user?.role || [];
|
||||||
|
const canAccess = userRoles.some((role) => roles.includes(role));
|
||||||
|
|
||||||
|
return canAccess ? (
|
||||||
|
children
|
||||||
|
) : (
|
||||||
|
<Navigate
|
||||||
|
to="/uptime"
|
||||||
|
replace
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -76,7 +76,7 @@ export const AuthFooter = ({ collapsed, accountMenuItems }: AuthFooterProps) =>
|
|||||||
alignItems="center"
|
alignItems="center"
|
||||||
py={theme.spacing(4)}
|
py={theme.spacing(4)}
|
||||||
px={theme.spacing(8)}
|
px={theme.spacing(8)}
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(4)}
|
||||||
>
|
>
|
||||||
<Avatar
|
<Avatar
|
||||||
small
|
small
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
|
import Backdrop from "@mui/material/Backdrop";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import List from "@mui/material/List";
|
import List from "@mui/material/List";
|
||||||
import Divider from "@mui/material/Divider";
|
import Divider from "@mui/material/Divider";
|
||||||
@@ -51,71 +52,80 @@ export const Sidebar = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<>
|
||||||
component="aside"
|
<Backdrop
|
||||||
position={isSmall ? "fixed" : "sticky"}
|
open={!collapsed && isSmall}
|
||||||
top={0}
|
onClick={() => dispatch(setCollapsed({ collapsed: true }))}
|
||||||
left={0}
|
sx={{ zIndex: 999 }}
|
||||||
minHeight={"100vh"}
|
/>
|
||||||
maxHeight={"100vh"}
|
<Stack
|
||||||
paddingTop={theme.spacing(6)}
|
component="aside"
|
||||||
paddingBottom={theme.spacing(6)}
|
position={isSmall ? "fixed" : "sticky"}
|
||||||
gap={theme.spacing(6)}
|
top={0}
|
||||||
borderRight={`1px solid ${theme.palette.divider}`}
|
left={0}
|
||||||
width={width}
|
minHeight={"100vh"}
|
||||||
sx={{
|
maxHeight={"100vh"}
|
||||||
transition: transition,
|
paddingTop={theme.spacing(6)}
|
||||||
zIndex: isSmall ? (t) => t.zIndex.drawer : "auto",
|
paddingBottom={theme.spacing(6)}
|
||||||
}}
|
gap={theme.spacing(6)}
|
||||||
>
|
borderRight={`1px solid ${theme.palette.divider}`}
|
||||||
<List
|
width={width}
|
||||||
component="nav"
|
|
||||||
disablePadding
|
|
||||||
sx={{
|
sx={{
|
||||||
px: theme.spacing(6),
|
touchAction: "none",
|
||||||
flex: 1,
|
transition: transition,
|
||||||
|
zIndex: 1000,
|
||||||
|
backdropFilter: "blur(8px)",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Logo
|
<List
|
||||||
pt={theme.spacing(8)}
|
component="nav"
|
||||||
pb={theme.spacing(10)}
|
disablePadding
|
||||||
/>
|
sx={{
|
||||||
{menu.map((item) => {
|
px: theme.spacing(6),
|
||||||
const selected = location.pathname.startsWith(`/${item.path}`);
|
flex: 1,
|
||||||
return (
|
}}
|
||||||
<NavItem
|
>
|
||||||
key={item.path}
|
<Logo
|
||||||
item={item}
|
pt={theme.spacing(8)}
|
||||||
selected={selected}
|
pb={theme.spacing(10)}
|
||||||
onClick={() => handleNavClick(item.path)}
|
/>
|
||||||
/>
|
{menu.map((item) => {
|
||||||
);
|
const selected = location.pathname.startsWith(`/${item.path}`);
|
||||||
})}
|
return (
|
||||||
</List>
|
<NavItem
|
||||||
<StarPrompt />
|
key={item.path}
|
||||||
<List
|
item={item}
|
||||||
component="nav"
|
selected={selected}
|
||||||
disablePadding
|
onClick={() => handleNavClick(item.path)}
|
||||||
sx={{ px: theme.spacing(6) }}
|
/>
|
||||||
>
|
);
|
||||||
{bottomMenu.map((item) => {
|
})}
|
||||||
const selected = location.pathname.startsWith(`/${item.path}`);
|
</List>
|
||||||
return (
|
<StarPrompt />
|
||||||
<NavItem
|
<List
|
||||||
key={item.path}
|
component="nav"
|
||||||
item={item}
|
disablePadding
|
||||||
selected={selected}
|
sx={{ px: theme.spacing(6) }}
|
||||||
onClick={() => handleNavClick(item.path)}
|
>
|
||||||
/>
|
{bottomMenu.map((item) => {
|
||||||
);
|
const selected = location.pathname.startsWith(`/${item.path}`);
|
||||||
})}
|
return (
|
||||||
</List>
|
<NavItem
|
||||||
<Divider sx={{ borderColor: theme.palette.divider }} />
|
key={item.path}
|
||||||
|
item={item}
|
||||||
|
selected={selected}
|
||||||
|
onClick={() => handleNavClick(item.path)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</List>
|
||||||
|
<Divider sx={{ borderColor: theme.palette.divider }} />
|
||||||
|
|
||||||
<AuthFooter
|
<AuthFooter
|
||||||
collapsed={collapsed}
|
collapsed={collapsed}
|
||||||
accountMenuItems={accountMenu}
|
accountMenuItems={accountMenu}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -5,7 +5,7 @@ import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
|||||||
import { useRegisterForm } from "@/Hooks/useRegisterForm";
|
import { useRegisterForm } from "@/Hooks/useRegisterForm";
|
||||||
import type { RegisterFormData } from "@/Validation/register";
|
import type { RegisterFormData } from "@/Validation/register";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
import { usePost, useGet } from "@/Hooks/UseApi";
|
||||||
import { setAuthState } from "@/Features/Auth/authSlice";
|
import { setAuthState } from "@/Features/Auth/authSlice";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
@@ -32,11 +32,21 @@ const RegisterPage = () => {
|
|||||||
const { post: verifyToken } = usePost<{ token: string }, InviteVerifyResponse>();
|
const { post: verifyToken } = usePost<{ token: string }, InviteVerifyResponse>();
|
||||||
const hasVerified = useRef(false);
|
const hasVerified = useRef(false);
|
||||||
|
|
||||||
|
const { data: superAdminExists, isLoading: isCheckingAdmin } = useGet<boolean>(
|
||||||
|
token ? null : "/auth/users/superadmin"
|
||||||
|
);
|
||||||
|
|
||||||
const { control, handleSubmit, setError, reset } = useForm<RegisterFormData>({
|
const { control, handleSubmit, setError, reset } = useForm<RegisterFormData>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (superAdminExists === true) {
|
||||||
|
navigate("/login", { replace: true });
|
||||||
|
}
|
||||||
|
}, [superAdminExists, navigate]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!token || hasVerified.current) return;
|
if (!token || hasVerified.current) return;
|
||||||
hasVerified.current = true;
|
hasVerified.current = true;
|
||||||
@@ -53,6 +63,8 @@ const RegisterPage = () => {
|
|||||||
});
|
});
|
||||||
}, [token]);
|
}, [token]);
|
||||||
|
|
||||||
|
if (isCheckingAdmin) return null;
|
||||||
|
|
||||||
const onSubmit = async (data: RegisterFormData) => {
|
const onSubmit = async (data: RegisterFormData) => {
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
|
|
||||||
|
|||||||
+21
-18
@@ -11,7 +11,7 @@ import NotFound from "@/Pages/NotFound";
|
|||||||
import AuthLogin from "@/Pages/Auth/Login";
|
import AuthLogin from "@/Pages/Auth/Login";
|
||||||
import AuthRegister from "@/Pages/Auth/Register";
|
import AuthRegister from "@/Pages/Auth/Register";
|
||||||
import AuthForgotPassword from "@/Pages/Auth/Recovery";
|
import AuthForgotPassword from "@/Pages/Auth/Recovery";
|
||||||
import AuthSetNewPassword from "../Pages/Auth/SetNewPassword";
|
import AuthSetNewPassword from "@/Pages/Auth/SetNewPassword";
|
||||||
|
|
||||||
// Uptime
|
// Uptime
|
||||||
import Uptime from "@/Pages/Uptime/Monitors";
|
import Uptime from "@/Pages/Uptime/Monitors";
|
||||||
@@ -23,40 +23,43 @@ import PageSpeedDetails from "@/Pages/PageSpeed/Details/";
|
|||||||
|
|
||||||
// Infrastructure
|
// Infrastructure
|
||||||
import Infrastructure from "@/Pages/Infrastructure/Monitors";
|
import Infrastructure from "@/Pages/Infrastructure/Monitors";
|
||||||
import InfrastructureDetails from "@/Pages/Infrastructure/Details/index";
|
import InfrastructureDetails from "@/Pages/Infrastructure/Details";
|
||||||
|
|
||||||
// Checks
|
// Checks
|
||||||
import Checks from "../Pages/Checks/index";
|
import Checks from "@/Pages/Checks";
|
||||||
|
|
||||||
// Incidents
|
// Incidents
|
||||||
import Incidents from "../Pages/Incidents/";
|
import Incidents from "@/Pages/Incidents";
|
||||||
|
|
||||||
// Status pages
|
// Status pages
|
||||||
import CreateStatus from "../Pages/StatusPage/Create/";
|
import CreateStatus from "@/Pages/StatusPage/Create/";
|
||||||
import StatusPages from "../Pages/StatusPage/StatusPages";
|
import StatusPages from "@/Pages/StatusPage/StatusPages";
|
||||||
import Status from "../Pages/StatusPage/Status";
|
import Status from "@/Pages/StatusPage/Status";
|
||||||
|
|
||||||
import Notifications from "../Pages/Notifications";
|
import Notifications from "@/Pages/Notifications";
|
||||||
import CreateNotifications from "../Pages/Notifications/create";
|
import CreateNotifications from "@/Pages/Notifications/create";
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
import Account from "@/Pages/Account";
|
import Account from "@/Pages/Account";
|
||||||
import EditUser from "../Pages/Account/EditUser";
|
import EditUser from "@/Pages/Account/EditUser";
|
||||||
import Settings from "../Pages/Settings";
|
import Settings from "@/Pages/Settings";
|
||||||
|
|
||||||
import Maintenance from "../Pages/Maintenance";
|
import Maintenance from "@/Pages/Maintenance";
|
||||||
import CreateNewMaintenanceWindow from "@/Pages/Maintenance/create";
|
import CreateNewMaintenanceWindow from "@/Pages/Maintenance/create";
|
||||||
|
|
||||||
import ProtectedRoute from "../Components/v1/ProtectedRoute";
|
// Logs & Diagnostics
|
||||||
import RoleProtectedRoute from "../Components/v1/RoleProtectedRoute";
|
import Logs from "@/Pages/Logs";
|
||||||
import withAdminCheck from "@/Components/v1/HOC/withAdminCheck";
|
|
||||||
import Logs from "../Pages/Logs";
|
// Routing
|
||||||
|
import {
|
||||||
|
ProtectedRoute,
|
||||||
|
RoleProtectedRoute,
|
||||||
|
} from "@/Components/v2/routing/RouteProtected";
|
||||||
|
|
||||||
import CreateMonitor from "@/Pages/CreateMonitor";
|
import CreateMonitor from "@/Pages/CreateMonitor";
|
||||||
|
|
||||||
const Routes = () => {
|
const Routes = () => {
|
||||||
const mode = useSelector((state) => state.ui.mode);
|
const mode = useSelector((state) => state.ui.mode);
|
||||||
const AdminCheckedRegister = withAdminCheck(AuthRegister);
|
|
||||||
const v2theme = mode === "light" ? lightTheme : darkTheme;
|
const v2theme = mode === "light" ? lightTheme : darkTheme;
|
||||||
return (
|
return (
|
||||||
<LibRoutes>
|
<LibRoutes>
|
||||||
@@ -380,7 +383,7 @@ const Routes = () => {
|
|||||||
element={
|
element={
|
||||||
<>
|
<>
|
||||||
<ThemeProvider theme={v2theme}>
|
<ThemeProvider theme={v2theme}>
|
||||||
<AdminCheckedRegister />
|
<AuthRegister />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user