Compare commits
12
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1244ff6d93 | ||
|
|
c0ea804c98 | ||
|
|
c21cf29db6 | ||
|
|
3d0da70ce6 | ||
|
|
feb061240b | ||
|
|
a924227805 | ||
|
|
2144d3f8c0 | ||
|
|
fcd6786149 | ||
|
|
ea968ebf3c | ||
|
|
8a7b852974 | ||
|
|
c8d3e3b70c | ||
|
|
7a90a6f9f4 |
No files matched your search
@@ -3,4 +3,3 @@
|
|||||||
.VSCodeCounter
|
.VSCodeCounter
|
||||||
*.sh
|
*.sh
|
||||||
mongo
|
mongo
|
||||||
node_modules/
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
echo "Running lint-staged..."
|
|
||||||
cd client && npx lint-staged && cd ..
|
|
||||||
cd server && npx lint-staged && cd ..
|
|
||||||
@@ -79,8 +79,9 @@ You can see the memory footprint of MongoDB and Redis on the same server (398Mb
|
|||||||
|
|
||||||
If you have any questions, suggestions or comments, you have several options:
|
If you have any questions, suggestions or comments, you have several options:
|
||||||
|
|
||||||
- [Discord channel](https://discord.gg/NAb6H3UTjK) (preferred)
|
- [Discord channel](https://discord.gg/NAb6H3UTjK)
|
||||||
- [GitHub Discussions](https://github.com/bluewave-labs/bluewave-uptime/discussions) (we check here from time to time)
|
- [GitHub Discussions](https://github.com/bluewave-labs/bluewave-uptime/discussions)
|
||||||
|
- [Reddit group](https://www.reddit.com/r/CheckmateMonitoring/)
|
||||||
|
|
||||||
Feel free to ask questions or share your ideas - we'd love to hear from you!
|
Feel free to ask questions or share your ideas - we'd love to hear from you!
|
||||||
|
|
||||||
|
|||||||
Generated
+1774
-1185
File diff suppressed because it is too large.
Load diff
+7
-12
@@ -12,18 +12,15 @@
|
|||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"format-check": "prettier --check ."
|
"format-check": "prettier --check ."
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
|
||||||
"**/*": "npm run format"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@emotion/react": "^11.13.3",
|
"@emotion/react": "^11.13.3",
|
||||||
"@emotion/styled": "^11.13.0",
|
"@emotion/styled": "^11.13.0",
|
||||||
"@hello-pangea/dnd": "^18.0.0",
|
"@hello-pangea/dnd": "^18.0.0",
|
||||||
"@hookform/resolvers": "5.2.2",
|
"@hookform/resolvers": "5.2.2",
|
||||||
"@mui/lab": "7.0.0",
|
"@mui/lab": "6.0.0-dev.240424162023-9968b4889d",
|
||||||
"@mui/material": "7.3.7",
|
"@mui/material": "6.4.11",
|
||||||
"@mui/x-charts": "7.29.1",
|
"@mui/x-charts": "^7.5.1",
|
||||||
"@mui/x-date-pickers": "7.29.4",
|
"@mui/x-date-pickers": "7.29.0",
|
||||||
"@reduxjs/toolkit": "2.7.0",
|
"@reduxjs/toolkit": "2.7.0",
|
||||||
"axios": "^1.7.4",
|
"axios": "^1.7.4",
|
||||||
"dayjs": "1.11.13",
|
"dayjs": "1.11.13",
|
||||||
@@ -33,12 +30,11 @@
|
|||||||
"i18next": "25.4.2",
|
"i18next": "25.4.2",
|
||||||
"joi": "17.13.3",
|
"joi": "17.13.3",
|
||||||
"lucide-react": "^0.562.0",
|
"lucide-react": "^0.562.0",
|
||||||
"mui-color-input": "^7.0.0",
|
"mui-color-input": "^6.0.0",
|
||||||
"pretty-bytes": "^7.1.0",
|
|
||||||
"pretty-ms": "^9.3.0",
|
"pretty-ms": "^9.3.0",
|
||||||
"react": "18.3.1",
|
"react": "18.3.1",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-hook-form": "^7.63.0",
|
"react-hook-form": "7.63.0",
|
||||||
"react-i18next": "^15.4.0",
|
"react-i18next": "^15.4.0",
|
||||||
"react-icons": "5.5.0",
|
"react-icons": "5.5.0",
|
||||||
"react-redux": "9.2.0",
|
"react-redux": "9.2.0",
|
||||||
@@ -49,7 +45,7 @@
|
|||||||
"redux-persist": "6.0.0",
|
"redux-persist": "6.0.0",
|
||||||
"swr": "^2.3.6",
|
"swr": "^2.3.6",
|
||||||
"vite-plugin-svgr": "^4.2.0",
|
"vite-plugin-svgr": "^4.2.0",
|
||||||
"zod": "^4.1.11"
|
"zod": "4.1.11"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "24.5.2",
|
"@types/node": "24.5.2",
|
||||||
@@ -60,7 +56,6 @@
|
|||||||
"eslint-plugin-react": "^7.34.1",
|
"eslint-plugin-react": "^7.34.1",
|
||||||
"eslint-plugin-react-hooks": "^5.0.0",
|
"eslint-plugin-react-hooks": "^5.0.0",
|
||||||
"eslint-plugin-react-refresh": "^0.4.6",
|
"eslint-plugin-react-refresh": "^0.4.6",
|
||||||
"lint-staged": "^16.2.7",
|
|
||||||
"prettier": "^3.3.3",
|
"prettier": "^3.3.3",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"vite": "6.3.6"
|
"vite": "6.3.6"
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import { Checkbox, FormControl, ListItemText, MenuItem, Select } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import Icon from "../Icon";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A reusable filter header component that displays a dropdown menu with selectable options.
|
||||||
|
*
|
||||||
|
* @component
|
||||||
|
* @param {Object} props - The component props.
|
||||||
|
* @param {string} props.header - The header text to display when no options are selected.
|
||||||
|
* @param {Array} props.options - An array of options to display in the dropdown menu. Each option should have a `value` and `label`.
|
||||||
|
* @param {Array} [props.value] - The currently selected values.
|
||||||
|
* @param {Function} props.onChange - The callback function to handle changes in the selected values.
|
||||||
|
* @param {boolean} [props.multiple=true] - Whether multiple options can be selected.
|
||||||
|
* @returns {JSX.Element} The rendered FilterHeader component.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const FilterHeader = ({ header, options, value, onChange, multiple = true }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const controlledValue = value === undefined ? [] : value; // Ensure value is always treated as an array for controlled component purposes
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormControl
|
||||||
|
sx={{ minWidth: "10%" }}
|
||||||
|
size="small"
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
multiple={multiple}
|
||||||
|
IconComponent={(props) => (
|
||||||
|
<Icon
|
||||||
|
{...props}
|
||||||
|
name="PlusCircle"
|
||||||
|
size={18}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
displayEmpty
|
||||||
|
value={controlledValue}
|
||||||
|
onChange={onChange}
|
||||||
|
renderValue={(selected) => {
|
||||||
|
if (!selected?.length) {
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
header +
|
||||||
|
" | " +
|
||||||
|
selected
|
||||||
|
.map((value) => options.find((option) => option.value === value)?.label)
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(", ")
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
MenuProps={{
|
||||||
|
anchorOrigin: {
|
||||||
|
vertical: "bottom",
|
||||||
|
horizontal: "left",
|
||||||
|
},
|
||||||
|
transformOrigin: {
|
||||||
|
vertical: "top",
|
||||||
|
horizontal: "left",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{options.map((option) => (
|
||||||
|
<MenuItem
|
||||||
|
key={option.value}
|
||||||
|
value={option.value}
|
||||||
|
sx={{
|
||||||
|
height: theme.spacing(17),
|
||||||
|
padding: 0,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Checkbox
|
||||||
|
checked={controlledValue.includes(option.value)}
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
<ListItemText primary={option.label} />
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
FilterHeader.propTypes = {
|
||||||
|
header: PropTypes.string.isRequired,
|
||||||
|
options: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({
|
||||||
|
value: PropTypes.string.isRequired,
|
||||||
|
label: PropTypes.string.isRequired,
|
||||||
|
})
|
||||||
|
).isRequired,
|
||||||
|
value: PropTypes.arrayOf(PropTypes.string),
|
||||||
|
onChange: PropTypes.func.isRequired,
|
||||||
|
multiple: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FilterHeader;
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import ButtonGroup from "@mui/material/ButtonGroup";
|
||||||
|
import Icon from "../Icon";
|
||||||
|
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
||||||
|
import Grow from "@mui/material/Grow";
|
||||||
|
import Paper from "@mui/material/Paper";
|
||||||
|
import Popper from "@mui/material/Popper";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import MenuList from "@mui/material/MenuList";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { createToast } from "../../../Utils/toastUtils.jsx";
|
||||||
|
import { useExportMonitors } from "../../../Hooks/monitorHooks.js";
|
||||||
|
|
||||||
|
const MonitorActions = ({ isLoading }) => {
|
||||||
|
const [open, setOpen] = React.useState(false);
|
||||||
|
const anchorRef = React.useRef(null);
|
||||||
|
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [exportMonitors, isExporting] = useExportMonitors();
|
||||||
|
|
||||||
|
const options = [t("monitorActions.import"), t("monitorActions.export")];
|
||||||
|
|
||||||
|
const handleClick = async () => {
|
||||||
|
if (selectedIndex === 0) {
|
||||||
|
// Import
|
||||||
|
navigate("/uptime/bulk-import");
|
||||||
|
} else {
|
||||||
|
// Export
|
||||||
|
const [success, error] = await exportMonitors();
|
||||||
|
if (!success) {
|
||||||
|
createToast({ body: error || t("export.failed") });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleMenuItemClick = (event, index) => {
|
||||||
|
setSelectedIndex(index);
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggle = () => {
|
||||||
|
setOpen((prevOpen) => !prevOpen);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = (event) => {
|
||||||
|
if (anchorRef.current && anchorRef.current.contains(event.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<ButtonGroup
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
ref={anchorRef}
|
||||||
|
aria-label="Monitor actions"
|
||||||
|
disabled={isLoading || isExporting}
|
||||||
|
>
|
||||||
|
<Button onClick={handleClick}>{options[selectedIndex]}</Button>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
aria-controls={open ? "split-button-menu" : undefined}
|
||||||
|
aria-expanded={open ? "true" : undefined}
|
||||||
|
aria-label="select monitor action"
|
||||||
|
aria-haspopup="menu"
|
||||||
|
onClick={handleToggle}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="ChevronDown"
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
<Popper
|
||||||
|
sx={{ zIndex: 1 }}
|
||||||
|
open={open}
|
||||||
|
anchorEl={anchorRef.current}
|
||||||
|
role={undefined}
|
||||||
|
transition
|
||||||
|
disablePortal
|
||||||
|
>
|
||||||
|
{({ TransitionProps, placement }) => (
|
||||||
|
<Grow
|
||||||
|
{...TransitionProps}
|
||||||
|
style={{
|
||||||
|
transformOrigin: placement === "bottom" ? "center top" : "center bottom",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Paper>
|
||||||
|
<ClickAwayListener onClickAway={handleClose}>
|
||||||
|
<MenuList
|
||||||
|
id="split-button-menu"
|
||||||
|
autoFocusItem
|
||||||
|
>
|
||||||
|
{options.map((option, index) => (
|
||||||
|
<MenuItem
|
||||||
|
key={option}
|
||||||
|
selected={index === selectedIndex}
|
||||||
|
onClick={(event) => handleMenuItemClick(event, index)}
|
||||||
|
>
|
||||||
|
{option}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</MenuList>
|
||||||
|
</ClickAwayListener>
|
||||||
|
</Paper>
|
||||||
|
</Grow>
|
||||||
|
)}
|
||||||
|
</Popper>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MonitorActions;
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { Stack, Typography } from "@mui/material";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import SkeletonLayout from "./skeleton.jsx";
|
||||||
|
|
||||||
|
const MonitorCountHeader = ({
|
||||||
|
isLoading = false,
|
||||||
|
monitorCount,
|
||||||
|
heading = "monitors",
|
||||||
|
sx,
|
||||||
|
children,
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
if (isLoading) return <SkeletonLayout />;
|
||||||
|
|
||||||
|
if (monitorCount === 1) {
|
||||||
|
heading = "monitor";
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
display="flex"
|
||||||
|
width="fit-content"
|
||||||
|
height={theme.spacing(18)}
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
mt={theme.spacing(2)}
|
||||||
|
px={theme.spacing(4)}
|
||||||
|
pt={theme.spacing(2)}
|
||||||
|
pb={theme.spacing(3)}
|
||||||
|
borderRadius={theme.spacing(1)}
|
||||||
|
sx={{
|
||||||
|
...sx,
|
||||||
|
backgroundColor: theme.palette.secondary.main,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{monitorCount} <Typography component="h2">{heading}</Typography>
|
||||||
|
{children}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
MonitorCountHeader.propTypes = {
|
||||||
|
isLoading: PropTypes.bool,
|
||||||
|
monitorCount: PropTypes.number,
|
||||||
|
heading: PropTypes.string,
|
||||||
|
children: PropTypes.node,
|
||||||
|
sx: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MonitorCountHeader;
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { Stack, Skeleton } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
<Skeleton
|
||||||
|
variant="text"
|
||||||
|
width={100}
|
||||||
|
height={32}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="circular"
|
||||||
|
width={40}
|
||||||
|
height={40}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SkeletonLayout;
|
||||||
@@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
|
import MonitorActions from "../MonitorActions/index.jsx";
|
||||||
|
|
||||||
const CreateMonitorHeader = ({ isAdmin, label, isLoading = true, path, bulkPath }) => {
|
const CreateMonitorHeader = ({ isAdmin, label, isLoading = true, path, bulkPath }) => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|||||||
@@ -0,0 +1,158 @@
|
|||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Status from "./status.jsx";
|
||||||
|
import Skeleton from "./skeleton.jsx";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import { Tooltip } from "@mui/material";
|
||||||
|
import Icon from "../Icon";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { usePauseMonitor } from "../../../Hooks/monitorHooks.js";
|
||||||
|
import { useSendTestEmail } from "../../../Hooks/useSendTestEmail.js";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useTestAllNotifications } from "../../../Hooks/useNotifications.js";
|
||||||
|
/**
|
||||||
|
* MonitorDetailsControlHeader component displays the control header for monitor details.
|
||||||
|
* It includes status display, pause/resume button, and a configure button for admins.
|
||||||
|
*
|
||||||
|
* @component
|
||||||
|
* @param {Object} props - Component props
|
||||||
|
* @param {string} props.path - The base path for navigation
|
||||||
|
* @param {boolean} [props.isLoading=false] - Flag indicating if the data is loading
|
||||||
|
* @param {boolean} [props.isAdmin=false] - Flag indicating if the user is an admin
|
||||||
|
* @param {Object} props.monitor - The monitor object containing details
|
||||||
|
* @param {Function} props.triggerUpdate - Function to trigger an update
|
||||||
|
* @returns {JSX.Element} The rendered component
|
||||||
|
*/
|
||||||
|
const MonitorDetailsControlHeader = ({
|
||||||
|
path,
|
||||||
|
isLoading = false,
|
||||||
|
isAdmin = false,
|
||||||
|
monitor,
|
||||||
|
triggerUpdate,
|
||||||
|
}) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [pauseMonitor, isPausing, error] = usePauseMonitor();
|
||||||
|
|
||||||
|
const isTestNotificationsDisabled = monitor?.notifications?.length === 0;
|
||||||
|
|
||||||
|
const tooltipTitle = isTestNotificationsDisabled ? t("testNotificationsDisabled") : "";
|
||||||
|
|
||||||
|
// const [isSending, emailError, sendTestEmail] = useSendTestEmail();
|
||||||
|
|
||||||
|
const [testAllNotifications, isSending, errorAllNotifications] =
|
||||||
|
useTestAllNotifications();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <Skeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<Status monitor={monitor} />
|
||||||
|
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
<Tooltip
|
||||||
|
key={monitor?.id}
|
||||||
|
placement="bottom"
|
||||||
|
title={tooltipTitle}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
loading={isSending}
|
||||||
|
startIcon={
|
||||||
|
<Icon
|
||||||
|
name="Mail"
|
||||||
|
size={18}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
disabled={isTestNotificationsDisabled}
|
||||||
|
onClick={() => {
|
||||||
|
testAllNotifications({ monitorId: monitor?.id });
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("sendTestNotifications")}
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
</Tooltip>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
onClick={(e) => {
|
||||||
|
navigate(`/incidents/${monitor?.id}`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("menu.incidents")}
|
||||||
|
</Button>
|
||||||
|
{isAdmin && (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
loading={isPausing}
|
||||||
|
startIcon={
|
||||||
|
monitor?.isActive ? (
|
||||||
|
<Icon
|
||||||
|
name="Pause"
|
||||||
|
size={18}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<Icon
|
||||||
|
name="Play"
|
||||||
|
size={18}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
pauseMonitor({
|
||||||
|
monitorId: monitor?.id,
|
||||||
|
triggerUpdate,
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{monitor?.isActive ? t("pause") : t("resume")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
{isAdmin && (
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
startIcon={
|
||||||
|
<Icon
|
||||||
|
name="Settings"
|
||||||
|
size={18}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
|
||||||
|
>
|
||||||
|
Configure
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
MonitorDetailsControlHeader.propTypes = {
|
||||||
|
path: PropTypes.string,
|
||||||
|
isLoading: PropTypes.bool,
|
||||||
|
isAdmin: PropTypes.bool,
|
||||||
|
monitor: PropTypes.object,
|
||||||
|
triggerUpdate: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MonitorDetailsControlHeader;
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { Stack, Skeleton } from "@mui/material";
|
||||||
|
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<Skeleton
|
||||||
|
height={40}
|
||||||
|
variant="rounded"
|
||||||
|
width="15%"
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
height={40}
|
||||||
|
variant="rounded"
|
||||||
|
width="15%"
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SkeletonLayout;
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
// Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import PulseDot from "../Animated/PulseDot.jsx";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Dot from "../Dot/index.jsx";
|
||||||
|
// Utils
|
||||||
|
import { formatDurationRounded } from "../../../Utils/timeUtilsLegacy.js";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils.js";
|
||||||
|
import { formatMonitorUrl } from "../../../Utils/utils.js";
|
||||||
|
/**
|
||||||
|
* Status component displays the status information of a monitor.
|
||||||
|
* It includes the monitor's name, URL, and check interval.
|
||||||
|
*
|
||||||
|
* @component
|
||||||
|
* @param {Object} props - Component props
|
||||||
|
* @param {Object} props.monitor - The monitor object containing details
|
||||||
|
* @param {string} props.monitor.name - The name of the monitor
|
||||||
|
* @param {string} props.monitor.url - The URL of the monitor
|
||||||
|
* @param {number} props.monitor.interval - The interval at which the monitor checks
|
||||||
|
* @returns {JSX.Element} The rendered component
|
||||||
|
*/
|
||||||
|
const Status = ({ monitor }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { statusColor, determineState } = useMonitorUtils();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Typography variant="monitorName">{monitor?.name}</Typography>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems={"center"}
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<PulseDot color={statusColor[determineState(monitor)]} />
|
||||||
|
<Typography variant="monitorUrl">{formatMonitorUrl(monitor?.url)}</Typography>
|
||||||
|
<Dot />
|
||||||
|
<Typography>
|
||||||
|
Checking every {formatDurationRounded(monitor?.interval)}.
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Status.propTypes = {
|
||||||
|
monitor: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Status;
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
// Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import Divider from "@mui/material/Divider";
|
||||||
|
import Icon from "../Icon";
|
||||||
|
import Search from "../Inputs/Search/index.jsx";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const NotificationConfig = ({
|
||||||
|
notifications,
|
||||||
|
setMonitor,
|
||||||
|
setNotifications,
|
||||||
|
//FieldWrapper's props
|
||||||
|
gap,
|
||||||
|
labelMb,
|
||||||
|
labelFontWeight,
|
||||||
|
labelVariant,
|
||||||
|
labelSx = {},
|
||||||
|
sx = {},
|
||||||
|
}) => {
|
||||||
|
// Local state
|
||||||
|
const [notificationsSearch, setNotificationsSearch] = useState("");
|
||||||
|
const [selectedNotifications, setSelectedNotifications] = useState([]);
|
||||||
|
|
||||||
|
const handleSearch = (value) => {
|
||||||
|
setSelectedNotifications(value);
|
||||||
|
setMonitor((prev) => {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
notifications: value.map((notification) => notification.id),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
const handleDelete = (id) => {
|
||||||
|
const updatedNotifications = selectedNotifications.filter(
|
||||||
|
(notification) => notification.id !== id
|
||||||
|
);
|
||||||
|
|
||||||
|
setSelectedNotifications(updatedNotifications);
|
||||||
|
setMonitor((prev) => {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
notifications: updatedNotifications.map((notification) => notification.id),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (setNotifications) {
|
||||||
|
const toSet = setNotifications.map((notification) => {
|
||||||
|
return notifications.find((n) => n.id === notification);
|
||||||
|
});
|
||||||
|
setSelectedNotifications(toSet);
|
||||||
|
}
|
||||||
|
}, [setNotifications, notifications]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.spacing(6)}>
|
||||||
|
<Search
|
||||||
|
type="notifications"
|
||||||
|
label="Notifications"
|
||||||
|
options={notifications}
|
||||||
|
filteredBy="notificationName"
|
||||||
|
multiple={true}
|
||||||
|
value={selectedNotifications}
|
||||||
|
inputValue={notificationsSearch}
|
||||||
|
handleInputChange={setNotificationsSearch}
|
||||||
|
handleChange={(value) => {
|
||||||
|
handleSearch(value);
|
||||||
|
}}
|
||||||
|
labelMb={labelMb}
|
||||||
|
labelVariant={labelVariant}
|
||||||
|
labelFontWeight={labelFontWeight}
|
||||||
|
labelSx={labelSx}
|
||||||
|
gap={gap}
|
||||||
|
sx={{
|
||||||
|
...sx,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Stack
|
||||||
|
flex={1}
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
{selectedNotifications.map((notification, index) => (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
key={notification.id}
|
||||||
|
width="100%"
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
flexGrow={1} // <-- This will take up all available horizontal space
|
||||||
|
>
|
||||||
|
{notification.notificationName}
|
||||||
|
</Typography>
|
||||||
|
<Icon
|
||||||
|
name="Trash2"
|
||||||
|
size={20}
|
||||||
|
onClick={() => {
|
||||||
|
handleDelete(notification.id);
|
||||||
|
}}
|
||||||
|
style={{ cursor: "pointer" }}
|
||||||
|
/>
|
||||||
|
{index < selectedNotifications.length - 1 && <Divider />}
|
||||||
|
</Stack>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationConfig.propTypes = {
|
||||||
|
notifications: PropTypes.array,
|
||||||
|
setMonitor: PropTypes.func,
|
||||||
|
setNotifications: PropTypes.array,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NotificationConfig;
|
||||||
+419
@@ -0,0 +1,419 @@
|
|||||||
|
import { useState, useMemo, useEffect, useCallback } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogContent,
|
||||||
|
DialogActions,
|
||||||
|
Button,
|
||||||
|
Typography,
|
||||||
|
Box,
|
||||||
|
Tabs,
|
||||||
|
Tab,
|
||||||
|
Stack,
|
||||||
|
} from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import TabPanel from "./TabPanel.jsx";
|
||||||
|
import TabComponent from "./TabComponent.jsx";
|
||||||
|
import useNotifications from "../Hooks/useNotification.js";
|
||||||
|
|
||||||
|
// Define constants for notification types to avoid magic values
|
||||||
|
const NOTIFICATION_TYPES = {
|
||||||
|
SLACK: "slack",
|
||||||
|
DISCORD: "discord",
|
||||||
|
TELEGRAM: "telegram",
|
||||||
|
WEBHOOK: "webhook",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define constants for field IDs
|
||||||
|
const FIELD_IDS = {
|
||||||
|
WEBHOOK: "webhook",
|
||||||
|
TOKEN: "token",
|
||||||
|
CHAT_ID: "chatId",
|
||||||
|
URL: "url",
|
||||||
|
};
|
||||||
|
|
||||||
|
const NotificationIntegrationModal = ({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
monitor,
|
||||||
|
setMonitor,
|
||||||
|
// Optional prop to configure available notification types
|
||||||
|
notificationTypes = null,
|
||||||
|
}) => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const [tabValue, setTabValue] = useState(0);
|
||||||
|
|
||||||
|
const [loading, _, sendTestNotification] = useNotifications();
|
||||||
|
|
||||||
|
// Helper to get the field state key with error handling
|
||||||
|
const getFieldKey = useCallback(
|
||||||
|
(typeId, fieldId) => {
|
||||||
|
if (typeof typeId !== "string" || typeId === "") {
|
||||||
|
throw new Error(t("errorInvalidTypeId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof fieldId !== "string" || fieldId === "") {
|
||||||
|
throw new Error(t("errorInvalidFieldId"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${typeId}${fieldId.charAt(0).toUpperCase() + fieldId.slice(1)}`;
|
||||||
|
},
|
||||||
|
[t]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Define notification types
|
||||||
|
const DEFAULT_NOTIFICATION_TYPES = [
|
||||||
|
{
|
||||||
|
id: NOTIFICATION_TYPES.SLACK,
|
||||||
|
label: t("notifications.slack.label"),
|
||||||
|
description: t("notifications.slack.description"),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: FIELD_IDS.WEBHOOK,
|
||||||
|
label: t("notifications.slack.webhookLabel"),
|
||||||
|
placeholder: t("notifications.slack.webhookPlaceholder"),
|
||||||
|
type: "text",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: NOTIFICATION_TYPES.DISCORD,
|
||||||
|
label: t("notifications.discord.label"),
|
||||||
|
description: t("notifications.discord.description"),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: FIELD_IDS.WEBHOOK,
|
||||||
|
label: t("notifications.discord.webhookLabel"),
|
||||||
|
placeholder: t("notifications.discord.webhookPlaceholder"),
|
||||||
|
type: "text",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: NOTIFICATION_TYPES.TELEGRAM,
|
||||||
|
label: t("notifications.telegram.label"),
|
||||||
|
description: t("notifications.telegram.description"),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: FIELD_IDS.TOKEN,
|
||||||
|
label: t("notifications.telegram.tokenLabel"),
|
||||||
|
placeholder: t("notifications.telegram.tokenPlaceholder"),
|
||||||
|
type: "text",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: FIELD_IDS.CHAT_ID,
|
||||||
|
label: t("notifications.telegram.chatIdLabel"),
|
||||||
|
placeholder: t("notifications.telegram.chatIdPlaceholder"),
|
||||||
|
type: "text",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: NOTIFICATION_TYPES.WEBHOOK,
|
||||||
|
label: t("notifications.webhook.label"),
|
||||||
|
description: t("notifications.webhook.description"),
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
id: FIELD_IDS.URL,
|
||||||
|
label: t("notifications.webhook.urlLabel"),
|
||||||
|
placeholder: t("notifications.webhook.urlPlaceholder"),
|
||||||
|
type: "text",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
// Use provided notification types or default to our translated ones
|
||||||
|
const activeNotificationTypes = notificationTypes || DEFAULT_NOTIFICATION_TYPES;
|
||||||
|
|
||||||
|
// Memoized function to initialize integrations state
|
||||||
|
const initialIntegrationsState = useMemo(() => {
|
||||||
|
const state = {};
|
||||||
|
|
||||||
|
activeNotificationTypes.forEach((type) => {
|
||||||
|
// Add enabled flag for each notification type
|
||||||
|
state[type.id] = false;
|
||||||
|
|
||||||
|
// Add state for each field in the notification type
|
||||||
|
type.fields.forEach((field) => {
|
||||||
|
const fieldKey = getFieldKey(type.id, field.id);
|
||||||
|
state[fieldKey] = "";
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return state;
|
||||||
|
}, [activeNotificationTypes, getFieldKey]); // Only recompute when these dependencies change
|
||||||
|
|
||||||
|
const [integrations, setIntegrations] = useState(initialIntegrationsState);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
const extractNotificationValues = () => {
|
||||||
|
const values = {};
|
||||||
|
|
||||||
|
if (!monitor?.notifications || !Array.isArray(monitor.notifications)) {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
|
monitor.notifications.forEach((notification) => {
|
||||||
|
// Handle notification based on its structure
|
||||||
|
if (notification.type === "webhook" && notification.platform) {
|
||||||
|
if (typeof notification.config === "undefined") return;
|
||||||
|
const platform = notification.platform;
|
||||||
|
values[platform] = true; // Set platform as enabled
|
||||||
|
|
||||||
|
// Extract configuration based on platform
|
||||||
|
switch (platform) {
|
||||||
|
case NOTIFICATION_TYPES.SLACK:
|
||||||
|
case NOTIFICATION_TYPES.DISCORD:
|
||||||
|
if (notification.config.webhookUrl) {
|
||||||
|
values[getFieldKey(platform, FIELD_IDS.WEBHOOK)] =
|
||||||
|
notification.config.webhookUrl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NOTIFICATION_TYPES.TELEGRAM:
|
||||||
|
if (notification.config.botToken) {
|
||||||
|
values[getFieldKey(platform, FIELD_IDS.TOKEN)] =
|
||||||
|
notification.config.botToken;
|
||||||
|
}
|
||||||
|
if (notification.config.chatId) {
|
||||||
|
values[getFieldKey(platform, FIELD_IDS.CHAT_ID)] =
|
||||||
|
notification.config.chatId;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NOTIFICATION_TYPES.WEBHOOK:
|
||||||
|
if (notification.config.webhookUrl) {
|
||||||
|
values[getFieldKey(platform, FIELD_IDS.URL)] =
|
||||||
|
notification.config.webhookUrl;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return values;
|
||||||
|
};
|
||||||
|
|
||||||
|
const extractedValues = extractNotificationValues();
|
||||||
|
setIntegrations((prev) => ({
|
||||||
|
...prev,
|
||||||
|
...extractedValues,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [open, monitor, getFieldKey]);
|
||||||
|
|
||||||
|
const handleChangeTab = (event, newValue) => {
|
||||||
|
setTabValue(newValue);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleIntegrationChange = (type, checked) => {
|
||||||
|
setIntegrations((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[type]: checked,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleInputChange = (type, value) => {
|
||||||
|
setIntegrations((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[type]: value,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleTestNotification = async (type) => {
|
||||||
|
// Get the notification type details
|
||||||
|
const notificationType = activeNotificationTypes.find((t) => t.id === type);
|
||||||
|
|
||||||
|
if (typeof notificationType === "undefined") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare config object based on notification type
|
||||||
|
const config = {};
|
||||||
|
|
||||||
|
// Add each field value to the config object
|
||||||
|
notificationType.fields.forEach((field) => {
|
||||||
|
const fieldKey = getFieldKey(type, field.id);
|
||||||
|
config[field.id] = integrations[fieldKey];
|
||||||
|
});
|
||||||
|
|
||||||
|
await sendTestNotification(type, config);
|
||||||
|
};
|
||||||
|
|
||||||
|
// In NotificationIntegrationModal.jsx, update the handleSave function:
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
// Get existing notifications
|
||||||
|
const notifications = [...(monitor?.notifications || [])];
|
||||||
|
|
||||||
|
// Get all notification types IDs
|
||||||
|
const existingTypes = activeNotificationTypes.map((type) => type.id);
|
||||||
|
|
||||||
|
// Filter out notifications that are configurable in this modal
|
||||||
|
const filteredNotifications = notifications.filter((notification) => {
|
||||||
|
if (notification.platform) {
|
||||||
|
return !existingTypes.includes(notification.platform);
|
||||||
|
}
|
||||||
|
|
||||||
|
return !existingTypes.includes(notification.type);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add each enabled notification with its configured fields
|
||||||
|
activeNotificationTypes.forEach((type) => {
|
||||||
|
if (integrations[type.id]) {
|
||||||
|
let notificationObject = {
|
||||||
|
type: "webhook",
|
||||||
|
platform: type.id, // Set platform to identify the specific service
|
||||||
|
config: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Configure based on notification type
|
||||||
|
switch (type.id) {
|
||||||
|
case "slack":
|
||||||
|
case "discord":
|
||||||
|
notificationObject.config.webhookUrl =
|
||||||
|
integrations[getFieldKey(type.id, "webhook")];
|
||||||
|
break;
|
||||||
|
case "telegram":
|
||||||
|
notificationObject.config.botToken =
|
||||||
|
integrations[getFieldKey(type.id, "token")];
|
||||||
|
notificationObject.config.chatId =
|
||||||
|
integrations[getFieldKey(type.id, "chatId")];
|
||||||
|
break;
|
||||||
|
case "webhook":
|
||||||
|
notificationObject.config.webhookUrl =
|
||||||
|
integrations[getFieldKey(type.id, "url")];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredNotifications.push(notificationObject);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Update monitor with new notifications
|
||||||
|
setMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
|
notifications: filteredNotifications,
|
||||||
|
}));
|
||||||
|
|
||||||
|
onClose();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
open={open}
|
||||||
|
onClose={onClose}
|
||||||
|
fullWidth
|
||||||
|
maxWidth="md"
|
||||||
|
sx={{
|
||||||
|
"& .MuiDialog-paper": {
|
||||||
|
width: `calc(80% - ${theme.spacing(40)})`,
|
||||||
|
maxWidth: `${theme.breakpoints.values.md - 70}px`,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DialogContent>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
sx={{
|
||||||
|
height: `calc(30vh - ${theme.spacing(20)})`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{/* Left sidebar with tabs */}
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
borderRight: 1,
|
||||||
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
|
width: "30%",
|
||||||
|
maxWidth: theme.spacing(120),
|
||||||
|
pr: theme.spacing(10),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="h2">
|
||||||
|
{t("notifications.addOrEditNotifications")}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Tabs
|
||||||
|
orientation="vertical"
|
||||||
|
variant="scrollable"
|
||||||
|
value={tabValue}
|
||||||
|
onChange={handleChangeTab}
|
||||||
|
aria-label="Notification tabs"
|
||||||
|
>
|
||||||
|
{activeNotificationTypes.map((type) => (
|
||||||
|
<Tab
|
||||||
|
key={type.id}
|
||||||
|
label={type.label}
|
||||||
|
orientation="vertical"
|
||||||
|
disableRipple
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Tabs>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{/* Right side content */}
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
flex: 1,
|
||||||
|
pl: theme.spacing(7.5),
|
||||||
|
overflowY: "auto",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{activeNotificationTypes.map((type, index) => (
|
||||||
|
<TabPanel
|
||||||
|
key={type.id}
|
||||||
|
value={tabValue}
|
||||||
|
index={index}
|
||||||
|
>
|
||||||
|
<TabComponent
|
||||||
|
type={type}
|
||||||
|
integrations={integrations}
|
||||||
|
handleIntegrationChange={handleIntegrationChange}
|
||||||
|
handleInputChange={handleInputChange}
|
||||||
|
handleTestNotification={handleTestNotification}
|
||||||
|
isLoading={loading}
|
||||||
|
/>
|
||||||
|
</TabPanel>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</DialogContent>
|
||||||
|
<DialogActions
|
||||||
|
sx={{
|
||||||
|
p: theme.spacing(4),
|
||||||
|
display: "flex",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
mb: theme.spacing(5),
|
||||||
|
mr: theme.spacing(5),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
onClick={handleSave}
|
||||||
|
loading={loading}
|
||||||
|
sx={{
|
||||||
|
width: "auto",
|
||||||
|
minWidth: theme.spacing(60),
|
||||||
|
px: theme.spacing(8),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("commonSave")}
|
||||||
|
</Button>
|
||||||
|
</DialogActions>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationIntegrationModal.propTypes = {
|
||||||
|
open: PropTypes.bool.isRequired,
|
||||||
|
onClose: PropTypes.func.isRequired,
|
||||||
|
monitor: PropTypes.object.isRequired,
|
||||||
|
setMonitor: PropTypes.func.isRequired,
|
||||||
|
notificationTypes: PropTypes.array,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NotificationIntegrationModal;
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Typography, Box, Button, CircularProgress } from "@mui/material";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import TextInput from "../../Inputs/TextInput/index.jsx";
|
||||||
|
import Checkbox from "../../Inputs/Checkbox/index.jsx";
|
||||||
|
|
||||||
|
const TabComponent = ({
|
||||||
|
type,
|
||||||
|
integrations,
|
||||||
|
handleIntegrationChange,
|
||||||
|
handleInputChange,
|
||||||
|
handleTestNotification,
|
||||||
|
isLoading,
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// Helper to get the field state key (e.g., slackWebhook, telegramToken)
|
||||||
|
const getFieldKey = (typeId, fieldId) => {
|
||||||
|
return `${typeId}${fieldId.charAt(0).toUpperCase() + fieldId.slice(1)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Check if all fields have values to enable test button
|
||||||
|
const areAllFieldsFilled = () => {
|
||||||
|
return type.fields.every((field) => {
|
||||||
|
const fieldKey = getFieldKey(type.id, field.id);
|
||||||
|
return integrations[fieldKey];
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle1"
|
||||||
|
component="h4"
|
||||||
|
sx={{
|
||||||
|
fontWeight: "bold",
|
||||||
|
color: theme.palette.primary.contrastTextSecondary,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{type.label}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
mt: theme.spacing(0.5),
|
||||||
|
mb: theme.spacing(1.5),
|
||||||
|
color: theme.palette.primary.contrastTextTertiary,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{type.description}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Box sx={{ pl: theme.spacing(1.5) }}>
|
||||||
|
<Checkbox
|
||||||
|
id={`enable-${type.id}`}
|
||||||
|
label={t("notifications.enableNotifications", { platform: type.label })}
|
||||||
|
isChecked={integrations[type.id]}
|
||||||
|
onChange={(e) => handleIntegrationChange(type.id, e.target.checked)}
|
||||||
|
disabled={isLoading}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{type.fields.map((field) => {
|
||||||
|
const fieldKey = getFieldKey(type.id, field.id);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
key={field.id}
|
||||||
|
sx={{ mt: theme.spacing(1) }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
mb: theme.spacing(2),
|
||||||
|
fontWeight: "bold",
|
||||||
|
color: theme.palette.primary.contrastTextSecondary,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{field.label}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<TextInput
|
||||||
|
id={`${type.id}-${field.id}`}
|
||||||
|
type={field.type}
|
||||||
|
placeholder={field.placeholder}
|
||||||
|
value={integrations[fieldKey]}
|
||||||
|
onChange={(e) => handleInputChange(fieldKey, e.target.value)}
|
||||||
|
disabled={!integrations[type.id] || isLoading}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
<Box sx={{ mt: theme.spacing(1) }}>
|
||||||
|
<Button
|
||||||
|
variant="text"
|
||||||
|
color="info"
|
||||||
|
onClick={() => handleTestNotification(type.id)}
|
||||||
|
disabled={!integrations[type.id] || !areAllFieldsFilled() || isLoading}
|
||||||
|
>
|
||||||
|
{isLoading ? (
|
||||||
|
<CircularProgress
|
||||||
|
size={theme.spacing(8)}
|
||||||
|
sx={{ mr: theme.spacing(1), color: theme.palette.accent.main }}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{t("notifications.testNotification")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TabComponent;
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import React from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { Box } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TabPanel component that displays content for the selected tab.
|
||||||
|
*
|
||||||
|
* @component
|
||||||
|
* @param {Object} props - The component props.
|
||||||
|
* @param {React.ReactNode} props.children - The content to be displayed when this tab panel is selected.
|
||||||
|
* @param {number} props.value - The currently selected tab value.
|
||||||
|
* @param {number} props.index - The index of this specific tab panel.
|
||||||
|
* @param {Object} props.other - Any additional props to be spread to the root element.
|
||||||
|
* @returns {React.ReactElement|null} The rendered tab panel or null if not selected.
|
||||||
|
*/
|
||||||
|
function TabPanel({ children, value, index, ...other }) {
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="tabpanel"
|
||||||
|
hidden={value !== index}
|
||||||
|
id={`notification-tabpanel-${index}`}
|
||||||
|
aria-labelledby={`notification-tab-${index}`}
|
||||||
|
{...other}
|
||||||
|
>
|
||||||
|
{value === index && <Box sx={{ pt: theme.spacing(3) }}>{children}</Box>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
TabPanel.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
|
||||||
|
index: PropTypes.number.isRequired,
|
||||||
|
|
||||||
|
value: PropTypes.number.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TabPanel;
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { networkService } from "../../../../Utils/NetworkService.js";
|
||||||
|
import { createToast } from "../../../../Utils/toastUtils.jsx";
|
||||||
|
|
||||||
|
// Define constants for notification types to avoid magic values
|
||||||
|
const NOTIFICATION_TYPES = {
|
||||||
|
SLACK: "slack",
|
||||||
|
DISCORD: "discord",
|
||||||
|
TELEGRAM: "telegram",
|
||||||
|
WEBHOOK: "webhook",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Define constants for field IDs
|
||||||
|
const FIELD_IDS = {
|
||||||
|
WEBHOOK: "webhook",
|
||||||
|
TOKEN: "token",
|
||||||
|
CHAT_ID: "chatId",
|
||||||
|
URL: "url",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom hook for notification-related operations
|
||||||
|
*/
|
||||||
|
const useNotifications = () => {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(undefined);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a test notification
|
||||||
|
* @param {string} type - The notification type (slack, discord, telegram, webhook)
|
||||||
|
* @param {object} config - Configuration object with necessary params
|
||||||
|
*/
|
||||||
|
const sendTestNotification = async (type, config) => {
|
||||||
|
setLoading(true);
|
||||||
|
setError(undefined);
|
||||||
|
|
||||||
|
// Validation based on notification type
|
||||||
|
let payload = { platform: type };
|
||||||
|
let isValid = true;
|
||||||
|
let errorMessage = "";
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case NOTIFICATION_TYPES.SLACK:
|
||||||
|
payload.webhookUrl = config.webhook;
|
||||||
|
if (typeof payload.webhookUrl === "undefined" || payload.webhookUrl === "") {
|
||||||
|
isValid = false;
|
||||||
|
errorMessage = t("notifications.slack.webhookRequired");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOTIFICATION_TYPES.DISCORD:
|
||||||
|
payload.webhookUrl = config.webhook;
|
||||||
|
if (typeof payload.webhookUrl === "undefined" || payload.webhookUrl === "") {
|
||||||
|
isValid = false;
|
||||||
|
errorMessage = t("notifications.discord.webhookRequired");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOTIFICATION_TYPES.TELEGRAM:
|
||||||
|
payload.botToken = config.token;
|
||||||
|
payload.chatId = config.chatId;
|
||||||
|
if (
|
||||||
|
typeof payload.botToken === "undefined" ||
|
||||||
|
payload.botToken === "" ||
|
||||||
|
typeof payload.chatId === "undefined" ||
|
||||||
|
payload.chatId === ""
|
||||||
|
) {
|
||||||
|
isValid = false;
|
||||||
|
errorMessage = t("notifications.telegram.fieldsRequired");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NOTIFICATION_TYPES.WEBHOOK:
|
||||||
|
payload.webhookUrl = config.url;
|
||||||
|
payload.platform = NOTIFICATION_TYPES.SLACK;
|
||||||
|
if (typeof payload.webhookUrl === "undefined" || payload.webhookUrl === "") {
|
||||||
|
isValid = false;
|
||||||
|
errorMessage = t("notifications.webhook.urlRequired");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
isValid = false;
|
||||||
|
errorMessage = t("notifications.unsupportedType");
|
||||||
|
}
|
||||||
|
|
||||||
|
// If validation fails, show error and return
|
||||||
|
if (isValid === false) {
|
||||||
|
createToast({
|
||||||
|
body: errorMessage,
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
setLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await networkService.testNotification({
|
||||||
|
platform: type,
|
||||||
|
payload: payload,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.data.success === true) {
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.testSuccess"),
|
||||||
|
variant: "info",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error(response.data.msg || t("notifications.testFailed"));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const errorMsg =
|
||||||
|
error.response?.data?.msg || error.message || t("notifications.networkError");
|
||||||
|
createToast({
|
||||||
|
body: `${t("notifications.testFailed")}: ${errorMsg}`,
|
||||||
|
variant: "error",
|
||||||
|
});
|
||||||
|
setError(errorMsg);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [loading, error, sendTestNotification];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useNotifications;
|
||||||
@@ -5,7 +5,7 @@ import PropTypes from "prop-types";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { Link as RouterLink } from "react-router-dom";
|
import { Link as RouterLink } from "react-router-dom";
|
||||||
|
|
||||||
const TextLink = ({ text, linkText, href, state, target = "_self" }) => {
|
const TextLink = ({ text, linkText, href, target = "_self" }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -19,7 +19,6 @@ const TextLink = ({ text, linkText, href, state, target = "_self" }) => {
|
|||||||
to={href}
|
to={href}
|
||||||
component={RouterLink}
|
component={RouterLink}
|
||||||
target={target}
|
target={target}
|
||||||
state={state}
|
|
||||||
>
|
>
|
||||||
{linkText}
|
{linkText}
|
||||||
</Link>
|
</Link>
|
||||||
@@ -31,7 +30,6 @@ TextLink.propTypes = {
|
|||||||
text: PropTypes.string,
|
text: PropTypes.string,
|
||||||
linkText: PropTypes.string,
|
linkText: PropTypes.string,
|
||||||
href: PropTypes.string,
|
href: PropTypes.string,
|
||||||
state: PropTypes.object,
|
|
||||||
target: PropTypes.string,
|
target: PropTypes.string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import type { RootState } from "@/Types/state";
|
import type { RootState } from "@/Types/state";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
type HeatmapCheck =
|
type HeatmapCheck =
|
||||||
| CheckSnapshot
|
| CheckSnapshot
|
||||||
| { status: "placeholder"; responseTime: 0; createdAt: "" };
|
| { status: "placeholder"; responseTime: 0; createdAt: "" };
|
||||||
@@ -56,9 +55,12 @@ export const HeatmapResponseTimeTooltip = ({
|
|||||||
<Typography>
|
<Typography>
|
||||||
{formatDateWithTz(check?.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone)}
|
{formatDateWithTz(check?.createdAt, "ddd, MMMM D, YYYY, HH:mm A", uiTimezone)}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography>
|
{check?.responseTime && (
|
||||||
{t("common.labels.responseTime")}: {check.originalResponseTime.toFixed()} ms
|
<Typography>
|
||||||
</Typography>
|
{t("common.labels.responseTime")}: {check.responseTime.toFixed()} ms
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
<Typography textTransform={"capitalize"}>
|
<Typography textTransform={"capitalize"}>
|
||||||
Status:{" "}
|
Status:{" "}
|
||||||
<span style={{ color: getColor(check?.status) }}>
|
<span style={{ color: getColor(check?.status) }}>
|
||||||
|
|||||||
+13
-87
@@ -1,7 +1,7 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { Icon, MonitorStatus } from "@/Components/v2/design-elements";
|
import { Icon, MonitorStatus } from "@/Components/v2/design-elements";
|
||||||
import { Button } from "@/Components/v2/inputs";
|
import { Button } from "@/Components/v2/inputs";
|
||||||
import { Settings, Pause, Play, Mail, Bug, Trash } from "lucide-react";
|
import { Settings, Pause, Play, Mail, Bug } from "lucide-react";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
@@ -9,28 +9,10 @@ import { useTheme } from "@mui/material/styles";
|
|||||||
import { usePost } from "@/Hooks/UseApi";
|
import { usePost } from "@/Hooks/UseApi";
|
||||||
|
|
||||||
import type { Monitor } from "@/Types/Monitor.js";
|
import type { Monitor } from "@/Types/Monitor.js";
|
||||||
interface BaseHeaderProps {
|
|
||||||
monitor: Monitor;
|
|
||||||
}
|
|
||||||
|
|
||||||
const BaseHeader = ({ monitor, children }: React.PropsWithChildren<BaseHeaderProps>) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
spacing={{ xs: theme.spacing(8), md: 0 }}
|
|
||||||
direction={{ xs: "column", md: "row" }}
|
|
||||||
alignItems={"center"}
|
|
||||||
justifyContent={"space-between"}
|
|
||||||
>
|
|
||||||
<MonitorStatus monitor={monitor} />
|
|
||||||
{children}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface HeaderMonitorControlsProps {
|
interface HeaderMonitorControlsProps {
|
||||||
path: string;
|
path: string;
|
||||||
monitor?: Monitor | null;
|
monitor?: Monitor;
|
||||||
isAdmin: boolean;
|
isAdmin: boolean;
|
||||||
refetch: Function;
|
refetch: Function;
|
||||||
}
|
}
|
||||||
@@ -42,8 +24,8 @@ export const HeaderMonitorControls = ({
|
|||||||
refetch,
|
refetch,
|
||||||
}: HeaderMonitorControlsProps) => {
|
}: HeaderMonitorControlsProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const theme = useTheme();
|
||||||
const {
|
const {
|
||||||
post,
|
post,
|
||||||
loading: isPosting,
|
loading: isPosting,
|
||||||
@@ -54,7 +36,13 @@ export const HeaderMonitorControls = ({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<BaseHeader monitor={monitor}>
|
<Stack
|
||||||
|
spacing={{ xs: theme.spacing(8), md: 0 }}
|
||||||
|
direction={{ xs: "column", md: "row" }}
|
||||||
|
alignItems={"center"}
|
||||||
|
justifyContent={"space-between"}
|
||||||
|
>
|
||||||
|
<MonitorStatus monitor={monitor} />
|
||||||
<Stack
|
<Stack
|
||||||
width={{ xs: "100%", md: "auto" }}
|
width={{ xs: "100%", md: "auto" }}
|
||||||
direction={{ xs: "column", md: "row" }}
|
direction={{ xs: "column", md: "row" }}
|
||||||
@@ -95,7 +83,7 @@ export const HeaderMonitorControls = ({
|
|||||||
await refetch();
|
await refetch();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{monitor?.isActive ? t("common.buttons.pause") : t("common.buttons.resume")}
|
{monitor?.isActive ? t("pause") : t("resume")}
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
@@ -105,72 +93,10 @@ export const HeaderMonitorControls = ({
|
|||||||
startIcon={<Icon icon={Settings} />}
|
startIcon={<Icon icon={Settings} />}
|
||||||
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
|
onClick={() => navigate(`/${path}/configure/${monitor.id}`)}
|
||||||
>
|
>
|
||||||
{t("common.buttons.configure")}
|
Configure
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</BaseHeader>
|
</Stack>
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface HeaderDeleteControlsProps {
|
|
||||||
monitor?: Monitor | null;
|
|
||||||
isAdmin: boolean;
|
|
||||||
refetch: Function;
|
|
||||||
onDelete?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const HeaderDeleteControls = ({
|
|
||||||
monitor,
|
|
||||||
isAdmin,
|
|
||||||
refetch,
|
|
||||||
onDelete,
|
|
||||||
}: HeaderDeleteControlsProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const {
|
|
||||||
post,
|
|
||||||
loading: isPosting,
|
|
||||||
// error: postError,
|
|
||||||
} = usePost<any, Monitor>();
|
|
||||||
|
|
||||||
if (!monitor) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<BaseHeader monitor={monitor}>
|
|
||||||
<Stack
|
|
||||||
width={{ xs: "100%", md: "auto" }}
|
|
||||||
direction={{ xs: "column", md: "row" }}
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
{isAdmin && (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="secondary"
|
|
||||||
loading={isPosting}
|
|
||||||
startIcon={monitor?.isActive ? <Icon icon={Pause} /> : <Icon icon={Play} />}
|
|
||||||
onClick={async () => {
|
|
||||||
await post(`/monitors/pause/${monitor.id}`, {});
|
|
||||||
await refetch();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{monitor?.isActive ? t("common.buttons.pause") : t("common.buttons.resume")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
{isAdmin && (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
startIcon={<Icon icon={Trash} />}
|
|
||||||
onClick={() => {
|
|
||||||
onDelete?.();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("common.buttons.delete")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</BaseHeader>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import { ToggleButtonGroup, ToggleButton } from "@/Components/v2/inputs";
|
import { ToggleButtonGroup, ToggleButton } from "@/Components/v2/inputs";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useMediaQuery } from "@mui/material";
|
|
||||||
|
|
||||||
interface MonitorTimeFrameHeaderProps {
|
interface MonitorTimeFrameHeaderProps {
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
@@ -21,8 +17,7 @@ export const HeaderTimeRange = ({
|
|||||||
setDateRange,
|
setDateRange,
|
||||||
}: MonitorTimeFrameHeaderProps) => {
|
}: MonitorTimeFrameHeaderProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
|
||||||
const isSmallScreen = useMediaQuery(theme.breakpoints.down("md"));
|
|
||||||
const handleChange = (
|
const handleChange = (
|
||||||
_event: React.MouseEvent<HTMLElement>,
|
_event: React.MouseEvent<HTMLElement>,
|
||||||
newValue: string | null
|
newValue: string | null
|
||||||
@@ -37,24 +32,34 @@ export const HeaderTimeRange = ({
|
|||||||
if (hasDateRange) {
|
if (hasDateRange) {
|
||||||
timeFramePicker = (
|
timeFramePicker = (
|
||||||
<ToggleButtonGroup
|
<ToggleButtonGroup
|
||||||
orientation={isSmallScreen ? "vertical" : "horizontal"}
|
|
||||||
value={dateRange}
|
value={dateRange}
|
||||||
exclusive
|
exclusive
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
size="small"
|
size="small"
|
||||||
fullWidth={isSmallScreen}
|
|
||||||
>
|
>
|
||||||
<ToggleButton value="recent">
|
<ToggleButton
|
||||||
{t("components.headerTimeRange.labels.recent")}
|
disabled={isLoading}
|
||||||
|
value="recent"
|
||||||
|
>
|
||||||
|
Recent
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
<ToggleButton value="day">
|
<ToggleButton
|
||||||
{t("components.headerTimeRange.labels.day")}
|
disabled={isLoading}
|
||||||
|
value="day"
|
||||||
|
>
|
||||||
|
Day
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
<ToggleButton value="week">
|
<ToggleButton
|
||||||
{t("components.headerTimeRange.labels.week")}
|
disabled={isLoading}
|
||||||
|
value="week"
|
||||||
|
>
|
||||||
|
Week
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
<ToggleButton value="month">
|
<ToggleButton
|
||||||
{t("components.headerTimeRange.labels.month")}
|
disabled={isLoading}
|
||||||
|
value="month"
|
||||||
|
>
|
||||||
|
Month
|
||||||
</ToggleButton>
|
</ToggleButton>
|
||||||
</ToggleButtonGroup>
|
</ToggleButtonGroup>
|
||||||
);
|
);
|
||||||
@@ -62,19 +67,21 @@ export const HeaderTimeRange = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction={{ xs: "column", md: "row" }}
|
direction="row"
|
||||||
justifyContent="flex-end"
|
justifyContent="flex-end"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
gap={theme.spacing(4)}
|
gap={theme.spacing(4)}
|
||||||
>
|
>
|
||||||
<Box
|
|
||||||
width={16}
|
|
||||||
height={16}
|
|
||||||
>
|
|
||||||
{isLoading && <CircularProgress size={16} />}
|
|
||||||
</Box>
|
|
||||||
<Typography variant="body2">
|
<Typography variant="body2">
|
||||||
{t(`components.headerTimeRange.description.${dateRange}`)}
|
Showing statistics for past{" "}
|
||||||
|
{dateRange === "recent"
|
||||||
|
? "2 hours"
|
||||||
|
: dateRange === "day"
|
||||||
|
? "24 hours"
|
||||||
|
: dateRange === "week"
|
||||||
|
? "7 days"
|
||||||
|
: "30 days"}
|
||||||
|
.
|
||||||
</Typography>
|
</Typography>
|
||||||
{timeFramePicker}
|
{timeFramePicker}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ export * from "../common/charts/HistogramResponseTime";
|
|||||||
export * from "../common/charts/HeatmapResponseTime";
|
export * from "../common/charts/HeatmapResponseTime";
|
||||||
export * from "../common/charts/HeatmapResponseTimeTooltip";
|
export * from "../common/charts/HeatmapResponseTimeTooltip";
|
||||||
export * from "../common/controls/HeaderCreate";
|
export * from "../common/controls/HeaderCreate";
|
||||||
|
export * from "../common/controls/HeaderMonitorControls";
|
||||||
export * from "../common/controls/HeaderTimeRange";
|
export * from "../common/controls/HeaderTimeRange";
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
import Logo from "@/assets/icons/checkmate-icon.svg?react";
|
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import Alert from "@mui/material/Alert";
|
import Alert from "@mui/material/Alert";
|
||||||
import Link from "@mui/material/Link";
|
import Link from "@mui/material/Link";
|
||||||
import {
|
import {
|
||||||
@@ -11,7 +9,6 @@ import {
|
|||||||
} from "@/Components/v2/design-elements/Fallback";
|
} from "@/Components/v2/design-elements/Fallback";
|
||||||
import { Breadcrumb } from "@/Components/v2/design-elements/Breadcrumb";
|
import { Breadcrumb } from "@/Components/v2/design-elements/Breadcrumb";
|
||||||
import CircularProgress from "@mui/material/CircularProgress";
|
import CircularProgress from "@mui/material/CircularProgress";
|
||||||
import { HeaderAuthControls } from "@/Pages/Auth/components/HeaderAuthControls";
|
|
||||||
|
|
||||||
import type { StackProps } from "@mui/material/Stack";
|
import type { StackProps } from "@mui/material/Stack";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
@@ -94,7 +91,7 @@ export const BasePage = ({
|
|||||||
spacing={theme.spacing(10)}
|
spacing={theme.spacing(10)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
<Breadcrumb breadcrumbOverride={breadcrumbOverride} />
|
<Breadcrumb />
|
||||||
{children}
|
{children}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
@@ -103,7 +100,7 @@ export const BasePage = ({
|
|||||||
interface BasePageWithStatesProps extends StackProps {
|
interface BasePageWithStatesProps extends StackProps {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: any;
|
error: any;
|
||||||
totalCount: number;
|
items: any[];
|
||||||
bullets: string[] | unknown;
|
bullets: string[] | unknown;
|
||||||
page: string;
|
page: string;
|
||||||
actionButtonText: string;
|
actionButtonText: string;
|
||||||
@@ -114,7 +111,7 @@ interface BasePageWithStatesProps extends StackProps {
|
|||||||
export const BasePageWithStates = ({
|
export const BasePageWithStates = ({
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
totalCount,
|
items,
|
||||||
page,
|
page,
|
||||||
bullets,
|
bullets,
|
||||||
actionButtonText,
|
actionButtonText,
|
||||||
@@ -122,9 +119,9 @@ export const BasePageWithStates = ({
|
|||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: BasePageWithStatesProps) => {
|
}: BasePageWithStatesProps) => {
|
||||||
const showLoading = loading && totalCount === 0;
|
const showLoading = loading && (!items || items.length === 0);
|
||||||
|
|
||||||
if (!loading && totalCount === 0) {
|
if (isEmpty(items)) {
|
||||||
return (
|
return (
|
||||||
<EmptyFallback
|
<EmptyFallback
|
||||||
bullets={bullets}
|
bullets={bullets}
|
||||||
@@ -149,17 +146,23 @@ export const BasePageWithStates = ({
|
|||||||
interface MonitorBasePageWithStatesProps extends StackProps {
|
interface MonitorBasePageWithStatesProps extends StackProps {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: any;
|
error: any;
|
||||||
totalCount: number;
|
items: any[];
|
||||||
page: string;
|
page: string;
|
||||||
actionLink?: string;
|
actionLink?: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
priorityFallback?: React.ReactNode;
|
priorityFallback?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isEmpty = (items: any[]) => {
|
||||||
|
if (!items) return true;
|
||||||
|
if (Array.isArray(items) && items.length === 0) return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
export const MonitorBasePageWithStates = ({
|
export const MonitorBasePageWithStates = ({
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
totalCount,
|
items,
|
||||||
page,
|
page,
|
||||||
actionLink,
|
actionLink,
|
||||||
children,
|
children,
|
||||||
@@ -168,7 +171,7 @@ export const MonitorBasePageWithStates = ({
|
|||||||
}: MonitorBasePageWithStatesProps) => {
|
}: MonitorBasePageWithStatesProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const showLoading = loading && totalCount === 0;
|
const showLoading = loading && (!items || items.length === 0);
|
||||||
|
|
||||||
if (priorityFallback) {
|
if (priorityFallback) {
|
||||||
return (
|
return (
|
||||||
@@ -182,7 +185,7 @@ export const MonitorBasePageWithStates = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loading && totalCount === 0) {
|
if (!loading && isEmpty(items)) {
|
||||||
return (
|
return (
|
||||||
<EmptyMonitorFallback
|
<EmptyMonitorFallback
|
||||||
page={page}
|
page={page}
|
||||||
@@ -204,61 +207,3 @@ export const MonitorBasePageWithStates = ({
|
|||||||
</BasePage>
|
</BasePage>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
interface BaseAuthPageProps extends React.PropsWithChildren, StackProps {
|
|
||||||
title: string;
|
|
||||||
subtitle: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const BaseAuthPage = ({
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
children,
|
|
||||||
...props
|
|
||||||
}: BaseAuthPageProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<BasePage
|
|
||||||
breadcrumbOverride={[]}
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
alignItems={"center"}
|
|
||||||
justifyContent={"center"}
|
|
||||||
minHeight="100vh"
|
|
||||||
position={"relative"}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<HeaderAuthControls
|
|
||||||
hideLogo
|
|
||||||
py={theme.spacing(4)}
|
|
||||||
position={"absolute"}
|
|
||||||
top={0}
|
|
||||||
left={0}
|
|
||||||
/>
|
|
||||||
<Box width={{ xs: 60, sm: 70, md: 80 }}>
|
|
||||||
<Logo
|
|
||||||
width={"100%"}
|
|
||||||
height={"100%"}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Stack alignItems={"center"}>
|
|
||||||
<Typography
|
|
||||||
variant="h1"
|
|
||||||
mb={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</Typography>
|
|
||||||
<Typography variant="h2">{subtitle}</Typography>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
width={{
|
|
||||||
xs: "80%",
|
|
||||||
md: "25%",
|
|
||||||
lg: "15%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Stack>
|
|
||||||
</BasePage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -3,17 +3,21 @@ import Typography from "@mui/material/Typography";
|
|||||||
import { Link, useLocation } from "react-router-dom";
|
import { Link, useLocation } from "react-router-dom";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { ChevronRight } from "lucide-react";
|
import { ChevronRight } from "lucide-react";
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import type { ReactNode } from "react";
|
|
||||||
|
|
||||||
const isId = (segment: string): boolean => {
|
const isId = (segment: string): boolean => {
|
||||||
return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment);
|
return segment.length === 24 || /^[a-f0-9-]{36}$/.test(segment);
|
||||||
};
|
};
|
||||||
|
|
||||||
const actionSegments = ["create", "configure"];
|
export const Breadcrumb = () => {
|
||||||
|
|
||||||
const BreadcrumbWrapper = ({ children }: { children: ReactNode }) => {
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const location = useLocation();
|
||||||
|
|
||||||
|
const segments = location.pathname.split("/").filter((x) => x);
|
||||||
|
|
||||||
|
// Build simplified breadcrumb: "uptime" or "uptime / details"
|
||||||
|
const basePage = segments[0] || "home";
|
||||||
|
const hasDetailsPage = segments.length > 1 && isId(segments[1]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MuiBreadcrumbs
|
<MuiBreadcrumbs
|
||||||
separator={
|
separator={
|
||||||
@@ -30,73 +34,7 @@ const BreadcrumbWrapper = ({ children }: { children: ReactNode }) => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{hasDetailsPage ? (
|
||||||
</MuiBreadcrumbs>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const Breadcrumb = ({
|
|
||||||
breadcrumbOverride,
|
|
||||||
}: {
|
|
||||||
breadcrumbOverride?: string[] | undefined;
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
// If override is an empty array, hide entirely
|
|
||||||
if (breadcrumbOverride !== undefined && breadcrumbOverride.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If override has items, render them directly
|
|
||||||
if (breadcrumbOverride !== undefined && breadcrumbOverride.length > 0) {
|
|
||||||
return (
|
|
||||||
<BreadcrumbWrapper>
|
|
||||||
{breadcrumbOverride.map((item, index) => {
|
|
||||||
const isLast = index === breadcrumbOverride.length - 1;
|
|
||||||
return (
|
|
||||||
<Typography
|
|
||||||
key={index}
|
|
||||||
sx={{
|
|
||||||
fontSize: "14px",
|
|
||||||
fontWeight: isLast ? 600 : 400,
|
|
||||||
color: isLast ? theme.palette.primary.main : theme.palette.text.secondary,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{item}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</BreadcrumbWrapper>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default behavior: use location pathname
|
|
||||||
const segments = location.pathname.split("/").filter((x) => x);
|
|
||||||
|
|
||||||
if (segments.length === 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build simplified breadcrumb: "uptime" or "uptime / details" or "uptime / create"
|
|
||||||
const basePage = segments[0] || t("common.breadcrumbs.home");
|
|
||||||
|
|
||||||
const secondSegment = segments[1];
|
|
||||||
const isActionPage = secondSegment && actionSegments.includes(secondSegment);
|
|
||||||
const isDetailsPage = secondSegment && isId(secondSegment);
|
|
||||||
const hasSubPage = isActionPage || isDetailsPage;
|
|
||||||
|
|
||||||
const getSubPageLabel = (): string => {
|
|
||||||
if (isActionPage) {
|
|
||||||
return secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1);
|
|
||||||
}
|
|
||||||
return t("common.breadcrumbs.details");
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BreadcrumbWrapper>
|
|
||||||
{hasSubPage ? (
|
|
||||||
<Link
|
<Link
|
||||||
to={`/${basePage}`}
|
to={`/${basePage}`}
|
||||||
style={{ textDecoration: "none" }}
|
style={{ textDecoration: "none" }}
|
||||||
@@ -124,7 +62,7 @@ export const Breadcrumb = ({
|
|||||||
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
|
{basePage.charAt(0).toUpperCase() + basePage.slice(1)}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
{hasSubPage && (
|
{hasDetailsPage && (
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: "14px",
|
fontSize: "14px",
|
||||||
@@ -132,9 +70,9 @@ export const Breadcrumb = ({
|
|||||||
color: theme.palette.primary.main,
|
color: theme.palette.primary.main,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{getSubPageLabel()}
|
Details
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
</BreadcrumbWrapper>
|
</MuiBreadcrumbs>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,155 +0,0 @@
|
|||||||
import { BaseChart } from "@/Components/v2/design-elements";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import { useMemo, useState, useEffect } from "react";
|
|
||||||
import { getInfraGaugeColor } from "@/Utils/MonitorUtils";
|
|
||||||
|
|
||||||
const MINIMUM_VALUE = 0;
|
|
||||||
const MAXIMUM_VALUE = 100;
|
|
||||||
|
|
||||||
export const Gauge = ({
|
|
||||||
isLoading = false,
|
|
||||||
progress = 0,
|
|
||||||
radius = 70,
|
|
||||||
strokeWidth = 15,
|
|
||||||
precision = 1,
|
|
||||||
unit = "%",
|
|
||||||
}: {
|
|
||||||
isLoading?: boolean;
|
|
||||||
progress?: number;
|
|
||||||
radius?: number;
|
|
||||||
strokeWidth?: number;
|
|
||||||
precision?: number;
|
|
||||||
unit?: string;
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const progressWithinRange = Math.max(MINIMUM_VALUE, Math.min(progress, MAXIMUM_VALUE));
|
|
||||||
|
|
||||||
// Calculate the length of the stroke for the circle
|
|
||||||
const { circumference, totalSize, strokeLength } = useMemo(
|
|
||||||
() => ({
|
|
||||||
circumference: 2 * Math.PI * radius,
|
|
||||||
totalSize: radius * 2 + strokeWidth * 2,
|
|
||||||
strokeLength: (progress / 100) * (2 * Math.PI * radius),
|
|
||||||
}),
|
|
||||||
[radius, strokeWidth, progress]
|
|
||||||
);
|
|
||||||
|
|
||||||
const [offset, setOffset] = useState(circumference);
|
|
||||||
useEffect(() => {
|
|
||||||
setOffset(circumference);
|
|
||||||
const timer = setTimeout(() => {
|
|
||||||
setOffset(circumference - strokeLength);
|
|
||||||
}, 100);
|
|
||||||
|
|
||||||
return () => clearTimeout(timer);
|
|
||||||
}, [progress, circumference, strokeLength]);
|
|
||||||
|
|
||||||
const fillColor = getInfraGaugeColor(progressWithinRange, theme);
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
display={"inline-block"}
|
|
||||||
position={"relative"}
|
|
||||||
width={radius}
|
|
||||||
height={radius}
|
|
||||||
bgcolor={theme.palette.background.paper}
|
|
||||||
borderRadius={"50%"}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
viewBox={`0 0 ${totalSize} ${totalSize}`}
|
|
||||||
width={radius}
|
|
||||||
height={radius}
|
|
||||||
>
|
|
||||||
<circle
|
|
||||||
stroke={theme.palette.secondary.main}
|
|
||||||
strokeWidth={strokeWidth}
|
|
||||||
fill="none"
|
|
||||||
cx={totalSize / 2}
|
|
||||||
cy={totalSize / 2}
|
|
||||||
r={radius}
|
|
||||||
/>
|
|
||||||
<circle
|
|
||||||
stroke={fillColor}
|
|
||||||
strokeWidth={strokeWidth}
|
|
||||||
strokeDasharray={`${circumference} ${circumference}`}
|
|
||||||
strokeDashoffset={offset}
|
|
||||||
fill="none"
|
|
||||||
cx={totalSize / 2}
|
|
||||||
cy={totalSize / 2}
|
|
||||||
r={radius}
|
|
||||||
style={{
|
|
||||||
transform: "rotate(-90deg)",
|
|
||||||
transformOrigin: "center",
|
|
||||||
transition: "stroke-dashoffset 1.5s ease-in-out",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
<Typography
|
|
||||||
style={{
|
|
||||||
position: "absolute",
|
|
||||||
top: "50%",
|
|
||||||
left: "50%",
|
|
||||||
transform: "translate(-50%, -50%)",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{`${progressWithinRange.toFixed(precision)}${unit}`}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DetailGauge = ({
|
|
||||||
title,
|
|
||||||
progress,
|
|
||||||
upperLabel,
|
|
||||||
upperValue,
|
|
||||||
lowerLabel,
|
|
||||||
lowerValue,
|
|
||||||
}: {
|
|
||||||
title: string;
|
|
||||||
progress: number;
|
|
||||||
upperLabel?: string;
|
|
||||||
upperValue?: string | number;
|
|
||||||
lowerLabel?: string;
|
|
||||||
lowerValue?: string | number;
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<BaseChart
|
|
||||||
icon={null}
|
|
||||||
title={title}
|
|
||||||
maxWidth={225}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
alignItems={"center"}
|
|
||||||
mb={theme.spacing(4)}
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
>
|
|
||||||
<Gauge progress={progress} />
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction={"row"}
|
|
||||||
justifyContent={"space-between"}
|
|
||||||
>
|
|
||||||
<Typography>{upperLabel}</Typography>
|
|
||||||
<Typography>{upperValue}</Typography>
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction={"row"}
|
|
||||||
justifyContent={"space-between"}
|
|
||||||
>
|
|
||||||
<Typography>{lowerLabel}</Typography>
|
|
||||||
<Typography>{lowerValue}</Typography>
|
|
||||||
</Stack>
|
|
||||||
</BaseChart>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
||||||
export const SplitBox = ({
|
|
||||||
left,
|
|
||||||
right,
|
|
||||||
}: {
|
|
||||||
left: React.ReactNode;
|
|
||||||
right: React.ReactNode;
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction={isSmall ? "column" : "row"}
|
|
||||||
bgcolor={theme.palette.background.paper}
|
|
||||||
border={1}
|
|
||||||
borderColor={theme.palette.divider}
|
|
||||||
borderRadius={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Box
|
|
||||||
padding={theme.spacing(15)}
|
|
||||||
borderRight={isSmall ? 0 : 1}
|
|
||||||
borderBottom={isSmall ? 1 : 0}
|
|
||||||
borderColor={theme.palette.divider}
|
|
||||||
flex={0.7}
|
|
||||||
sx={{
|
|
||||||
background:
|
|
||||||
theme.palette.mode === "dark"
|
|
||||||
? "linear-gradient(135deg, rgba(255, 255, 255, 0.01) 0%, rgba(255, 255, 255, 0.02) 100%)"
|
|
||||||
: "linear-gradient(135deg, rgba(0, 0, 0, 0.01) 0%, rgba(0, 0, 0, 0.02) 100%)",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{left}
|
|
||||||
</Box>
|
|
||||||
<Box
|
|
||||||
flex={1}
|
|
||||||
padding={theme.spacing(15)}
|
|
||||||
>
|
|
||||||
{right}
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const ConfigBox = ({
|
|
||||||
title,
|
|
||||||
subtitle,
|
|
||||||
leftContent,
|
|
||||||
rightContent,
|
|
||||||
}: {
|
|
||||||
title: string;
|
|
||||||
subtitle: string;
|
|
||||||
leftContent?: React.ReactNode;
|
|
||||||
rightContent: React.ReactNode;
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<SplitBox
|
|
||||||
left={
|
|
||||||
<Stack spacing={theme.spacing(4)}>
|
|
||||||
<Typography
|
|
||||||
textTransform={"capitalize"}
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">{subtitle}</Typography>
|
|
||||||
{leftContent}
|
|
||||||
</Stack>
|
|
||||||
}
|
|
||||||
right={rightContent}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -4,16 +4,12 @@ import Box from "@mui/material/Box";
|
|||||||
import { BaseBox } from "@/Components/v2/design-elements";
|
import { BaseBox } from "@/Components/v2/design-elements";
|
||||||
import Background from "@/assets/Images/background-grid.svg?react";
|
import Background from "@/assets/Images/background-grid.svg?react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import type { SxProps } from "@mui/material";
|
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
|
||||||
type StatusBoxProps = React.PropsWithChildren<{
|
type StatusBoxProps = React.PropsWithChildren<{ children: React.ReactNode }>;
|
||||||
children: React.ReactNode;
|
|
||||||
sx?: SxProps;
|
|
||||||
}>;
|
|
||||||
|
|
||||||
export const BGBox = ({ children, sx }: StatusBoxProps) => {
|
export const BGBox = ({ children }: StatusBoxProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<BaseBox
|
<BaseBox
|
||||||
@@ -22,7 +18,6 @@ export const BGBox = ({ children, sx }: StatusBoxProps) => {
|
|||||||
position: "relative",
|
position: "relative",
|
||||||
flex: 1,
|
flex: 1,
|
||||||
padding: theme.spacing(4),
|
padding: theme.spacing(4),
|
||||||
...sx,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box
|
<Box
|
||||||
@@ -41,16 +36,14 @@ const StatusBox = ({
|
|||||||
label,
|
label,
|
||||||
n,
|
n,
|
||||||
color,
|
color,
|
||||||
sx,
|
|
||||||
}: {
|
}: {
|
||||||
label: string;
|
label: string;
|
||||||
n: number;
|
n: number;
|
||||||
color: string | undefined;
|
color: string | undefined;
|
||||||
sx?: SxProps;
|
|
||||||
}) => {
|
}) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<BGBox sx={sx}>
|
<BGBox>
|
||||||
<Stack spacing={theme.spacing(4)}>
|
<Stack spacing={theme.spacing(4)}>
|
||||||
<Typography
|
<Typography
|
||||||
variant={"h2"}
|
variant={"h2"}
|
||||||
@@ -105,39 +98,6 @@ export const PausedStatusBox = ({ n }: { n: number }) => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export const TotalChecksBox = ({ n }: { n: number }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
return (
|
|
||||||
<StatusBox
|
|
||||||
label={t("pages.common.monitors.status.total")}
|
|
||||||
n={n}
|
|
||||||
color={theme.palette.primary.light}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
export const DownChecksBox = ({ n }: { n: number }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
return (
|
|
||||||
<StatusBox
|
|
||||||
label={t("pages.common.monitors.status.down")}
|
|
||||||
n={n}
|
|
||||||
color={theme.palette.error.light}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
export const UpChecksBox = ({ n }: { n: number }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
return (
|
|
||||||
<StatusBox
|
|
||||||
label={t("pages.common.monitors.status.up")}
|
|
||||||
n={n}
|
|
||||||
color={theme.palette.success.light}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const InitializingStatusBox = ({ n }: { n: number }) => {
|
export const InitializingStatusBox = ({ n }: { n: number }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ export const ValueLabel = ({ value, text }: { value: ValueType; text: string })
|
|||||||
borderRadius="50%"
|
borderRadius="50%"
|
||||||
marginRight="5px"
|
marginRight="5px"
|
||||||
/>
|
/>
|
||||||
<Typography>{transformedText}</Typography>
|
{transformedText}
|
||||||
</BaseBox>
|
</BaseBox>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import Grid2 from "@mui/material/Grid";
|
import Grid2 from "@mui/material/Grid2";
|
||||||
import Box from "@mui/material/Box";
|
import Box from "@mui/material/Box";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Paper from "@mui/material/Paper";
|
import Paper from "@mui/material/Paper";
|
||||||
@@ -27,9 +27,8 @@ import TablePagination from "@mui/material/TablePagination";
|
|||||||
import type { TablePaginationOwnProps } from "@mui/material/TablePagination";
|
import type { TablePaginationOwnProps } from "@mui/material/TablePagination";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useState, Fragment, useEffect } from "react";
|
import { useState, Fragment } from "react";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import type { SxProps, Theme } from "@mui/material/styles";
|
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
import useMediaQuery from "@mui/material/useMediaQuery";
|
||||||
|
|
||||||
export type Header<T> = {
|
export type Header<T> = {
|
||||||
@@ -48,7 +47,6 @@ type DataTableProps<T extends { id?: string | number; _id?: string | number }> =
|
|||||||
renderExpandedContent?: (row: T) => React.ReactNode;
|
renderExpandedContent?: (row: T) => React.ReactNode;
|
||||||
emptyViewText?: string;
|
emptyViewText?: string;
|
||||||
emptyViewPositive?: boolean;
|
emptyViewPositive?: boolean;
|
||||||
getRowSx?: (row: T) => SxProps<Theme>;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function DataTable<
|
export function DataTable<
|
||||||
@@ -66,7 +64,6 @@ export function DataTable<
|
|||||||
renderExpandedContent,
|
renderExpandedContent,
|
||||||
emptyViewText,
|
emptyViewText,
|
||||||
emptyViewPositive,
|
emptyViewPositive,
|
||||||
getRowSx,
|
|
||||||
}: DataTableProps<T>) {
|
}: DataTableProps<T>) {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [expanded, setExpanded] = useState<(string | number) | null>(null);
|
const [expanded, setExpanded] = useState<(string | number) | null>(null);
|
||||||
@@ -207,7 +204,6 @@ export function DataTable<
|
|||||||
<TableRow
|
<TableRow
|
||||||
sx={{
|
sx={{
|
||||||
cursor: onRowClick ? "pointer" : "default",
|
cursor: onRowClick ? "pointer" : "default",
|
||||||
...(getRowSx?.(row) as object),
|
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (expandableRows) handleExpand(row);
|
if (expandableRows) handleExpand(row);
|
||||||
@@ -458,26 +454,12 @@ function HasMoreTablePaginationActions(props: HasMoreTablePaginationActionsProps
|
|||||||
interface PaginationProps extends TablePaginationOwnProps {
|
interface PaginationProps extends TablePaginationOwnProps {
|
||||||
component?: React.ElementType;
|
component?: React.ElementType;
|
||||||
hasMore?: boolean;
|
hasMore?: boolean;
|
||||||
itemsOnPage?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Pagination = ({ ...props }: PaginationProps) => {
|
export const Pagination = ({ ...props }: PaginationProps) => {
|
||||||
const { hasMore, itemsOnPage, ...rest } = props;
|
const { hasMore, ...rest } = props;
|
||||||
const isSmall = useMediaQuery((theme: any) => theme.breakpoints.down("sm"));
|
const isSmall = useMediaQuery((theme: any) => theme.breakpoints.down("sm"));
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (
|
|
||||||
typeof itemsOnPage === "number" &&
|
|
||||||
itemsOnPage === 0 &&
|
|
||||||
rest.count > 0 &&
|
|
||||||
rest.page > 0 &&
|
|
||||||
rest.onPageChange
|
|
||||||
) {
|
|
||||||
rest.onPageChange(null, rest.page - 1);
|
|
||||||
}
|
|
||||||
}, [itemsOnPage, rest.count, rest.page, rest.onPageChange]);
|
|
||||||
|
|
||||||
const labelDisplayedRows = ({
|
const labelDisplayedRows = ({
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
import MuiTabs from "@mui/material/Tabs";
|
|
||||||
import type { TabsProps } from "@mui/material/Tabs";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
interface CustomTabsProps extends TabsProps {}
|
|
||||||
|
|
||||||
export const Tabs = (props: CustomTabsProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<MuiTabs
|
|
||||||
sx={{
|
|
||||||
minHeight: 34,
|
|
||||||
borderBottom: `1px solid ${theme.palette.divider}`,
|
|
||||||
"& .MuiTabs-indicator": {
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
height: 2,
|
|
||||||
bottom: 0,
|
|
||||||
},
|
|
||||||
"& .MuiTabs-flexContainer": {
|
|
||||||
gap: theme.spacing(16),
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
{props.children}
|
|
||||||
</MuiTabs>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
import MuiTab from "@mui/material/Tab";
|
|
||||||
import type { TabProps } from "@mui/material/Tab";
|
|
||||||
interface CustomTabProps extends TabProps {}
|
|
||||||
|
|
||||||
export const Tab = (props: CustomTabProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<MuiTab
|
|
||||||
disableRipple
|
|
||||||
iconPosition="start"
|
|
||||||
sx={{
|
|
||||||
textTransform: "none",
|
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: 500,
|
|
||||||
minHeight: 34,
|
|
||||||
padding: theme.spacing(1, 0),
|
|
||||||
paddingBottom: 0,
|
|
||||||
minWidth: "auto",
|
|
||||||
alignItems: "flex-start",
|
|
||||||
color: theme.palette.text.secondary,
|
|
||||||
"&.Mui-selected": {
|
|
||||||
color: theme.palette.primary.main,
|
|
||||||
fontWeight: 600,
|
|
||||||
},
|
|
||||||
"&:hover": {
|
|
||||||
color: theme.palette.text.secondary,
|
|
||||||
},
|
|
||||||
"& .MuiTab-iconWrapper": {
|
|
||||||
marginRight: theme.spacing(2),
|
|
||||||
marginBottom: 0,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
{...props}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import type { StackProps } from "@mui/material/Stack";
|
|
||||||
import Link from "@mui/material/Link";
|
|
||||||
import { Link as RouterLink } from "react-router-dom";
|
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
|
|
||||||
interface TextLinkProps extends StackProps {
|
|
||||||
text: string;
|
|
||||||
linkText: string;
|
|
||||||
href: string;
|
|
||||||
target?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TextLink = ({
|
|
||||||
text,
|
|
||||||
linkText,
|
|
||||||
href,
|
|
||||||
target = "_self",
|
|
||||||
...props
|
|
||||||
}: TextLinkProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<Typography>{text}</Typography>
|
|
||||||
<Link
|
|
||||||
color="primary"
|
|
||||||
to={href}
|
|
||||||
component={RouterLink}
|
|
||||||
target={target}
|
|
||||||
>
|
|
||||||
{linkText}
|
|
||||||
</Link>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -15,7 +15,3 @@ export { default as Icon } from "./Icon";
|
|||||||
export * from "./Tooltip";
|
export * from "./Tooltip";
|
||||||
export * from "./StatBox";
|
export * from "./StatBox";
|
||||||
export * from "./BaseChart";
|
export * from "./BaseChart";
|
||||||
export * from "./Gauge";
|
|
||||||
export * from "./Tabs";
|
|
||||||
export * from "./SplitBox";
|
|
||||||
export * from "./TextLink";
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import { MuiColorInput } from "mui-color-input";
|
|
||||||
import type { MuiColorInputProps } from "mui-color-input";
|
|
||||||
import { typographyLevels } from "@/Utils/Theme/v2Palette";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import { FieldLabel } from "@/Components/v2/inputs/FieldLabel";
|
|
||||||
|
|
||||||
interface ColorPickerProps extends MuiColorInputProps {
|
|
||||||
fieldLabel?: string;
|
|
||||||
required?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ColorInput = ({ fieldLabel, required, ...props }: ColorPickerProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const input = (
|
|
||||||
<MuiColorInput
|
|
||||||
{...props}
|
|
||||||
sx={{
|
|
||||||
"& .MuiOutlinedInput-root": {
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
height: 34,
|
|
||||||
fontSize: typographyLevels.base,
|
|
||||||
},
|
|
||||||
"& .MuiOutlinedInput-notchedOutline": {
|
|
||||||
borderColor: theme.palette.divider,
|
|
||||||
},
|
|
||||||
"&:hover .MuiOutlinedInput-notchedOutline": {
|
|
||||||
borderColor: theme.palette.divider,
|
|
||||||
},
|
|
||||||
"& .MuiFormHelperText-root": {
|
|
||||||
marginLeft: 0,
|
|
||||||
marginRight: 0,
|
|
||||||
marginTop: theme.spacing(1),
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
if (fieldLabel) {
|
|
||||||
return (
|
|
||||||
<Stack spacing={theme.spacing(2)}>
|
|
||||||
<FieldLabel required={required}>{fieldLabel}</FieldLabel>
|
|
||||||
{input}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return input;
|
|
||||||
};
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
|
||||||
import type { DatePickerProps } from "@mui/x-date-pickers/DatePicker";
|
|
||||||
import type { Dayjs } from "dayjs";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import { FieldLabel } from "./FieldLabel";
|
|
||||||
import { Calendar } from "lucide-react";
|
|
||||||
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
|
||||||
import { LocalizationProvider } from "@mui/x-date-pickers";
|
|
||||||
|
|
||||||
interface DatePickerComponentProps extends Omit<DatePickerProps<Dayjs>, "label"> {
|
|
||||||
fieldLabel?: string;
|
|
||||||
required?: boolean;
|
|
||||||
error?: boolean;
|
|
||||||
helperText?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DatePickerComponent = ({
|
|
||||||
fieldLabel,
|
|
||||||
required,
|
|
||||||
error,
|
|
||||||
helperText,
|
|
||||||
...props
|
|
||||||
}: DatePickerComponentProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const picker = (
|
|
||||||
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
||||||
<DatePicker
|
|
||||||
{...props}
|
|
||||||
slots={{
|
|
||||||
openPickerIcon: () => (
|
|
||||||
<Calendar
|
|
||||||
size={20}
|
|
||||||
stroke={theme.palette.text.secondary}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
...props.slots,
|
|
||||||
}}
|
|
||||||
slotProps={{
|
|
||||||
switchViewButton: { sx: { display: "none" } },
|
|
||||||
nextIconButton: { sx: { ml: theme.spacing(2) } },
|
|
||||||
day: {
|
|
||||||
sx: {
|
|
||||||
"&.MuiPickersDay-root.Mui-disabled": {
|
|
||||||
color: theme.palette.text.disabled,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
field: {
|
|
||||||
sx: {
|
|
||||||
width: "fit-content",
|
|
||||||
"& > .MuiOutlinedInput-root": {
|
|
||||||
flexDirection: "row-reverse",
|
|
||||||
},
|
|
||||||
"& input": {
|
|
||||||
minHeight: 34,
|
|
||||||
p: 0,
|
|
||||||
pl: theme.spacing(3),
|
|
||||||
pr: theme.spacing(5),
|
|
||||||
},
|
|
||||||
"& fieldset": {
|
|
||||||
borderColor: error ? theme.palette.error.main : theme.palette.divider,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
},
|
|
||||||
"&:not(:has(.Mui-disabled)):not(:has(.Mui-error)) .MuiOutlinedInput-root:not(:has(input:focus)):hover fieldset":
|
|
||||||
{
|
|
||||||
borderColor: error ? theme.palette.error.main : theme.palette.divider,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
inputAdornment: { sx: { ml: 0 } },
|
|
||||||
openPickerButton: {
|
|
||||||
sx: {
|
|
||||||
py: 0,
|
|
||||||
mr: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
...props.slotProps,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</LocalizationProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack spacing={theme.spacing(2)}>
|
|
||||||
{fieldLabel && <FieldLabel required={required}>{fieldLabel}</FieldLabel>}
|
|
||||||
{picker}
|
|
||||||
{helperText && (
|
|
||||||
<Typography
|
|
||||||
variant="caption"
|
|
||||||
color={error ? "error" : "text.secondary"}
|
|
||||||
>
|
|
||||||
{helperText}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import Dialog from "@mui/material/Dialog";
|
import Dialog from "@mui/material/Dialog";
|
||||||
import type { DialogProps } from "@mui/material/Dialog";
|
|
||||||
import DialogActions from "@mui/material/DialogActions";
|
import DialogActions from "@mui/material/DialogActions";
|
||||||
import DialogContent from "@mui/material/DialogContent";
|
import DialogContent from "@mui/material/DialogContent";
|
||||||
import DialogContentText from "@mui/material/DialogContentText";
|
import DialogContentText from "@mui/material/DialogContentText";
|
||||||
@@ -7,7 +6,6 @@ import DialogTitle from "@mui/material/DialogTitle";
|
|||||||
import { Button } from "@/Components/v2/inputs";
|
import { Button } from "@/Components/v2/inputs";
|
||||||
import { typographyLevels } from "@/Utils/Theme/v2Palette";
|
import { typographyLevels } from "@/Utils/Theme/v2Palette";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import type { ReactNode } from "react";
|
|
||||||
|
|
||||||
export const DialogInput = ({
|
export const DialogInput = ({
|
||||||
open,
|
open,
|
||||||
@@ -18,11 +16,6 @@ export const DialogInput = ({
|
|||||||
confirmColor = "primary",
|
confirmColor = "primary",
|
||||||
cancelColor = "error",
|
cancelColor = "error",
|
||||||
loading = false,
|
loading = false,
|
||||||
cancelText,
|
|
||||||
confirmText,
|
|
||||||
children,
|
|
||||||
maxWidth,
|
|
||||||
fullWidth = false,
|
|
||||||
}: {
|
}: {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -32,23 +25,13 @@ export const DialogInput = ({
|
|||||||
confirmColor?: "error" | "primary";
|
confirmColor?: "error" | "primary";
|
||||||
cancelColor?: "error" | "primary";
|
cancelColor?: "error" | "primary";
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
cancelText?: string;
|
|
||||||
confirmText?: string;
|
|
||||||
children?: ReactNode;
|
|
||||||
maxWidth?: DialogProps["maxWidth"];
|
|
||||||
fullWidth?: boolean;
|
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog open={open}>
|
||||||
open={open}
|
<DialogTitle sx={{ fontSize: typographyLevels.l }}>{title}</DialogTitle>
|
||||||
maxWidth={maxWidth}
|
|
||||||
fullWidth={fullWidth}
|
|
||||||
>
|
|
||||||
{title && <DialogTitle sx={{ fontSize: typographyLevels.l }}>{title}</DialogTitle>}
|
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
{content && <DialogContentText>{content}</DialogContentText>}
|
<DialogContentText>{content}</DialogContentText>
|
||||||
{children}
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button
|
<Button
|
||||||
@@ -57,18 +40,16 @@ export const DialogInput = ({
|
|||||||
color={cancelColor}
|
color={cancelColor}
|
||||||
onClick={onCancel}
|
onClick={onCancel}
|
||||||
>
|
>
|
||||||
{cancelText ?? t("common.buttons.cancel")}
|
{t("common.buttons.cancel")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
loading={loading}
|
||||||
|
variant="contained"
|
||||||
|
color={confirmColor}
|
||||||
|
onClick={onConfirm}
|
||||||
|
>
|
||||||
|
{t("common.buttons.confirm")}
|
||||||
</Button>
|
</Button>
|
||||||
{onConfirm && (
|
|
||||||
<Button
|
|
||||||
loading={loading}
|
|
||||||
variant="contained"
|
|
||||||
color={confirmColor}
|
|
||||||
onClick={onConfirm}
|
|
||||||
>
|
|
||||||
{confirmText ?? t("common.buttons.confirm")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ interface FieldLabelProps {
|
|||||||
|
|
||||||
export const FieldLabel = ({ children, required = false, htmlFor }: FieldLabelProps) => {
|
export const FieldLabel = ({ children, required = false, htmlFor }: FieldLabelProps) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
if (children === " ") {
|
|
||||||
children = "\u00A0";
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<Typography
|
<Typography
|
||||||
component="label"
|
component="label"
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
import { Box, Stack, Typography, IconButton } from "@mui/material";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import { Upload, X } from "lucide-react";
|
|
||||||
import { useState, useRef, useCallback } from "react";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
interface FileObject {
|
|
||||||
src: string;
|
|
||||||
name: string;
|
|
||||||
file: File;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ImageUploadProps {
|
|
||||||
src?: string;
|
|
||||||
onChange?: (file: FileObject | undefined) => void;
|
|
||||||
maxSize?: number;
|
|
||||||
accept?: string[];
|
|
||||||
error?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ImageUpload = ({
|
|
||||||
src,
|
|
||||||
onChange,
|
|
||||||
maxSize = 3 * 1024 * 1024,
|
|
||||||
accept = ["jpg", "jpeg", "png"],
|
|
||||||
error,
|
|
||||||
}: ImageUploadProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const inputRef = useRef<HTMLInputElement>(null);
|
|
||||||
const [isDragging, setIsDragging] = useState(false);
|
|
||||||
const [localError, setLocalError] = useState<string | null>(null);
|
|
||||||
const [preview, setPreview] = useState<FileObject | null>(null);
|
|
||||||
|
|
||||||
const handleFile = useCallback(
|
|
||||||
(file: File | undefined) => {
|
|
||||||
if (!file) return;
|
|
||||||
const isValidType = accept.some((type) => file.type.includes(type));
|
|
||||||
const isValidSize = file.size <= maxSize;
|
|
||||||
if (!isValidType) {
|
|
||||||
setLocalError(t("common.errors.invalidFileFormat"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!isValidSize) {
|
|
||||||
setLocalError(t("common.errors.invalidFileSize"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setLocalError(null);
|
|
||||||
const fileObj: FileObject = {
|
|
||||||
src: URL.createObjectURL(file),
|
|
||||||
name: file.name,
|
|
||||||
file,
|
|
||||||
};
|
|
||||||
setPreview(fileObj);
|
|
||||||
onChange?.(fileObj);
|
|
||||||
},
|
|
||||||
[maxSize, accept, onChange, t]
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleClear = () => {
|
|
||||||
setPreview(null);
|
|
||||||
setLocalError(null);
|
|
||||||
onChange?.(undefined);
|
|
||||||
if (inputRef.current) inputRef.current.value = "";
|
|
||||||
};
|
|
||||||
|
|
||||||
const displaySrc = src || preview?.src;
|
|
||||||
const displayError = localError || error;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack sx={{ width: "100%", maxWidth: 500 }}>
|
|
||||||
{displaySrc ? (
|
|
||||||
<Stack
|
|
||||||
alignItems="center"
|
|
||||||
gap={1}
|
|
||||||
>
|
|
||||||
<Box
|
|
||||||
component="img"
|
|
||||||
src={displaySrc}
|
|
||||||
alt="Preview"
|
|
||||||
sx={{ maxWidth: 250, maxHeight: 250, objectFit: "contain", borderRadius: 1 }}
|
|
||||||
/>
|
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
onClick={handleClear}
|
|
||||||
sx={{ color: theme.palette.error.main }}
|
|
||||||
>
|
|
||||||
<X size={18} />
|
|
||||||
</IconButton>
|
|
||||||
</Stack>
|
|
||||||
) : (
|
|
||||||
<Stack
|
|
||||||
onDragOver={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
setIsDragging(true);
|
|
||||||
}}
|
|
||||||
onDragLeave={() => setIsDragging(false)}
|
|
||||||
onDrop={(e) => {
|
|
||||||
e.preventDefault();
|
|
||||||
setIsDragging(false);
|
|
||||||
handleFile(e.dataTransfer.files?.[0]);
|
|
||||||
}}
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="center"
|
|
||||||
gap={1}
|
|
||||||
sx={{
|
|
||||||
position: "relative",
|
|
||||||
width: "100%",
|
|
||||||
minHeight: 150,
|
|
||||||
border: "2px dashed",
|
|
||||||
borderRadius: 1,
|
|
||||||
borderColor: isDragging ? theme.palette.primary.main : theme.palette.divider,
|
|
||||||
backgroundColor: isDragging ? theme.palette.action.hover : "transparent",
|
|
||||||
transition: "0.2s",
|
|
||||||
cursor: "pointer",
|
|
||||||
"&:hover": {
|
|
||||||
borderColor: theme.palette.primary.main,
|
|
||||||
backgroundColor: theme.palette.action.hover,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
ref={inputRef}
|
|
||||||
type="file"
|
|
||||||
accept={accept.map((ext) => `.${ext}`).join(",")}
|
|
||||||
onChange={(e) => handleFile(e.target.files?.[0])}
|
|
||||||
style={{ position: "absolute", inset: 0, opacity: 0, cursor: "pointer" }}
|
|
||||||
/>
|
|
||||||
<Upload size={24} />
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
color="text.secondary"
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
variant="body2"
|
|
||||||
color="primary"
|
|
||||||
fontWeight={500}
|
|
||||||
>
|
|
||||||
{t("common.imageUpload.clickToUpload")}
|
|
||||||
</Typography>{" "}
|
|
||||||
{t("common.imageUpload.orDragAndDrop")}
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
variant="caption"
|
|
||||||
color="text.disabled"
|
|
||||||
>
|
|
||||||
{accept.join(", ").toUpperCase()} • {t("common.imageUpload.maxSize")}{" "}
|
|
||||||
{Math.round(maxSize / 1024 / 1024)}MB
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
{displayError && (
|
|
||||||
<Typography
|
|
||||||
variant="caption"
|
|
||||||
color="error"
|
|
||||||
sx={{ mt: 1 }}
|
|
||||||
>
|
|
||||||
{displayError}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,100 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
|
||||||
import { Select } from "@/Components/v2/inputs";
|
|
||||||
import "flag-icons/css/flag-icons.min.css";
|
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import { setLanguage } from "@/Features/UI/uiSlice";
|
|
||||||
import type { RootState } from "@/Types/state";
|
|
||||||
|
|
||||||
const langMap: Record<string, string> = {
|
|
||||||
cs: "cz",
|
|
||||||
ja: "jp",
|
|
||||||
uk: "ua",
|
|
||||||
vi: "vn",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const LanguageSelector = () => {
|
|
||||||
const { i18n } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const { language = "en" } = useSelector((state: RootState) => state.ui);
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
const handleChange = (event: any) => {
|
|
||||||
const newLang = event.target.value;
|
|
||||||
dispatch(setLanguage(newLang));
|
|
||||||
};
|
|
||||||
|
|
||||||
const languages = Object.keys(i18n.options.resources || {});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Select
|
|
||||||
value={language}
|
|
||||||
onChange={handleChange}
|
|
||||||
size="small"
|
|
||||||
// sx={{
|
|
||||||
// minWidth: 80,
|
|
||||||
// "& .MuiSelect-select": {
|
|
||||||
// display: "flex",
|
|
||||||
// alignItems: "center",
|
|
||||||
// justifyContent: "center",
|
|
||||||
// },
|
|
||||||
// "& .MuiSelect-icon": {
|
|
||||||
// alignSelf: "center",
|
|
||||||
// },
|
|
||||||
// }}
|
|
||||||
>
|
|
||||||
{languages.map((lang) => {
|
|
||||||
let parsedLang = lang === "en" ? "gb" : lang;
|
|
||||||
|
|
||||||
if (parsedLang.includes("-")) {
|
|
||||||
parsedLang = parsedLang.split("-")[1].toLowerCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
parsedLang = langMap[parsedLang] || parsedLang;
|
|
||||||
|
|
||||||
const flag = parsedLang ? `fi fi-${parsedLang}` : null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<MenuItem
|
|
||||||
key={lang}
|
|
||||||
value={lang}
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "center",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
spacing={theme.spacing(2)}
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="center"
|
|
||||||
>
|
|
||||||
<Box
|
|
||||||
component="span"
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{flag && <span className={flag} />}
|
|
||||||
</Box>
|
|
||||||
<Box
|
|
||||||
component="span"
|
|
||||||
sx={{ textTransform: "uppercase" }}
|
|
||||||
>
|
|
||||||
{lang}
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
</MenuItem>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</Select>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LanguageSelector;
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
import Radio from "@mui/material/Radio";
|
|
||||||
import type { RadioProps } from "@mui/material/Radio";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import { Circle, CircleDot } from "lucide-react";
|
|
||||||
import FormControlLabel from "@mui/material/FormControlLabel";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
|
|
||||||
interface RadioInputProps extends RadioProps {}
|
|
||||||
|
|
||||||
export const RadioInput = ({ ...props }: RadioInputProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<Radio
|
|
||||||
{...props}
|
|
||||||
icon={
|
|
||||||
<Circle
|
|
||||||
size={16}
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
checkedIcon={
|
|
||||||
<CircleDot
|
|
||||||
size={14}
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
sx={{
|
|
||||||
padding: 0,
|
|
||||||
mt: theme.spacing(0.5),
|
|
||||||
color: theme.palette.text.secondary,
|
|
||||||
"&.Mui-checked": {
|
|
||||||
color: theme.palette.primary.main,
|
|
||||||
"& svg circle": {
|
|
||||||
fill: theme.palette.primary.main,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"& .MuiSvgIcon-root": {
|
|
||||||
fontSize: 16,
|
|
||||||
},
|
|
||||||
"& svg": {
|
|
||||||
stroke: "currentColor",
|
|
||||||
},
|
|
||||||
"& svg path, & svg line, & svg polyline, & svg rect, & svg circle": {
|
|
||||||
stroke: "currentColor",
|
|
||||||
fill: "none",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const RadioWithDescription = ({
|
|
||||||
label,
|
|
||||||
description,
|
|
||||||
...props
|
|
||||||
}: RadioInputProps & { label: string; description: string }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<FormControlLabel
|
|
||||||
control={<RadioInput {...props} />}
|
|
||||||
label={
|
|
||||||
<>
|
|
||||||
<Typography component="p">{label}</Typography>
|
|
||||||
<Typography
|
|
||||||
component="h6"
|
|
||||||
color={theme.palette.text.secondary}
|
|
||||||
>
|
|
||||||
{description}
|
|
||||||
</Typography>
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
sx={{
|
|
||||||
alignItems: "flex-start",
|
|
||||||
p: theme.spacing(2.5),
|
|
||||||
m: theme.spacing(-2.5),
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
|
|
||||||
"&:hover": {
|
|
||||||
backgroundColor: theme.palette.background.paper,
|
|
||||||
},
|
|
||||||
"& .MuiButtonBase-root": {
|
|
||||||
p: 0,
|
|
||||||
mr: theme.spacing(6),
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import Select from "@mui/material/Select";
|
import Select from "@mui/material/Select";
|
||||||
import type { SelectProps } from "@mui/material/Select";
|
import React from "react";
|
||||||
import React, { forwardRef } from "react";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import type { SelectProps } from "@mui/material/Select";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { FieldLabel } from "./FieldLabel";
|
import { FieldLabel } from "./FieldLabel";
|
||||||
import { ChevronDown } from "lucide-react";
|
import { ChevronDown } from "lucide-react";
|
||||||
@@ -14,15 +14,18 @@ interface SelectInputProps<T> extends Omit<SelectProps<T>, "label"> {
|
|||||||
placeholderColor?: string;
|
placeholderColor?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SelectInputInner = <T,>(
|
export const SelectInput = <T,>({
|
||||||
{ fieldLabel, required, placeholder, placeholderColor, ...props }: SelectInputProps<T>,
|
fieldLabel,
|
||||||
ref: React.ForwardedRef<HTMLDivElement>
|
required,
|
||||||
) => {
|
placeholder,
|
||||||
|
placeholderColor,
|
||||||
|
...props
|
||||||
|
}: SelectInputProps<T>) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const emptyPlaceholderColor = placeholderColor || theme.palette.text.disabled;
|
const emptyPlaceholderColor = placeholderColor || theme.palette.text.disabled;
|
||||||
|
|
||||||
const renderValue = (selected: unknown) => {
|
const renderValue = (selected: any) => {
|
||||||
const isMultiple = Boolean((props as { multiple?: boolean }).multiple);
|
const isMultiple = Boolean((props as any).multiple);
|
||||||
const isEmpty = isMultiple
|
const isEmpty = isMultiple
|
||||||
? !Array.isArray(selected) || selected.length === 0
|
? !Array.isArray(selected) || selected.length === 0
|
||||||
: selected === undefined || selected === null || selected === "";
|
: selected === undefined || selected === null || selected === "";
|
||||||
@@ -36,7 +39,7 @@ const SelectInputInner = <T,>(
|
|||||||
const capitalized = items.map(
|
const capitalized = items.map(
|
||||||
(item) => item.charAt(0).toUpperCase() + item.slice(1)
|
(item) => item.charAt(0).toUpperCase() + item.slice(1)
|
||||||
);
|
);
|
||||||
return <Typography>{capitalized.join(" | ")}</Typography>;
|
return (<Typography>{capitalized.join(" | ")}</Typography>) as any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodes = React.Children.toArray(props.children as React.ReactNode);
|
const nodes = React.Children.toArray(props.children as React.ReactNode);
|
||||||
@@ -56,7 +59,6 @@ const SelectInputInner = <T,>(
|
|||||||
const select = (
|
const select = (
|
||||||
<Select<T>
|
<Select<T>
|
||||||
{...props}
|
{...props}
|
||||||
ref={ref}
|
|
||||||
displayEmpty
|
displayEmpty
|
||||||
renderValue={renderValue}
|
renderValue={renderValue}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -72,12 +74,6 @@ const SelectInputInner = <T,>(
|
|||||||
)}
|
)}
|
||||||
sx={{
|
sx={{
|
||||||
height: "34px",
|
height: "34px",
|
||||||
"& .MuiSelect-select": {
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
height: "100%",
|
|
||||||
boxSizing: "border-box",
|
|
||||||
},
|
|
||||||
"& .MuiSelect-icon": {
|
"& .MuiSelect-icon": {
|
||||||
right: theme.spacing(3),
|
right: theme.spacing(3),
|
||||||
},
|
},
|
||||||
@@ -104,7 +100,3 @@ const SelectInputInner = <T,>(
|
|||||||
|
|
||||||
return select;
|
return select;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SelectInput = forwardRef(SelectInputInner) as <T>(
|
|
||||||
props: SelectInputProps<T> & { ref?: React.ForwardedRef<HTMLDivElement> }
|
|
||||||
) => React.ReactElement;
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import { forwardRef } from "react";
|
|
||||||
import Slider from "@mui/material/Slider";
|
|
||||||
import type { SliderProps } from "@mui/material/Slider";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import { FieldLabel } from "./FieldLabel";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import type { ResponsiveStyleValue } from "@mui/system";
|
|
||||||
|
|
||||||
interface SliderInputProps extends SliderProps {
|
|
||||||
sx?: SliderProps["sx"];
|
|
||||||
showValue?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SliderInput = forwardRef<HTMLSpanElement, SliderInputProps>(
|
|
||||||
({ sx, showValue = false, ...props }, ref) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const additionalSx = Array.isArray(sx) ? sx : sx ? [sx] : [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
gap={theme.spacing(8)}
|
|
||||||
direction={"row"}
|
|
||||||
alignItems={"center"}
|
|
||||||
>
|
|
||||||
{showValue && <Typography>{props.value}</Typography>}
|
|
||||||
<Slider
|
|
||||||
{...props}
|
|
||||||
ref={ref}
|
|
||||||
sx={[
|
|
||||||
{
|
|
||||||
"& .MuiSlider-track": {
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
border: "none",
|
|
||||||
},
|
|
||||||
"& .MuiSlider-rail": {
|
|
||||||
backgroundColor: theme.palette.grey[300],
|
|
||||||
opacity: 1,
|
|
||||||
},
|
|
||||||
"& .MuiSlider-thumb": {
|
|
||||||
backgroundColor: "#fff",
|
|
||||||
"&:hover, &.Mui-focusVisible": {
|
|
||||||
boxShadow: `0 0 0 8px ${theme.palette.primary.main}20`,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
"& .MuiSlider-valueLabel": {
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
...additionalSx,
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
interface SliderWithLabelProps extends SliderProps {
|
|
||||||
fieldLabel?: string;
|
|
||||||
required?: boolean;
|
|
||||||
showValue?: boolean;
|
|
||||||
sliderMaxWidth?: ResponsiveStyleValue<number | string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SliderWithLabel = forwardRef<HTMLSpanElement, SliderWithLabelProps>(
|
|
||||||
(
|
|
||||||
{ fieldLabel, required, showValue = true, value, sliderMaxWidth = "100%", ...props },
|
|
||||||
ref
|
|
||||||
) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const labelText = fieldLabel;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack spacing={theme.spacing(2)}>
|
|
||||||
{fieldLabel && <FieldLabel required={required}>{labelText}</FieldLabel>}
|
|
||||||
<Box maxWidth={sliderMaxWidth}>
|
|
||||||
<SliderInput
|
|
||||||
{...props}
|
|
||||||
showValue={showValue}
|
|
||||||
value={value}
|
|
||||||
ref={ref}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import { forwardRef } from "react";
|
|
||||||
import Switch from "@mui/material/Switch";
|
|
||||||
import type { SwitchProps } from "@mui/material/Switch";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
|
|
||||||
interface SwitchComponentProps extends SwitchProps {
|
|
||||||
dualOption?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SwitchComponent = forwardRef<HTMLInputElement, SwitchComponentProps>(
|
|
||||||
function SwitchComponent({ sx, dualOption = false, ...props }, ref) {
|
|
||||||
const theme = useTheme();
|
|
||||||
const additionalSx = Array.isArray(sx) ? sx : sx ? [sx] : [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Switch
|
|
||||||
{...props}
|
|
||||||
slotProps={{
|
|
||||||
input: {
|
|
||||||
ref: ref,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
sx={[
|
|
||||||
{
|
|
||||||
"& .MuiSwitch-switchBase": {
|
|
||||||
"&.Mui-checked": {
|
|
||||||
color: "#E0E0E0",
|
|
||||||
"& + .MuiSwitch-track": {
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
opacity: 1,
|
|
||||||
border: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
...(dualOption && {
|
|
||||||
"& .MuiSwitch-track": {
|
|
||||||
backgroundColor: theme.palette.primary.main,
|
|
||||||
opacity: 1,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
...additionalSx,
|
|
||||||
]}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import IconButton from "@mui/material/IconButton";
|
|
||||||
|
|
||||||
import { Moon, Sun } from "lucide-react";
|
|
||||||
|
|
||||||
import { setMode } from "@/Features/UI/uiSlice.js";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
|
||||||
import type { RootState } from "@/Types/state";
|
|
||||||
|
|
||||||
export const SwitchTheme = () => {
|
|
||||||
const mode = useSelector((state: RootState) => state.ui.mode);
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const handleChange = () => {
|
|
||||||
dispatch(setMode(mode === "light" ? "dark" : "light"));
|
|
||||||
};
|
|
||||||
return (
|
|
||||||
<IconButton
|
|
||||||
id="theme-toggle"
|
|
||||||
onClick={handleChange}
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
"& svg": {
|
|
||||||
transition: "stroke 0.2s ease",
|
|
||||||
},
|
|
||||||
"&:hover svg path, &:hover svg line, &:hover svg polyline, &:hover svg rect, &:hover svg circle":
|
|
||||||
{
|
|
||||||
stroke: theme.palette.primary.main,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{mode === "light" ? (
|
|
||||||
<Moon
|
|
||||||
size={16}
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<Sun
|
|
||||||
size={16}
|
|
||||||
strokeWidth={1.5}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</IconButton>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
import { MobileTimePicker } from "@mui/x-date-pickers/MobileTimePicker";
|
|
||||||
import type { MobileTimePickerProps } from "@mui/x-date-pickers/MobileTimePicker";
|
|
||||||
import type { Dayjs } from "dayjs";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import { FieldLabel } from "./FieldLabel";
|
|
||||||
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
|
||||||
import { LocalizationProvider } from "@mui/x-date-pickers";
|
|
||||||
|
|
||||||
interface TimePickerComponentProps extends Omit<MobileTimePickerProps<Dayjs>, "label"> {
|
|
||||||
fieldLabel?: string;
|
|
||||||
required?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TimePickerComponent = ({
|
|
||||||
fieldLabel,
|
|
||||||
required,
|
|
||||||
...props
|
|
||||||
}: TimePickerComponentProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const picker = (
|
|
||||||
<LocalizationProvider dateAdapter={AdapterDayjs}>
|
|
||||||
<MobileTimePicker
|
|
||||||
{...props}
|
|
||||||
slotProps={{
|
|
||||||
field: {
|
|
||||||
sx: {
|
|
||||||
width: "fit-content",
|
|
||||||
"& input": {
|
|
||||||
minHeight: 34,
|
|
||||||
p: 0,
|
|
||||||
px: theme.spacing(5),
|
|
||||||
},
|
|
||||||
"& fieldset": {
|
|
||||||
borderColor: theme.palette.divider,
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
},
|
|
||||||
"&:not(:has(.Mui-disabled)):not(:has(.Mui-error)) .MuiOutlinedInput-root:not(:has(input:focus)):hover fieldset":
|
|
||||||
{
|
|
||||||
borderColor: theme.palette.divider,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
...props.slotProps,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</LocalizationProvider>
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fieldLabel) {
|
|
||||||
return (
|
|
||||||
<Stack spacing={theme.spacing(2)}>
|
|
||||||
<FieldLabel required={required}>{fieldLabel}</FieldLabel>
|
|
||||||
{picker}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return picker;
|
|
||||||
};
|
|
||||||
@@ -9,12 +9,3 @@ export {
|
|||||||
ToggleButtonGroupInput as ToggleButtonGroup,
|
ToggleButtonGroupInput as ToggleButtonGroup,
|
||||||
} from "./ToggleButton";
|
} from "./ToggleButton";
|
||||||
export { DialogInput as Dialog } from "./Dialog";
|
export { DialogInput as Dialog } from "./Dialog";
|
||||||
export * from "./Radio";
|
|
||||||
export * from "./Switch";
|
|
||||||
export * from "./Slider";
|
|
||||||
export * from "./ImageUpload";
|
|
||||||
export * from "./ColorPicker";
|
|
||||||
export { DatePickerComponent as DatePicker } from "./DatePicker";
|
|
||||||
export { TimePickerComponent as TimePicker } from "./TimePicker";
|
|
||||||
export * from "./LanguageSelector";
|
|
||||||
export * from "./SwitchTheme";
|
|
||||||
@@ -6,12 +6,11 @@ import useMediaQuery from "@mui/material/useMediaQuery";
|
|||||||
import type { MonitorType } from "@/Types/Monitor";
|
import type { MonitorType } from "@/Types/Monitor";
|
||||||
import { Typography, useTheme } from "@mui/material";
|
import { Typography, useTheme } from "@mui/material";
|
||||||
|
|
||||||
const types = ["http", "ping", "port", "docker", "game"];
|
const types = ["http", "ping", "port", "docker"];
|
||||||
const statuses = ["up", "down"];
|
const statuses = ["up", "down"];
|
||||||
const states = ["active", "paused"];
|
const states = ["active", "paused"];
|
||||||
|
|
||||||
export const ControlsFilter = ({
|
export const ControlsFilter = ({
|
||||||
showTypes = true,
|
|
||||||
selectedTypes,
|
selectedTypes,
|
||||||
setSelectedTypes,
|
setSelectedTypes,
|
||||||
selectedStatus,
|
selectedStatus,
|
||||||
@@ -20,9 +19,8 @@ export const ControlsFilter = ({
|
|||||||
setSelectedState,
|
setSelectedState,
|
||||||
onClearFilters,
|
onClearFilters,
|
||||||
}: {
|
}: {
|
||||||
showTypes?: boolean;
|
selectedTypes: MonitorType[];
|
||||||
selectedTypes?: MonitorType[];
|
setSelectedTypes: React.Dispatch<React.SetStateAction<MonitorType[]>>;
|
||||||
setSelectedTypes?: React.Dispatch<React.SetStateAction<MonitorType[]>>;
|
|
||||||
selectedStatus: string;
|
selectedStatus: string;
|
||||||
setSelectedStatus: React.Dispatch<React.SetStateAction<string>>;
|
setSelectedStatus: React.Dispatch<React.SetStateAction<string>>;
|
||||||
selectedState: string;
|
selectedState: string;
|
||||||
@@ -32,29 +30,27 @@ export const ControlsFilter = ({
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
||||||
const isFilterActive =
|
const isFilterActive =
|
||||||
(selectedTypes?.length ?? 0) > 0 || selectedStatus !== "" || selectedState !== "";
|
selectedTypes.length > 0 || selectedStatus !== "" || selectedState !== "";
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
direction={isSmall ? "column" : "row"}
|
direction={isSmall ? "column" : "row"}
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
{showTypes && setSelectedTypes && (
|
<Select
|
||||||
<Select
|
multiple
|
||||||
multiple
|
placeholder="Type"
|
||||||
placeholder="Type"
|
value={selectedTypes}
|
||||||
value={selectedTypes ?? []}
|
onChange={(e) => setSelectedTypes(e.target.value as MonitorType[])}
|
||||||
onChange={(e) => setSelectedTypes(e.target.value as MonitorType[])}
|
>
|
||||||
>
|
{types.map((type) => (
|
||||||
{types.map((type) => (
|
<MenuItem
|
||||||
<MenuItem
|
key={type}
|
||||||
key={type}
|
value={type}
|
||||||
value={type}
|
>
|
||||||
>
|
<Typography textTransform={"capitalize"}>{type}</Typography>
|
||||||
<Typography textTransform={"capitalize"}>{type}</Typography>
|
</MenuItem>
|
||||||
</MenuItem>
|
))}
|
||||||
))}
|
</Select>
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
<Select
|
<Select
|
||||||
placeholder="Status"
|
placeholder="Status"
|
||||||
value={selectedStatus}
|
value={selectedStatus}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { StatBox } from "@/Components/v2/design-elements";
|
import { StatBox } from "@/Components/v2/design-elements";
|
||||||
|
|
||||||
import prettyMilliseconds from "pretty-ms";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import type { MonitorStats, Monitor } from "@/Types/Monitor";
|
import type { MonitorStats, Monitor } from "@/Types/Monitor";
|
||||||
|
import { getHumanReadableDuration } from "@/Utils/timeUtilsLegacy.js";
|
||||||
import { getStatusPalette } from "@/Utils/MonitorUtils";
|
import { getStatusPalette } from "@/Utils/MonitorUtils";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
@@ -32,16 +32,11 @@ export const MonitorStatBoxes = ({
|
|||||||
|
|
||||||
// Determine time since last check
|
// Determine time since last check
|
||||||
const timeOfLastCheck = monitorStats?.lastCheckTimestamp || 0;
|
const timeOfLastCheck = monitorStats?.lastCheckTimestamp || 0;
|
||||||
const timeSinceLastCheck = Date.now() - timeOfLastCheck || 0;
|
const timeSinceLastCheck = Date.now() - timeOfLastCheck;
|
||||||
|
|
||||||
const options = {
|
const streakTime = getHumanReadableDuration(timeSinceLastFailure);
|
||||||
secondsDecimalDigits: 0,
|
|
||||||
millisecondsDecimalDigits: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
const streakTime = prettyMilliseconds(timeSinceLastFailure, options);
|
const lastCheckTime = getHumanReadableDuration(timeSinceLastCheck);
|
||||||
|
|
||||||
const lastCheckTime = prettyMilliseconds(timeSinceLastCheck, options);
|
|
||||||
const palette = getStatusPalette(monitor?.status);
|
const palette = getStatusPalette(monitor?.status);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -60,7 +55,7 @@ export const MonitorStatBoxes = ({
|
|||||||
/>
|
/>
|
||||||
<StatBox
|
<StatBox
|
||||||
title={t("pages.common.monitors.statBoxes.lastResponseTime")}
|
title={t("pages.common.monitors.statBoxes.lastResponseTime")}
|
||||||
subtitle={prettyMilliseconds(monitorStats?.lastResponseTime ?? 0)}
|
subtitle={monitorStats?.lastResponseTime + " ms"}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{monitor?.type === "http" && (
|
{monitor?.type === "http" && (
|
||||||
|
|||||||
@@ -1,206 +0,0 @@
|
|||||||
import { BaseChart } from "@/Components/v2/design-elements";
|
|
||||||
import {
|
|
||||||
AreaChart,
|
|
||||||
Area,
|
|
||||||
XAxis,
|
|
||||||
YAxis,
|
|
||||||
CartesianGrid,
|
|
||||||
ResponsiveContainer,
|
|
||||||
} from "recharts";
|
|
||||||
import { Fragment, useId } from "react";
|
|
||||||
import { XTick } from "@/Components/v2/monitors";
|
|
||||||
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import type { HardwareCheckStats } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
const AREA_COLORS = [
|
|
||||||
// Blues
|
|
||||||
"#3182bd", // Deep blue
|
|
||||||
"#6baed6", // Medium blue
|
|
||||||
"#9ecae1", // Light blue
|
|
||||||
|
|
||||||
// Greens
|
|
||||||
"#74c476", // Soft green
|
|
||||||
"#a1d99b", // Light green
|
|
||||||
"#c7e9c0", // Pale green
|
|
||||||
|
|
||||||
// Oranges
|
|
||||||
"#fdae6b", // Warm orange
|
|
||||||
"#fdd0a2", // Light orange
|
|
||||||
"#feedde", // Pale orange
|
|
||||||
|
|
||||||
// Purples
|
|
||||||
"#9467bd", // Lavender
|
|
||||||
"#a55194", // Deep magenta
|
|
||||||
"#c994c7", // Soft magenta
|
|
||||||
|
|
||||||
// Reds
|
|
||||||
"#ff9896", // Soft red
|
|
||||||
"#de2d26", // Deep red
|
|
||||||
"#fc9272", // Medium red
|
|
||||||
|
|
||||||
// Cyans/Teals
|
|
||||||
"#17becf", // Cyan
|
|
||||||
"#7fcdbb", // Teal
|
|
||||||
"#a1dab4", // Light teal
|
|
||||||
|
|
||||||
// Yellows
|
|
||||||
"#fec44f", // Mustard
|
|
||||||
"#fee391", // Light yellow
|
|
||||||
"#ffffd4", // Pale yellow
|
|
||||||
|
|
||||||
// Additional colors
|
|
||||||
"#e377c2", // Soft pink
|
|
||||||
"#bcbd22", // Olive
|
|
||||||
"#2ca02c", // Vibrant green
|
|
||||||
];
|
|
||||||
|
|
||||||
const createGradient = ({
|
|
||||||
id,
|
|
||||||
startColor,
|
|
||||||
endColor,
|
|
||||||
startOpacity = 0.8,
|
|
||||||
endOpacity = 0,
|
|
||||||
direction = "vertical",
|
|
||||||
}: {
|
|
||||||
id: string;
|
|
||||||
startColor: string;
|
|
||||||
endColor: string;
|
|
||||||
startOpacity?: number;
|
|
||||||
endOpacity?: number;
|
|
||||||
direction?: "vertical" | "horizontal";
|
|
||||||
}) => (
|
|
||||||
<defs>
|
|
||||||
<linearGradient
|
|
||||||
id={id}
|
|
||||||
x1={direction === "vertical" ? "0" : "0"}
|
|
||||||
y1={direction === "vertical" ? "0" : "0"}
|
|
||||||
x2={direction === "vertical" ? "0" : "1"}
|
|
||||||
y2={direction === "vertical" ? "1" : "0"}
|
|
||||||
>
|
|
||||||
<stop
|
|
||||||
offset="0%"
|
|
||||||
stopColor={startColor}
|
|
||||||
stopOpacity={startOpacity}
|
|
||||||
/>
|
|
||||||
<stop
|
|
||||||
offset="100%"
|
|
||||||
stopColor={endColor}
|
|
||||||
stopOpacity={endOpacity}
|
|
||||||
/>
|
|
||||||
</linearGradient>
|
|
||||||
</defs>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const HistogramInfrastructure = ({
|
|
||||||
dateRange,
|
|
||||||
title,
|
|
||||||
type,
|
|
||||||
idx: _idx,
|
|
||||||
checks,
|
|
||||||
xKey,
|
|
||||||
yDomain,
|
|
||||||
dataKeys,
|
|
||||||
gradient = false,
|
|
||||||
gradientDirection = "vertical",
|
|
||||||
gradientStartColor,
|
|
||||||
gradientEndColor,
|
|
||||||
strokeColor,
|
|
||||||
fillColor,
|
|
||||||
yAxisFormatter,
|
|
||||||
}: {
|
|
||||||
dateRange: string;
|
|
||||||
title: string;
|
|
||||||
type: string;
|
|
||||||
idx: number | null;
|
|
||||||
checks: HardwareCheckStats[];
|
|
||||||
xKey: string;
|
|
||||||
yDomain?: number[];
|
|
||||||
dataKeys: string[];
|
|
||||||
gradient?: boolean;
|
|
||||||
gradientDirection?: "vertical" | "horizontal";
|
|
||||||
gradientStartColor?: string;
|
|
||||||
gradientEndColor?: string;
|
|
||||||
strokeColor: string;
|
|
||||||
fillColor?: string;
|
|
||||||
yAxisFormatter?: (value: number) => string;
|
|
||||||
}) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const uniqueId = useId();
|
|
||||||
const data = checks;
|
|
||||||
|
|
||||||
let avgTemps: { bucketDate: string; avg_temp: number | null }[] = [];
|
|
||||||
let tempYDomain: number[] = [];
|
|
||||||
if (type === "temp") {
|
|
||||||
avgTemps = data.map((check) => {
|
|
||||||
const temps = check.avgTemperature || [];
|
|
||||||
if (temps.length === 0) return { bucketDate: check.bucketDate, avg_temp: null };
|
|
||||||
const totalTemp = temps.reduce((sum, temp) => sum + (temp || 0), 0);
|
|
||||||
const avgTemp = totalTemp / temps.length;
|
|
||||||
return { bucketDate: check.bucketDate, avg_temp: avgTemp };
|
|
||||||
});
|
|
||||||
|
|
||||||
const maxTemp: number = avgTemps.reduce((max, item) => {
|
|
||||||
return item.avg_temp && item.avg_temp > max ? item.avg_temp : max;
|
|
||||||
}, 0);
|
|
||||||
|
|
||||||
tempYDomain = [0, Math.ceil((maxTemp * 1.3) / 10) * 10];
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BaseChart
|
|
||||||
icon={null}
|
|
||||||
title={title}
|
|
||||||
>
|
|
||||||
<ResponsiveContainer
|
|
||||||
width="100%"
|
|
||||||
height={200}
|
|
||||||
>
|
|
||||||
<AreaChart data={type === "temp" ? avgTemps : data}>
|
|
||||||
<XAxis
|
|
||||||
dataKey={xKey}
|
|
||||||
tick={(props) => (
|
|
||||||
<XTick
|
|
||||||
{...props}
|
|
||||||
range={dateRange}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<YAxis
|
|
||||||
domain={type === "temp" ? tempYDomain : yDomain}
|
|
||||||
tickFormatter={yAxisFormatter}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<CartesianGrid
|
|
||||||
stroke={theme.palette.divider}
|
|
||||||
strokeWidth={1}
|
|
||||||
strokeOpacity={1}
|
|
||||||
fill="transparent"
|
|
||||||
vertical={false}
|
|
||||||
/>
|
|
||||||
{dataKeys?.map((dataKey, index) => {
|
|
||||||
const gradientId = `gradient-${uniqueId}-${index}`;
|
|
||||||
return (
|
|
||||||
<Fragment key={`${dataKey}-${index}`}>
|
|
||||||
{gradient === true &&
|
|
||||||
createGradient({
|
|
||||||
id: gradientId,
|
|
||||||
startColor: gradientStartColor || AREA_COLORS[index],
|
|
||||||
endColor: gradientEndColor || "transparent",
|
|
||||||
direction: gradientDirection,
|
|
||||||
})}
|
|
||||||
<Area
|
|
||||||
key={dataKey}
|
|
||||||
type="monotone"
|
|
||||||
dataKey={dataKey}
|
|
||||||
stroke={strokeColor || AREA_COLORS[index]}
|
|
||||||
fill={gradient === true ? `url(#${gradientId})` : fillColor}
|
|
||||||
/>
|
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</AreaChart>
|
|
||||||
</ResponsiveContainer>
|
|
||||||
</BaseChart>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -8,9 +8,8 @@ import type { TooltipProps } from "recharts";
|
|||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import type { RootState } from "@/Types/state";
|
import type { RootState } from "@/Types/state";
|
||||||
|
|
||||||
interface HistogramPageSpeedScoresTooltipProps extends Partial<
|
interface HistogramPageSpeedScoresTooltipProps
|
||||||
TooltipProps<number, string>
|
extends Partial<TooltipProps<number, string>> {
|
||||||
> {
|
|
||||||
config: Record<string, ConfigItem>;
|
config: Record<string, ConfigItem>;
|
||||||
}
|
}
|
||||||
export const HistogramPageSpeedScoresTooltip = ({
|
export const HistogramPageSpeedScoresTooltip = ({
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
export * from "./ControlsFilter";
|
export * from "./ControlsFilter";
|
||||||
export * from "./MonitorStatBoxes";
|
export * from "./MonitorStatBoxes";
|
||||||
export * from "./HeaderMonitorControls";
|
|
||||||
export * from "./charts/HistogramStatus";
|
export * from "./charts/HistogramStatus";
|
||||||
export * from "./charts/RadialAvgResponse";
|
export * from "./charts/RadialAvgResponse";
|
||||||
export * from "./charts/HistogramDetails";
|
export * from "./charts/HistogramDetails";
|
||||||
@@ -10,4 +9,3 @@ export * from "./charts/PiePageSpeed";
|
|||||||
export * from "./charts/PiePageSpeedLegend";
|
export * from "./charts/PiePageSpeedLegend";
|
||||||
export * from "./charts/HistogramPageSpeedDetails";
|
export * from "./charts/HistogramPageSpeedDetails";
|
||||||
export * from "./charts/HistogramPageSpeedDetailsTooltip";
|
export * from "./charts/HistogramPageSpeedDetailsTooltip";
|
||||||
export * from "./charts/HistogramInfrastructure";
|
|
||||||
@@ -196,13 +196,6 @@ const authSlice = createSlice({
|
|||||||
state.success = true;
|
state.success = true;
|
||||||
state.msg = "Logged out successfully";
|
state.msg = "Logged out successfully";
|
||||||
},
|
},
|
||||||
setAuthState: (state, action) => {
|
|
||||||
state.isLoading = false;
|
|
||||||
state.success = action.payload.success;
|
|
||||||
state.msg = action.payload.msg;
|
|
||||||
state.authToken = action.payload.data.token;
|
|
||||||
state.user = action.payload.data.user;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
extraReducers: (builder) => {
|
extraReducers: (builder) => {
|
||||||
// Register thunk
|
// Register thunk
|
||||||
@@ -256,4 +249,4 @@ const authSlice = createSlice({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export default authSlice.reducer;
|
export default authSlice.reducer;
|
||||||
export const { clearAuthState, setAuthState } = authSlice.actions;
|
export const { clearAuthState } = authSlice.actions;
|
||||||
@@ -19,9 +19,6 @@ const initialState = {
|
|||||||
infrastructure: {
|
infrastructure: {
|
||||||
rowsPerPage: 5,
|
rowsPerPage: 5,
|
||||||
},
|
},
|
||||||
logs: {
|
|
||||||
rowsPerPage: 15,
|
|
||||||
},
|
|
||||||
sidebar: {
|
sidebar: {
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
},
|
},
|
||||||
@@ -44,10 +41,9 @@ const uiSlice = createSlice({
|
|||||||
},
|
},
|
||||||
setRowsPerPage: (state, action) => {
|
setRowsPerPage: (state, action) => {
|
||||||
const { table, value } = action.payload;
|
const { table, value } = action.payload;
|
||||||
if (!state[table]) {
|
if (state[table]) {
|
||||||
state[table] = {};
|
state[table].rowsPerPage = value;
|
||||||
}
|
}
|
||||||
state[table].rowsPerPage = value;
|
|
||||||
},
|
},
|
||||||
toggleSidebar: (state) => {
|
toggleSidebar: (state) => {
|
||||||
state.sidebar.collapsed = !state.sidebar.collapsed;
|
state.sidebar.collapsed = !state.sidebar.collapsed;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import type { SWRConfiguration } from "swr";
|
import type { SWRConfiguration } from "swr";
|
||||||
import type { AxiosRequestConfig } from "axios";
|
import type { AxiosRequestConfig } from "axios";
|
||||||
import { get, patch, post, put, deleteOp } from "@/Utils/ApiClient";
|
import { get, patch, post, deleteOp } from "@/Utils/ApiClient";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useToast } from "@/Hooks/UseToast";
|
import { useToast } from "@/Hooks/UseToast";
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ export const useGet = <T>(
|
|||||||
axiosConfig?: AxiosRequestConfig,
|
axiosConfig?: AxiosRequestConfig,
|
||||||
swrConfig?: SWRConfiguration
|
swrConfig?: SWRConfiguration
|
||||||
) => {
|
) => {
|
||||||
const { data, error, isLoading, isValidating, mutate } = useSWR<ApiResponse<T>>(
|
const { data, error, isLoading, mutate } = useSWR<ApiResponse<T>>(
|
||||||
url,
|
url,
|
||||||
(url: string) => fetcher<T>(url, axiosConfig),
|
(url: string) => fetcher<T>(url, axiosConfig),
|
||||||
swrConfig
|
swrConfig
|
||||||
@@ -30,7 +30,6 @@ export const useGet = <T>(
|
|||||||
return {
|
return {
|
||||||
data: data?.data ?? null,
|
data: data?.data ?? null,
|
||||||
isLoading,
|
isLoading,
|
||||||
isValidating,
|
|
||||||
error,
|
error,
|
||||||
refetch: mutate,
|
refetch: mutate,
|
||||||
};
|
};
|
||||||
@@ -109,42 +108,6 @@ export const usePatch = <B = any, R = any>() => {
|
|||||||
return { patch: patchFn, loading, error };
|
return { patch: patchFn, loading, error };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const usePut = <B = any, R = any>() => {
|
|
||||||
const [loading, setLoading] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const { toastError, toastSuccess } = useToast();
|
|
||||||
|
|
||||||
const putFn = async (
|
|
||||||
endpoint: string,
|
|
||||||
body?: B,
|
|
||||||
config?: AxiosRequestConfig
|
|
||||||
): Promise<ApiResponse<R> | null> => {
|
|
||||||
setLoading(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await put<ApiResponse<R>>(endpoint, body, {
|
|
||||||
...config,
|
|
||||||
headers: {
|
|
||||||
...config?.headers,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
toastSuccess(res.data?.msg || "Operation successful");
|
|
||||||
return res.data;
|
|
||||||
} catch (err: any) {
|
|
||||||
console.error(err);
|
|
||||||
const errMsg = err?.response?.data?.msg || err.message || "An error occurred";
|
|
||||||
toastError(errMsg);
|
|
||||||
setError(errMsg);
|
|
||||||
return null;
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return { put: putFn, loading, error };
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useDelete = <R = any>() => {
|
export const useDelete = <R = any>() => {
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|||||||
@@ -1,8 +1,107 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { networkService } from "../main.jsx";
|
import { networkService } from "../main.jsx";
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
import { createToast } from "../Utils/toastUtils.jsx";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useMonitorUtils } from "./useMonitorUtils.js";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
export const useFetchMonitorsWithSummary = ({ types, monitorUpdateTrigger }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [monitors, setMonitors] = useState(undefined);
|
||||||
|
const [monitorsSummary, setMonitorsSummary] = useState(undefined);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitors = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const res = await networkService.getMonitorsWithSummaryByTeamId({
|
||||||
|
types,
|
||||||
|
});
|
||||||
|
const { monitors, summary } = res?.data?.data ?? {};
|
||||||
|
setMonitors(monitors);
|
||||||
|
setMonitorsSummary(summary);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
setNetworkError(true);
|
||||||
|
createToast({
|
||||||
|
body: error.message,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitors();
|
||||||
|
}, [types, monitorUpdateTrigger]);
|
||||||
|
return [monitors, monitorsSummary, isLoading, networkError];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFetchMonitorsWithChecks = ({
|
||||||
|
types,
|
||||||
|
limit,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
filter,
|
||||||
|
field,
|
||||||
|
order,
|
||||||
|
monitorUpdateTrigger,
|
||||||
|
}) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [count, setCount] = useState(undefined);
|
||||||
|
const [monitors, setMonitors] = useState(undefined);
|
||||||
|
const [summary, setSummary] = useState(undefined);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
|
||||||
|
const theme = useTheme();
|
||||||
|
const { getMonitorWithPercentage } = useMonitorUtils();
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitors = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const res = await networkService.getMonitorsWithChecksByTeamId({
|
||||||
|
limit,
|
||||||
|
types,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
filter,
|
||||||
|
field,
|
||||||
|
order,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { count, monitors, summary } = res?.data?.data ?? {};
|
||||||
|
const mappedMonitors = monitors.map((monitor) =>
|
||||||
|
getMonitorWithPercentage(monitor, theme)
|
||||||
|
);
|
||||||
|
setSummary(summary);
|
||||||
|
setMonitors(mappedMonitors);
|
||||||
|
setCount(count || 0);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
setNetworkError(true);
|
||||||
|
createToast({
|
||||||
|
body: error.message,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitors();
|
||||||
|
}, [
|
||||||
|
field,
|
||||||
|
filter,
|
||||||
|
getMonitorWithPercentage,
|
||||||
|
limit,
|
||||||
|
order,
|
||||||
|
page,
|
||||||
|
rowsPerPage,
|
||||||
|
theme,
|
||||||
|
types,
|
||||||
|
monitorUpdateTrigger,
|
||||||
|
]);
|
||||||
|
return [summary, monitors, count, isLoading, networkError];
|
||||||
|
};
|
||||||
|
|
||||||
export const useFetchMonitorsByTeamId = ({ types, filter, updateTrigger }) => {
|
export const useFetchMonitorsByTeamId = ({ types, filter, updateTrigger }) => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [monitors, setMonitors] = useState(undefined);
|
const [monitors, setMonitors] = useState(undefined);
|
||||||
@@ -33,17 +132,225 @@ export const useFetchMonitorsByTeamId = ({ types, filter, updateTrigger }) => {
|
|||||||
return [monitors, isLoading, networkError];
|
return [monitors, isLoading, networkError];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useDeleteMonitor = () => {
|
export const useFetchStatsByMonitorId = ({
|
||||||
|
monitorId,
|
||||||
|
sortOrder,
|
||||||
|
limit,
|
||||||
|
dateRange,
|
||||||
|
numToDisplay,
|
||||||
|
normalize,
|
||||||
|
updateTrigger,
|
||||||
|
}) => {
|
||||||
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
const [audits, setAudits] = useState(undefined);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitor = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const res = await networkService.getStatsByMonitorId({
|
||||||
|
monitorId: monitorId,
|
||||||
|
sortOrder,
|
||||||
|
limit,
|
||||||
|
dateRange,
|
||||||
|
numToDisplay,
|
||||||
|
normalize,
|
||||||
|
});
|
||||||
|
setMonitor(res?.data?.data ?? undefined);
|
||||||
|
setAudits(res?.data?.data?.checks?.[0]?.audits ?? undefined);
|
||||||
|
} catch (error) {
|
||||||
|
setNetworkError(true);
|
||||||
|
createToast({ body: error.message });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitor();
|
||||||
|
}, [monitorId, dateRange, numToDisplay, normalize, sortOrder, limit, updateTrigger]);
|
||||||
|
return [monitor, audits, isLoading, networkError];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFetchMonitorGames = ({ setGames, updateTrigger }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchGames = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const res = await networkService.getMonitorGames();
|
||||||
|
setGames(res.data.data);
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: error.message });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchGames();
|
||||||
|
}, [setGames, updateTrigger]);
|
||||||
|
return [isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
useEffect(() => {
|
||||||
|
if (typeof monitorId === "undefined") {
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const fetchMonitor = async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const res = await networkService.getMonitorById({ monitorId: monitorId });
|
||||||
|
setMonitor(res.data.data);
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: error.message });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitor();
|
||||||
|
}, [monitorId, setMonitor, updateTrigger]);
|
||||||
|
return [isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFetchHardwareMonitorById = ({ monitorId, dateRange, updateTrigger }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitor = async () => {
|
||||||
|
try {
|
||||||
|
if (!monitorId) {
|
||||||
|
return { monitor: undefined, isLoading: false, networkError: undefined };
|
||||||
|
}
|
||||||
|
const response = await networkService.getHardwareDetailsByMonitorId({
|
||||||
|
monitorId: monitorId,
|
||||||
|
dateRange: dateRange,
|
||||||
|
});
|
||||||
|
setMonitor(response.data.data);
|
||||||
|
} catch (error) {
|
||||||
|
setNetworkError(true);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitor();
|
||||||
|
}, [monitorId, dateRange, updateTrigger]);
|
||||||
|
return [monitor, isLoading, networkError];
|
||||||
|
};
|
||||||
|
export const useFetchPageSpeedMonitorById = ({ monitorId, dateRange, updateTrigger }) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
const [monitorStats, setMonitorStats] = useState(undefined);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitor = async () => {
|
||||||
|
try {
|
||||||
|
if (!monitorId) {
|
||||||
|
return { monitor: undefined, isLoading: false, networkError: undefined };
|
||||||
|
}
|
||||||
|
const response = await networkService.getPageSpeedDetailsByMonitorId({
|
||||||
|
monitorId: monitorId,
|
||||||
|
dateRange: dateRange,
|
||||||
|
});
|
||||||
|
setMonitor(response.data.data.monitor);
|
||||||
|
setMonitorStats(response.data.data.monitorStats);
|
||||||
|
} catch (error) {
|
||||||
|
setNetworkError(true);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitor();
|
||||||
|
}, [monitorId, dateRange, updateTrigger]);
|
||||||
|
return [monitor, monitorStats, isLoading, networkError];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFetchUptimeMonitorById = ({ monitorId, dateRange, trigger }) => {
|
||||||
|
const [networkError, setNetworkError] = useState(false);
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [monitor, setMonitor] = useState(undefined);
|
||||||
|
const [monitorStats, setMonitorStats] = useState(undefined);
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchMonitors = async () => {
|
||||||
|
try {
|
||||||
|
const res = await networkService.getUptimeDetailsById({
|
||||||
|
monitorId: monitorId,
|
||||||
|
dateRange: dateRange,
|
||||||
|
normalize: true,
|
||||||
|
});
|
||||||
|
const { monitorData, monitorStats } = res?.data?.data ?? {};
|
||||||
|
setMonitor(monitorData);
|
||||||
|
setMonitorStats(monitorStats);
|
||||||
|
} catch (error) {
|
||||||
|
setNetworkError(true);
|
||||||
|
createToast({ body: error.message });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchMonitors();
|
||||||
|
}, [dateRange, monitorId, trigger]);
|
||||||
|
return [monitor, monitorStats, isLoading, networkError];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useCreateMonitor = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const { t } = useTranslation();
|
const navigate = useNavigate();
|
||||||
const deleteMonitor = async (monitorId, successCallback = () => {}) => {
|
const createMonitor = async ({ monitor, redirect }) => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
await networkService.deleteMonitorById({ monitorId });
|
await networkService.createMonitor({ monitor });
|
||||||
successCallback();
|
createToast({ body: "Monitor created successfully!" });
|
||||||
createToast({ body: t("monitorDeleted") });
|
if (redirect) {
|
||||||
|
navigate(redirect);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
createToast({ body: t("failedDeleteMonitor") });
|
createToast({ body: "Failed to create monitor." });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return [createMonitor, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useFetchGlobalSettings = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
const [globalSettings, setGlobalSettings] = useState(undefined);
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchGlobalSettings = async () => {
|
||||||
|
try {
|
||||||
|
const res = await networkService.getAppSettings();
|
||||||
|
setGlobalSettings(res?.data);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch global settings:", error);
|
||||||
|
createToast({ body: "Failed to load global settings" });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchGlobalSettings();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return [globalSettings, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useDeleteMonitor = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const deleteMonitor = async ({ monitor, redirect }) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.deleteMonitorById({ monitorId: monitor.id });
|
||||||
|
createToast({ body: "Monitor deleted successfully!" });
|
||||||
|
if (redirect) {
|
||||||
|
navigate(redirect);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: "Failed to delete monitor." });
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -51,24 +358,68 @@ export const useDeleteMonitor = () => {
|
|||||||
return [deleteMonitor, isLoading];
|
return [deleteMonitor, isLoading];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useUpdateMonitor = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const updateMonitor = async ({ monitor, redirect }) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const updatedFields = {
|
||||||
|
name: monitor.name,
|
||||||
|
statusWindowSize: monitor.statusWindowSize,
|
||||||
|
statusWindowThreshold: monitor.statusWindowThreshold,
|
||||||
|
description: monitor.description,
|
||||||
|
interval: monitor.interval,
|
||||||
|
notifications: monitor.notifications,
|
||||||
|
matchMethod: monitor.matchMethod,
|
||||||
|
expectedValue: monitor.expectedValue,
|
||||||
|
ignoreTlsErrors: monitor.ignoreTlsErrors,
|
||||||
|
jsonPath: monitor.jsonPath,
|
||||||
|
...((monitor.type === "port" || monitor.type === "game") && {
|
||||||
|
port: monitor.port,
|
||||||
|
}),
|
||||||
|
...(monitor.type == "game" && {
|
||||||
|
gameId: monitor.gameId,
|
||||||
|
}),
|
||||||
|
...(monitor.type === "hardware" && {
|
||||||
|
thresholds: monitor.thresholds,
|
||||||
|
secret: monitor.secret,
|
||||||
|
selectedDisks: monitor.selectedDisks,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
await networkService.updateMonitor({
|
||||||
|
monitorId: monitor.id,
|
||||||
|
updatedFields,
|
||||||
|
});
|
||||||
|
|
||||||
|
createToast({ body: "Monitor updated successfully!" });
|
||||||
|
if (redirect) {
|
||||||
|
navigate(redirect);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
createToast({ body: "Failed to update monitor." });
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return [updateMonitor, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
export const usePauseMonitor = () => {
|
export const usePauseMonitor = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(undefined);
|
||||||
const { t } = useTranslation();
|
const pauseMonitor = async ({ monitorId, triggerUpdate }) => {
|
||||||
|
|
||||||
const pauseMonitor = async (monitorId, successCallback = () => {}) => {
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const res = await networkService.pauseMonitorById({ monitorId });
|
const res = await networkService.pauseMonitorById({ monitorId });
|
||||||
successCallback();
|
createToast({
|
||||||
if (res.data.data.isActive === false) {
|
body: res.data.data.isActive
|
||||||
createToast({ body: t("monitorPaused") });
|
? "Monitor resumed successfully"
|
||||||
} else {
|
: "Monitor paused successfully",
|
||||||
createToast({ body: t("monitorResumed") });
|
});
|
||||||
}
|
triggerUpdate();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(error.message);
|
setError(error);
|
||||||
createToast({ body: t("failedPauseMonitor") });
|
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
@@ -140,7 +491,7 @@ export const useCreateBulkMonitors = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await networkService.createBulkMonitors(formData);
|
const response = await networkService.createBulkMonitors(formData);
|
||||||
return [true, response.data, null];
|
return [true, response.data, null]; // [success, data, error]
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMessage = err?.response?.data?.msg || err.message;
|
const errorMessage = err?.response?.data?.msg || err.message;
|
||||||
return [false, null, errorMessage];
|
return [false, null, errorMessage];
|
||||||
@@ -152,6 +503,39 @@ export const useCreateBulkMonitors = () => {
|
|||||||
return [createBulkMonitors, isLoading];
|
return [createBulkMonitors, isLoading];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useExportMonitors = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const exportMonitors = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const response = await networkService.exportMonitors();
|
||||||
|
|
||||||
|
// Create a download link
|
||||||
|
const url = window.URL.createObjectURL(response.data);
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.setAttribute("download", "monitors.csv");
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
link.remove();
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
|
||||||
|
createToast({ body: t("export.success") });
|
||||||
|
return [true, null];
|
||||||
|
} catch (err) {
|
||||||
|
const errorMessage = err?.response?.data?.msg || err.message;
|
||||||
|
createToast({ body: errorMessage || t("export.failed") });
|
||||||
|
return [false, errorMessage];
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [exportMonitors, isLoading];
|
||||||
|
};
|
||||||
|
|
||||||
export const useFetchJson = () => {
|
export const useFetchJson = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const fetchJson = async () => {
|
const fetchJson = async () => {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { loginSchema, type LoginFormData } from "@/Validation/login";
|
|
||||||
|
|
||||||
export const useLoginForm = () => {
|
|
||||||
return useMemo(() => {
|
|
||||||
const defaults: LoginFormData = {
|
|
||||||
email: "",
|
|
||||||
password: "",
|
|
||||||
};
|
|
||||||
|
|
||||||
return { schema: loginSchema, defaults };
|
|
||||||
}, []);
|
|
||||||
};
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import dayjs from "dayjs";
|
|
||||||
import {
|
|
||||||
maintenanceWindowSchema,
|
|
||||||
repeatOptions,
|
|
||||||
type MaintenanceWindowFormData,
|
|
||||||
} from "@/Validation/maintenanceWindow";
|
|
||||||
import type { MaintenanceWindow } from "@/Types/MaintenanceWindow";
|
|
||||||
|
|
||||||
interface UseMaintenanceWindowFormOptions {
|
|
||||||
data?: MaintenanceWindow | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getRepeatId = (repeatMs: number): string => {
|
|
||||||
const option = repeatOptions.find((opt) => opt.value === repeatMs);
|
|
||||||
return option?.id ?? "none";
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useMaintenanceWindowForm = ({
|
|
||||||
data = null,
|
|
||||||
}: UseMaintenanceWindowFormOptions = {}) => {
|
|
||||||
return useMemo(() => {
|
|
||||||
let defaults: MaintenanceWindowFormData;
|
|
||||||
|
|
||||||
if (data) {
|
|
||||||
const startDate = dayjs(data.start);
|
|
||||||
|
|
||||||
defaults = {
|
|
||||||
name: data.name,
|
|
||||||
repeat: getRepeatId(data.repeat),
|
|
||||||
startDate: startDate.format("YYYY-MM-DD"),
|
|
||||||
startTime: startDate.format("HH:mm"),
|
|
||||||
duration: data.duration ?? 0,
|
|
||||||
durationUnit: data.durationUnit ?? "minutes",
|
|
||||||
monitors: [data.monitorId],
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const now = dayjs();
|
|
||||||
defaults = {
|
|
||||||
name: "",
|
|
||||||
repeat: "none",
|
|
||||||
startDate: now.format("YYYY-MM-DD"),
|
|
||||||
startTime: now.format("HH:mm"),
|
|
||||||
duration: 0,
|
|
||||||
durationUnit: "minutes",
|
|
||||||
monitors: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { schema: maintenanceWindowSchema, defaults };
|
|
||||||
}, [data]);
|
|
||||||
};
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { monitorSchema, type MonitorFormData } from "@/Validation/monitor";
|
|
||||||
import type { Monitor, MonitorType } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
interface UseMonitorFormOptions {
|
|
||||||
data?: Monitor | null;
|
|
||||||
defaultType?: MonitorType;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getBaseDefaults = (data?: Monitor | null) => ({
|
|
||||||
name: data?.name || "",
|
|
||||||
description: data?.description || "",
|
|
||||||
interval: data?.interval || 60000,
|
|
||||||
notifications: data?.notifications || [],
|
|
||||||
statusWindowSize: data?.statusWindowSize || 5,
|
|
||||||
statusWindowThreshold: data?.statusWindowThreshold || 60,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const useMonitorForm = ({
|
|
||||||
data = null,
|
|
||||||
defaultType = "http",
|
|
||||||
}: UseMonitorFormOptions = {}) => {
|
|
||||||
return useMemo(() => {
|
|
||||||
const type = data?.type || defaultType;
|
|
||||||
const base = getBaseDefaults(data);
|
|
||||||
|
|
||||||
let defaults: MonitorFormData;
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case "http":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "http",
|
|
||||||
url: data?.url || "",
|
|
||||||
ignoreTlsErrors: data?.ignoreTlsErrors || false,
|
|
||||||
useAdvancedMatching: data?.useAdvancedMatching || false,
|
|
||||||
matchMethod: data?.matchMethod || "",
|
|
||||||
expectedValue: data?.expectedValue || "",
|
|
||||||
jsonPath: data?.jsonPath || "",
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case "ping":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "ping",
|
|
||||||
url: data?.url || "",
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case "port":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "port",
|
|
||||||
url: data?.url || "",
|
|
||||||
port: data?.port || 80,
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case "docker":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "docker",
|
|
||||||
url: data?.url || "",
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case "game":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "game",
|
|
||||||
url: data?.url || "",
|
|
||||||
port: data?.port || 27015,
|
|
||||||
gameId: data?.gameId || "",
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case "pagespeed":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "pagespeed",
|
|
||||||
url: data?.url || "",
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
case "hardware":
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "hardware",
|
|
||||||
url: data?.url || "",
|
|
||||||
secret: data?.secret || "",
|
|
||||||
cpuAlertThreshold: data?.cpuAlertThreshold ?? 80,
|
|
||||||
memoryAlertThreshold: data?.memoryAlertThreshold ?? 80,
|
|
||||||
diskAlertThreshold: data?.diskAlertThreshold ?? 80,
|
|
||||||
tempAlertThreshold: data?.tempAlertThreshold ?? 80,
|
|
||||||
selectedDisks: data?.selectedDisks || [],
|
|
||||||
};
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
defaults = {
|
|
||||||
...base,
|
|
||||||
type: "http",
|
|
||||||
url: "",
|
|
||||||
ignoreTlsErrors: false,
|
|
||||||
useAdvancedMatching: false,
|
|
||||||
matchMethod: "",
|
|
||||||
expectedValue: "",
|
|
||||||
jsonPath: "",
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return { schema: monitorSchema, defaults };
|
|
||||||
}, [data, defaultType]);
|
|
||||||
};
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { notificationSchema } from "@/Validation/notifications";
|
|
||||||
import type { Notification } from "@/Types/Notification";
|
|
||||||
|
|
||||||
interface UseNotificationFormOptions {
|
|
||||||
data?: Notification | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useNotificationForm = ({ data = null }: UseNotificationFormOptions = {}) => {
|
|
||||||
return useMemo(() => {
|
|
||||||
const defaults =
|
|
||||||
data?.type === "matrix"
|
|
||||||
? {
|
|
||||||
type: "matrix" as const,
|
|
||||||
notificationName: data.notificationName || "",
|
|
||||||
homeserverUrl: data.homeserverUrl || "",
|
|
||||||
roomId: data.roomId || "",
|
|
||||||
accessToken: data.accessToken || "",
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
type: (data?.type || "email") as Exclude<Notification["type"], "matrix">,
|
|
||||||
notificationName: data?.notificationName || "",
|
|
||||||
address: data?.address || "",
|
|
||||||
};
|
|
||||||
|
|
||||||
return { schema: notificationSchema, defaults };
|
|
||||||
}, [data]);
|
|
||||||
};
|
|
||||||
@@ -1,7 +1,36 @@
|
|||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { createToast } from "../Utils/toastUtils.jsx";
|
import { createToast } from "../Utils/toastUtils.jsx";
|
||||||
import { networkService } from "../main.jsx";
|
import { networkService } from "../main.jsx";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { NOTIFICATION_TYPES } from "../Pages/Notifications/utils.js";
|
||||||
|
|
||||||
|
const useCreateNotification = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const createNotification = async (notification) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.createNotification({ notification });
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.create.success"),
|
||||||
|
});
|
||||||
|
navigate("/notifications");
|
||||||
|
} catch (error) {
|
||||||
|
setError(error);
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.create.failed"),
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [createNotification, isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
const useGetNotificationsByTeamId = (updateTrigger) => {
|
const useGetNotificationsByTeamId = (updateTrigger) => {
|
||||||
const [notifications, setNotifications] = useState([]);
|
const [notifications, setNotifications] = useState([]);
|
||||||
@@ -31,6 +60,119 @@ const useGetNotificationsByTeamId = (updateTrigger) => {
|
|||||||
return [notifications, isLoading, error];
|
return [notifications, isLoading, error];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const useDeleteNotification = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const deleteNotification = async (id, callback) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.deleteNotificationById({ id });
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.delete.success"),
|
||||||
|
});
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
setError(error);
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.delete.failed"),
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [deleteNotification, isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
|
const useGetNotificationById = (id, setNotification) => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
|
||||||
|
const getNotificationById = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
const response = await networkService.getNotificationById({ id });
|
||||||
|
|
||||||
|
const notification = response?.data?.data ?? null;
|
||||||
|
|
||||||
|
const notificationData = {
|
||||||
|
address: notification?.address,
|
||||||
|
notificationName: notification?.notificationName,
|
||||||
|
type: NOTIFICATION_TYPES.find((type) => type.value === notification?.type)?.id,
|
||||||
|
};
|
||||||
|
|
||||||
|
setNotification(notificationData);
|
||||||
|
} catch (error) {
|
||||||
|
setError(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}, [id, setNotification]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (id) {
|
||||||
|
getNotificationById();
|
||||||
|
}
|
||||||
|
}, [getNotificationById, id]);
|
||||||
|
|
||||||
|
return [isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
|
const useEditNotification = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const editNotification = async (id, notification) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.editNotification({ id, notification });
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.edit.success"),
|
||||||
|
});
|
||||||
|
navigate(`/notifications`);
|
||||||
|
} catch (error) {
|
||||||
|
setError(error);
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.edit.failed"),
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [editNotification, isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
|
const useTestNotification = () => {
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [error, setError] = useState(null);
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const testNotification = async (notification) => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
await networkService.testNotification({ notification });
|
||||||
|
createToast({
|
||||||
|
body: t("notifications.test.success"),
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
setError(error);
|
||||||
|
createToast({
|
||||||
|
body: error?.response?.data?.msg || t("notifications.test.failed"),
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return [testNotification, isLoading, error];
|
||||||
|
};
|
||||||
|
|
||||||
const useTestAllNotifications = () => {
|
const useTestAllNotifications = () => {
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [error, setError] = useState(undefined);
|
const [error, setError] = useState(undefined);
|
||||||
@@ -55,4 +197,12 @@ const useTestAllNotifications = () => {
|
|||||||
return [testAllNotifications, isLoading, error];
|
return [testAllNotifications, isLoading, error];
|
||||||
};
|
};
|
||||||
|
|
||||||
export { useGetNotificationsByTeamId, useTestAllNotifications };
|
export {
|
||||||
|
useCreateNotification,
|
||||||
|
useGetNotificationsByTeamId,
|
||||||
|
useDeleteNotification,
|
||||||
|
useGetNotificationById,
|
||||||
|
useEditNotification,
|
||||||
|
useTestNotification,
|
||||||
|
useTestAllNotifications,
|
||||||
|
};
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { recoverySchema } from "@/Validation/recovery";
|
|
||||||
|
|
||||||
export const useRecoveryForm = () => {
|
|
||||||
const defaults = {
|
|
||||||
email: "",
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
schema: recoverySchema,
|
|
||||||
defaults,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
import { registerSchema, type RegisterFormData } from "@/Validation/register";
|
|
||||||
|
|
||||||
export const useRegisterForm = () => {
|
|
||||||
const defaults: RegisterFormData = {
|
|
||||||
firstName: "",
|
|
||||||
lastName: "",
|
|
||||||
email: "",
|
|
||||||
password: "",
|
|
||||||
confirm: "",
|
|
||||||
};
|
|
||||||
|
|
||||||
return {
|
|
||||||
schema: registerSchema,
|
|
||||||
defaults,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { useMemo } from "react";
|
|
||||||
import { statusPageSchema, type StatusPageFormData } from "@/Validation/statusPage";
|
|
||||||
import type { StatusPage } from "@/Types/StatusPage";
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
interface UseStatusPageFormOptions {
|
|
||||||
data?: StatusPage | null;
|
|
||||||
monitors?: Monitor[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const generateDefaultUrl = () => Math.floor(Math.random() * 1000000).toString();
|
|
||||||
|
|
||||||
const transformLogo = (logo: StatusPage["logo"]): StatusPageFormData["logo"] => {
|
|
||||||
if (!logo || !logo.data) return null;
|
|
||||||
return {
|
|
||||||
data: `data:${logo.contentType};base64,${logo.data}`,
|
|
||||||
contentType: logo.contentType,
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
export const useStatusPageForm = ({
|
|
||||||
data = null,
|
|
||||||
monitors = null,
|
|
||||||
}: UseStatusPageFormOptions = {}) => {
|
|
||||||
return useMemo(() => {
|
|
||||||
const defaults: StatusPageFormData = {
|
|
||||||
companyName: data?.companyName || "",
|
|
||||||
url: data?.url || generateDefaultUrl(),
|
|
||||||
timezone: data?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
||||||
color: data?.color || "#4169E1",
|
|
||||||
monitors: data?.monitors || [],
|
|
||||||
isPublished: data?.isPublished ?? false,
|
|
||||||
showCharts: data?.showCharts ?? true,
|
|
||||||
showUptimePercentage: data?.showUptimePercentage ?? true,
|
|
||||||
showAdminLoginLink: data?.showAdminLoginLink ?? false,
|
|
||||||
customCSS: data?.customCSS || "",
|
|
||||||
logo: transformLogo(data?.logo),
|
|
||||||
};
|
|
||||||
|
|
||||||
return { schema: statusPageSchema, defaults };
|
|
||||||
}, [data, monitors]);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import React from "react";
|
||||||
|
import AppBar from "@/Components/v1/Common/AppBar.jsx";
|
||||||
|
import Footer from "@/Components/v1/Common/Footer.jsx";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const AboutUs = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<AppBar />
|
||||||
|
<h1>{t("aboutus")}</h1>
|
||||||
|
<Footer />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AboutUs;
|
||||||
@@ -11,9 +11,6 @@ import { useDispatch, useSelector } from "react-redux";
|
|||||||
import { createToast } from "../../../Utils/toastUtils.jsx";
|
import { createToast } from "../../../Utils/toastUtils.jsx";
|
||||||
import { getTouchedFieldErrors } from "../../../Validation/error.js";
|
import { getTouchedFieldErrors } from "../../../Validation/error.js";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useNavigate, useLocation } from "react-router-dom";
|
|
||||||
import { clearAuthState } from "../../../Features/Auth/authSlice.js";
|
|
||||||
import TextLink from "@/Components/v1/TextLink/index.jsx";
|
|
||||||
|
|
||||||
const defaultPasswordsState = {
|
const defaultPasswordsState = {
|
||||||
password: "",
|
password: "",
|
||||||
@@ -31,13 +28,11 @@ const PasswordPanel = () => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
const SPACING_GAP = theme.spacing(12);
|
const SPACING_GAP = theme.spacing(12);
|
||||||
|
|
||||||
//redux state
|
//redux state
|
||||||
const { isLoading, authToken } = useSelector((state) => state.auth);
|
const { isLoading } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
const idToName = {
|
const idToName = {
|
||||||
"edit-current-password": "password",
|
"edit-current-password": "password",
|
||||||
@@ -84,16 +79,6 @@ const PasswordPanel = () => {
|
|||||||
const handleSubmit = async (event) => {
|
const handleSubmit = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
// Check for expired/invalid token before submitting
|
|
||||||
if (!authToken) {
|
|
||||||
createToast({
|
|
||||||
body: "Your session has expired. Please log in again.",
|
|
||||||
});
|
|
||||||
dispatch(clearAuthState());
|
|
||||||
navigate("/login");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const { error } = newOrChangedCredentials.validate(localData, {
|
const { error } = newOrChangedCredentials.validate(localData, {
|
||||||
abortEarly: false,
|
abortEarly: false,
|
||||||
context: { password: localData.newPassword },
|
context: { password: localData.newPassword },
|
||||||
@@ -264,15 +249,8 @@ const PasswordPanel = () => {
|
|||||||
)}
|
)}
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
justifyContent="space-between"
|
justifyContent="flex-end"
|
||||||
alignItems="center"
|
|
||||||
>
|
>
|
||||||
<TextLink
|
|
||||||
text={"Forgot password?"}
|
|
||||||
linkText={"Reset password"}
|
|
||||||
state={{ from: location.pathname }}
|
|
||||||
href={"/forgot-password"}
|
|
||||||
/>
|
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="accent"
|
color="accent"
|
||||||
@@ -285,6 +263,7 @@ const PasswordPanel = () => {
|
|||||||
}
|
}
|
||||||
sx={{
|
sx={{
|
||||||
px: theme.spacing(12),
|
px: theme.spacing(12),
|
||||||
|
mt: theme.spacing(20),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("commonSave", "Save")}
|
{t("commonSave", "Save")}
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ const Account = ({ open = "profile" }) => {
|
|||||||
))}
|
))}
|
||||||
</CustomTabList>
|
</CustomTabList>
|
||||||
<ProfilePanel />
|
<ProfilePanel />
|
||||||
<PasswordPanel />
|
{user.role.includes("superadmin") && <PasswordPanel />}
|
||||||
{!hideTeams && <TeamPanel />}
|
{!hideTeams && <TeamPanel />}
|
||||||
</TabContext>
|
</TabContext>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Box, Button, Stack, Typography } from "@mui/material";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { useNavigate, useLocation } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { createToast } from "../../Utils/toastUtils.jsx";
|
import { createToast } from "../../Utils/toastUtils.jsx";
|
||||||
import { forgotPassword } from "../../Features/Auth/authSlice.js";
|
import { forgotPassword } from "../../Features/Auth/authSlice.js";
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
@@ -17,7 +17,6 @@ const CheckEmail = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const location = useLocation();
|
|
||||||
|
|
||||||
const [email, setEmail] = useState();
|
const [email, setEmail] = useState();
|
||||||
const [disabled, setDisabled] = useState(false);
|
const [disabled, setDisabled] = useState(false);
|
||||||
@@ -84,9 +83,7 @@ const CheckEmail = () => {
|
|||||||
|
|
||||||
const handleNavigate = () => {
|
const handleNavigate = () => {
|
||||||
sessionStorage.removeItem("email");
|
sessionStorage.removeItem("email");
|
||||||
location.state?.from
|
navigate("/login");
|
||||||
? navigate(location.state.from, { replace: true })
|
|
||||||
: navigate("/login");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -222,11 +219,7 @@ const CheckEmail = () => {
|
|||||||
>
|
>
|
||||||
<Typography display="inline-block">
|
<Typography display="inline-block">
|
||||||
<Trans
|
<Trans
|
||||||
i18nKey={
|
i18nKey="auth.forgotPassword.links.login"
|
||||||
location.state?.from === "/account/password"
|
|
||||||
? "Go back to <a>Account Password</a>"
|
|
||||||
: "auth.forgotPassword.links.login"
|
|
||||||
}
|
|
||||||
components={{
|
components={{
|
||||||
a: (
|
a: (
|
||||||
<Typography
|
<Typography
|
||||||
|
|||||||
@@ -0,0 +1,234 @@
|
|||||||
|
import { Box, Stack, Typography, Button } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { createToast } from "../../Utils/toastUtils.jsx";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
import { forgotPassword } from "../../Features/Auth/authSlice.js";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { newOrChangedCredentials } from "../../Validation/validation.js";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
|
||||||
|
import Logo from "@/assets/icons/checkmate-icon.svg?react";
|
||||||
|
import Background from "@/assets/Images/background-grid.svg?react";
|
||||||
|
import IconBox from "@/Components/v1/IconBox/index.jsx";
|
||||||
|
import Icon from "@/Components/v1/Icon";
|
||||||
|
import { Trans, useTranslation } from "react-i18next";
|
||||||
|
import "./index.css";
|
||||||
|
|
||||||
|
const ForgotPassword = () => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const { isLoading } = useSelector((state) => state.auth);
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
email: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const email = sessionStorage.getItem("email");
|
||||||
|
email && setForm({ email: sessionStorage.getItem("email") });
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handleSubmit = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
const { error } = newOrChangedCredentials.validate(form, { abortEarly: false });
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
// validation errors
|
||||||
|
const err =
|
||||||
|
error.details && error.details.length > 0
|
||||||
|
? error.details[0].message // FIXME: Possibly untranslated string
|
||||||
|
: t("auth.common.errors.validation");
|
||||||
|
setErrors({ email: err });
|
||||||
|
createToast({
|
||||||
|
body: err,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const action = await dispatch(forgotPassword(form));
|
||||||
|
if (action.payload.success) {
|
||||||
|
sessionStorage.setItem("email", form.email);
|
||||||
|
navigate("/check-email");
|
||||||
|
createToast({
|
||||||
|
body: t("auth.forgotPassword.toasts.sent").replace("<email/>", form.email),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (action.payload) {
|
||||||
|
// dispatch errors
|
||||||
|
createToast({
|
||||||
|
body: action.payload.msg, // FIXME: Potentially untranslated string
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// unknown errors
|
||||||
|
createToast({
|
||||||
|
body: t("common.toasts.unknownError"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (event) => {
|
||||||
|
const { value } = event.target;
|
||||||
|
setForm({ email: value });
|
||||||
|
|
||||||
|
const { error } = newOrChangedCredentials.validate(
|
||||||
|
{ email: value },
|
||||||
|
{ abortEarly: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
if (error) setErrors({ email: error.details[0].message });
|
||||||
|
else delete errors.email;
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleNavigate = () => {
|
||||||
|
sessionStorage.removeItem("email");
|
||||||
|
navigate("/login");
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
className="forgot-password-page auth"
|
||||||
|
overflow="hidden"
|
||||||
|
sx={{
|
||||||
|
"& h1": {
|
||||||
|
color: theme.palette.primary.main,
|
||||||
|
fontWeight: 600,
|
||||||
|
fontSize: 21,
|
||||||
|
},
|
||||||
|
"& p": {
|
||||||
|
/* TODO font size from theme */
|
||||||
|
fontSize: 14,
|
||||||
|
color: theme.palette.primary.contrastTextSecondary,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
className="background-pattern-svg"
|
||||||
|
sx={{
|
||||||
|
"& svg g g:last-of-type path": {
|
||||||
|
stroke: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Background style={{ width: "100%" }} />
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
px={theme.spacing(12)}
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<Logo style={{ borderRadius: theme.shape.borderRadius }} />
|
||||||
|
<Typography sx={{ userSelect: "none" }}>{t("common.appName")}</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
width="100%"
|
||||||
|
maxWidth={600}
|
||||||
|
flex={1}
|
||||||
|
justifyContent="center"
|
||||||
|
px={{ xs: theme.spacing(12), lg: theme.spacing(20) }}
|
||||||
|
pb={theme.spacing(20)}
|
||||||
|
mx="auto"
|
||||||
|
sx={{
|
||||||
|
"& > .MuiStack-root": {
|
||||||
|
border: 1,
|
||||||
|
borderRadius: theme.spacing(5),
|
||||||
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
padding: {
|
||||||
|
xs: theme.spacing(12),
|
||||||
|
sm: theme.spacing(20),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
gap={{ xs: theme.spacing(8), sm: theme.spacing(12) }}
|
||||||
|
alignItems="center"
|
||||||
|
textAlign="center"
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="center"
|
||||||
|
>
|
||||||
|
<IconBox
|
||||||
|
height={48}
|
||||||
|
width={48}
|
||||||
|
minWidth={48}
|
||||||
|
borderRadius={12}
|
||||||
|
svgWidth={24}
|
||||||
|
svgHeight={24}
|
||||||
|
mb={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<Icon name="Key" />
|
||||||
|
</IconBox>
|
||||||
|
</Stack>
|
||||||
|
<Typography component="h1">{t("auth.forgotPassword.heading")}</Typography>
|
||||||
|
<Typography>{t("auth.forgotPassword.subheadings.stepOne")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
component="form"
|
||||||
|
width="95%"
|
||||||
|
textAlign="left"
|
||||||
|
noValidate
|
||||||
|
spellCheck={false}
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
type="email"
|
||||||
|
id="forgot-password-email-input"
|
||||||
|
label={t("auth.common.inputs.email.label")}
|
||||||
|
isRequired={true}
|
||||||
|
placeholder={t("auth.common.inputs.email.placeholder")}
|
||||||
|
value={form.email}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors.email ? true : false}
|
||||||
|
helperText={t(errors.email)} // Localization keys are in validation.js
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
loading={isLoading}
|
||||||
|
disabled={errors.email !== undefined}
|
||||||
|
onClick={handleSubmit}
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
mt: theme.spacing(15),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("auth.common.navigation.continue")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<Box
|
||||||
|
textAlign="center"
|
||||||
|
p={theme.spacing(12)}
|
||||||
|
>
|
||||||
|
<Typography display="inline-block">
|
||||||
|
<Trans
|
||||||
|
i18nKey="auth.forgotPassword.links.login"
|
||||||
|
components={{
|
||||||
|
a: (
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
color={theme.palette.accent.main}
|
||||||
|
ml={theme.spacing(2)}
|
||||||
|
onClick={handleNavigate}
|
||||||
|
sx={{ userSelect: "none" }}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ForgotPassword;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// Hook to avoid double submits and manage loading state
|
||||||
|
import { useState, useCallback } from "react";
|
||||||
|
|
||||||
|
const useLoadingSubmit = () => {
|
||||||
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
const executeSubmit = useCallback(
|
||||||
|
async (submitFunction) => {
|
||||||
|
if (submitting) return;
|
||||||
|
setSubmitting(true);
|
||||||
|
try {
|
||||||
|
return await submitFunction();
|
||||||
|
} finally {
|
||||||
|
setSubmitting(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[submitting]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { submitting, executeSubmit };
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLoadingSubmit;
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const useLoginForm = () => {
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
email: "",
|
||||||
|
password: "",
|
||||||
|
});
|
||||||
|
const onChange = (e) => {
|
||||||
|
let { name, value } = e.target;
|
||||||
|
if (name === "email") {
|
||||||
|
value = value.toLowerCase();
|
||||||
|
}
|
||||||
|
const updatedForm = { ...form, [name]: value };
|
||||||
|
setForm(updatedForm);
|
||||||
|
};
|
||||||
|
return [form, onChange];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLoginForm;
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { useDispatch } from "react-redux";
|
||||||
|
import { login } from "../../../../Features/Auth/authSlice.js";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { createToast } from "../../../../Utils/toastUtils.jsx";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const useLoginSubmit = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handleLoginSubmit = async (form, setErrors) => {
|
||||||
|
const action = await dispatch(login(form));
|
||||||
|
if (action.payload.success) {
|
||||||
|
navigate("/uptime");
|
||||||
|
createToast({
|
||||||
|
body: t("auth.login.toasts.success"),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (action.payload) {
|
||||||
|
if (action.payload.msg === "Incorrect password")
|
||||||
|
setErrors({
|
||||||
|
password: t("auth.login.errors.password.incorrect"),
|
||||||
|
});
|
||||||
|
// dispatch errors
|
||||||
|
createToast({
|
||||||
|
body: t("auth.login.toasts.incorrectPassword"),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// unknown errors
|
||||||
|
createToast({
|
||||||
|
body: t("common.toasts.unknownError"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return [handleLoginSubmit];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useLoginSubmit;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { loginCredentials } from "../../../../Validation/validation.js";
|
||||||
|
|
||||||
|
const useValidateLoginForm = () => {
|
||||||
|
const [errors, setErrors] = useState({
|
||||||
|
email: "",
|
||||||
|
password: "",
|
||||||
|
});
|
||||||
|
const validateField = (name, value) => {
|
||||||
|
const { error } = loginCredentials.validate({ [name]: value });
|
||||||
|
setErrors((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[name]: error?.details?.[0]?.message || "",
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
const validateForm = (form) => {
|
||||||
|
const { error } = loginCredentials.validate(form, { abortEarly: false });
|
||||||
|
if (error) {
|
||||||
|
const formErrors = {};
|
||||||
|
for (const err of error.details) {
|
||||||
|
formErrors[err.path[0]] = err.message;
|
||||||
|
}
|
||||||
|
setErrors(formErrors);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
return [errors, setErrors, validateField, validateForm];
|
||||||
|
};
|
||||||
|
|
||||||
|
export default useValidateLoginForm;
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
// Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
|
||||||
|
import { PasswordEndAdornment } from "@/Components/v1/Inputs/TextInput/Adornments/index.jsx";
|
||||||
|
import TextLink from "@/Components/v1/TextLink/index.jsx";
|
||||||
|
import AuthPageWrapper from "../components/AuthPageWrapper.jsx";
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import useLoginForm from "./hooks/useLoginForm.jsx";
|
||||||
|
import useValidateLoginForm from "./hooks/useValidateLoginForm.jsx";
|
||||||
|
import useLoginSubmit from "./hooks/useLoginSubmit.jsx";
|
||||||
|
import useLoadingSubmit from "./hooks/useLoadingSubmit.jsx";
|
||||||
|
|
||||||
|
const Login = () => {
|
||||||
|
// Hooks
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
const [form, onChange] = useLoginForm();
|
||||||
|
const [errors, setErrors, validateField, validateForm] = useValidateLoginForm();
|
||||||
|
const [handleLoginSubmit] = useLoginSubmit();
|
||||||
|
const { submitting, executeSubmit } = useLoadingSubmit();
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
const handleChange = (e) => {
|
||||||
|
onChange(e);
|
||||||
|
validateField(e.target.name, e.target.value);
|
||||||
|
};
|
||||||
|
const onSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const isValid = validateForm(form);
|
||||||
|
if (!isValid) return;
|
||||||
|
await executeSubmit(() => handleLoginSubmit(form, setErrors));
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<AuthPageWrapper
|
||||||
|
welcome={t("auth.login.welcome")}
|
||||||
|
heading={t("auth.login.heading")}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
component="form"
|
||||||
|
width="100%"
|
||||||
|
padding={theme.spacing(8)}
|
||||||
|
gap={theme.spacing(12)}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
sx={{
|
||||||
|
width: {
|
||||||
|
sm: "80%",
|
||||||
|
md: "70%",
|
||||||
|
lg: "65%",
|
||||||
|
xl: "65%",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
type="email"
|
||||||
|
name="email"
|
||||||
|
label={t("auth.common.inputs.email.label")}
|
||||||
|
placeholder={t("auth.common.inputs.email.placeholder")}
|
||||||
|
autoComplete="email"
|
||||||
|
value={form.email}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors.email ? true : false}
|
||||||
|
helperText={errors.email ? t(errors.email) : ""} // Localization keys are in validation.js
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
type="password"
|
||||||
|
name="password"
|
||||||
|
label={t("auth.common.inputs.password.label")}
|
||||||
|
placeholder="••••••••••"
|
||||||
|
autoComplete="current-password"
|
||||||
|
value={form.password}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors.password ? true : false}
|
||||||
|
helperText={errors.password ? t(errors.password) : ""} // Localization keys are in validation.js
|
||||||
|
endAdornment={<PasswordEndAdornment />}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
type="submit"
|
||||||
|
sx={{ width: "100%", alignSelf: "center", fontWeight: 700 }}
|
||||||
|
loading={submitting}
|
||||||
|
>
|
||||||
|
Login
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
<TextLink
|
||||||
|
text={t("auth.login.links.forgotPassword")}
|
||||||
|
linkText={t("auth.login.links.forgotPasswordLink")}
|
||||||
|
href="/forgot-password"
|
||||||
|
/>
|
||||||
|
<TextLink
|
||||||
|
text={t("auth.login.links.register")}
|
||||||
|
linkText={t("auth.login.links.registerLink")}
|
||||||
|
href="/register"
|
||||||
|
/>
|
||||||
|
</AuthPageWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default Login;
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
import { BaseAuthPage, TextLink } from "@/Components/v2/design-elements";
|
|
||||||
import { Button, TextField } from "@/Components/v2/inputs";
|
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useForm, Controller } from "react-hook-form";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
|
||||||
import { useLoginForm } from "@/Hooks/useLoginForm";
|
|
||||||
import type { LoginFormData } from "@/Validation/login";
|
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { setAuthState } from "@/Features/Auth/authSlice";
|
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
|
||||||
|
|
||||||
const LoginPage = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const { post, loading } = usePost();
|
|
||||||
|
|
||||||
const { schema, defaults } = useLoginForm();
|
|
||||||
|
|
||||||
const { control, handleSubmit } = useForm<LoginFormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: defaults,
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = async (data: LoginFormData) => {
|
|
||||||
if (loading) return;
|
|
||||||
|
|
||||||
const result = await post("/auth/login", data);
|
|
||||||
|
|
||||||
if (result?.success) {
|
|
||||||
dispatch(setAuthState(result));
|
|
||||||
navigate("/uptime");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BaseAuthPage
|
|
||||||
component="form"
|
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
|
||||||
title={t("pages.auth.login.title")}
|
|
||||||
subtitle={t("pages.auth.login.subtitle")}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name="email"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.email.label")}
|
|
||||||
placeholder={t("pages.auth.common.form.option.email.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error ? t(fieldState.error.message ?? "") : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="password"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="password"
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.password.label")}
|
|
||||||
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error ? t(fieldState.error.message ?? "") : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
type="submit"
|
|
||||||
loading={loading}
|
|
||||||
>
|
|
||||||
{t("pages.auth.login.submit")}
|
|
||||||
</Button>
|
|
||||||
<TextLink
|
|
||||||
alignSelf={"center"}
|
|
||||||
text={t("pages.auth.login.links.forgotPassword.text")}
|
|
||||||
linkText={t("pages.auth.login.links.forgotPassword.linkText")}
|
|
||||||
href="/forgot-password"
|
|
||||||
/>
|
|
||||||
<TextLink
|
|
||||||
alignSelf={"center"}
|
|
||||||
text={t("pages.auth.login.links.register.text")}
|
|
||||||
linkText={t("pages.auth.login.links.register.linkText")}
|
|
||||||
href="/register"
|
|
||||||
/>
|
|
||||||
</BaseAuthPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LoginPage;
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
import { Button, TextField } from "@/Components/v2/inputs";
|
|
||||||
import { BaseAuthPage, TextLink } from "@/Components/v2/design-elements";
|
|
||||||
|
|
||||||
import { useForm, Controller } from "react-hook-form";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
|
||||||
import { useRecoveryForm } from "@/Hooks/useRecoveryForm";
|
|
||||||
import type { RecoveryFormData } from "@/Validation/recovery";
|
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
|
|
||||||
const ForgotPasswordPage = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { post, loading } = usePost();
|
|
||||||
|
|
||||||
const { schema, defaults } = useRecoveryForm();
|
|
||||||
|
|
||||||
const { control, handleSubmit } = useForm<RecoveryFormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: defaults,
|
|
||||||
});
|
|
||||||
|
|
||||||
const onSubmit = async (data: RecoveryFormData) => {
|
|
||||||
if (loading) return;
|
|
||||||
|
|
||||||
const result = await post("/auth/recovery/request", data);
|
|
||||||
|
|
||||||
if (result?.success) {
|
|
||||||
// Navigate to Check email page
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BaseAuthPage
|
|
||||||
component="form"
|
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
|
||||||
title={t("pages.auth.forgotPassword.title")}
|
|
||||||
subtitle={t("pages.auth.forgotPassword.subtitle")}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name="email"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.email.label")}
|
|
||||||
placeholder={t("pages.auth.common.form.option.email.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error ? t(fieldState.error.message ?? "") : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
type="submit"
|
|
||||||
loading={loading}
|
|
||||||
>
|
|
||||||
{t("pages.auth.forgotPassword.submit")}
|
|
||||||
</Button>
|
|
||||||
<TextLink
|
|
||||||
alignSelf={"center"}
|
|
||||||
text={t("pages.auth.forgotPassword.links.login.text")}
|
|
||||||
linkText={t("pages.auth.forgotPassword.links.login.linkText")}
|
|
||||||
href="/login"
|
|
||||||
/>
|
|
||||||
</BaseAuthPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ForgotPasswordPage;
|
|
||||||
@@ -0,0 +1,330 @@
|
|||||||
|
// Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
|
||||||
|
import Button from "@mui/material/Button";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import PasswordTooltip from "../components/PasswordTooltip.jsx";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { networkService } from "../../../main.jsx";
|
||||||
|
import { newOrChangedCredentials } from "../../../Validation/validation.js";
|
||||||
|
import { register } from "../../../Features/Auth/authSlice.js";
|
||||||
|
import AuthPageWrapper from "../components/AuthPageWrapper.jsx";
|
||||||
|
import { createToast } from "../../../Utils/toastUtils.jsx";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const getFeedbackStatus = (form, errors, field, criteria) => {
|
||||||
|
const fieldErrors = errors?.[field];
|
||||||
|
const isFieldEmpty = form?.[field]?.length === 0;
|
||||||
|
const hasError = fieldErrors?.includes(criteria) || fieldErrors?.includes("empty");
|
||||||
|
const isCorrect = !isFieldEmpty && !hasError;
|
||||||
|
|
||||||
|
if (isCorrect) {
|
||||||
|
return "success";
|
||||||
|
} else if (hasError) {
|
||||||
|
return "error";
|
||||||
|
} else {
|
||||||
|
return "info";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const Register = ({ superAdminExists }) => {
|
||||||
|
// Redux
|
||||||
|
const { isLoading } = useSelector((state) => state.auth);
|
||||||
|
|
||||||
|
// Local state
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
firstName: "",
|
||||||
|
lastName: "",
|
||||||
|
email: "",
|
||||||
|
password: "",
|
||||||
|
confirm: "",
|
||||||
|
role: [],
|
||||||
|
teamId: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
const [feedback, setFeedback] = useState({});
|
||||||
|
|
||||||
|
// Hooks
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { token } = useParams();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
|
// Effects
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchInvite = async () => {
|
||||||
|
if (token !== undefined) {
|
||||||
|
try {
|
||||||
|
const res = await networkService.verifyInvitationToken(token);
|
||||||
|
const invite = res.data.data;
|
||||||
|
const { email } = invite;
|
||||||
|
setForm((prevForm) => {
|
||||||
|
if (!prevForm.email) {
|
||||||
|
return { ...prevForm, email };
|
||||||
|
}
|
||||||
|
return prevForm;
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
navigate("/register", { replace: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
fetchInvite();
|
||||||
|
}, [form, token, navigate]);
|
||||||
|
|
||||||
|
// Handlers
|
||||||
|
const onChange = (e) => {
|
||||||
|
let { name, value } = e.target;
|
||||||
|
if (name === "email") value = value.toLowerCase();
|
||||||
|
const updatedForm = { ...form, [name]: value };
|
||||||
|
|
||||||
|
const { error } = newOrChangedCredentials.validate(
|
||||||
|
{ [name]: value },
|
||||||
|
{ abortEarly: false, context: { password: form.password } }
|
||||||
|
);
|
||||||
|
|
||||||
|
setErrors((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[name]: error?.details?.[0]?.message || "",
|
||||||
|
}));
|
||||||
|
|
||||||
|
setForm(updatedForm);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPasswordChange = (e) => {
|
||||||
|
const { name, value } = e.target;
|
||||||
|
const updatedForm = { ...form, [name]: value };
|
||||||
|
setForm(updatedForm);
|
||||||
|
const validateValue = { [name]: value };
|
||||||
|
const validateOptions = { abortEarly: false, context: { password: form.password } };
|
||||||
|
if (name === "password" && form.confirm.length > 0) {
|
||||||
|
validateValue.confirm = form.confirm;
|
||||||
|
validateOptions.context = { password: value };
|
||||||
|
} else if (name === "confirm") {
|
||||||
|
validateValue.password = form.password;
|
||||||
|
}
|
||||||
|
const { error } = newOrChangedCredentials.validate(validateValue, validateOptions);
|
||||||
|
|
||||||
|
const pwdErrors = error?.details.map((error) => ({
|
||||||
|
path: error.path[0],
|
||||||
|
type: error.type,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const errorsByPath =
|
||||||
|
pwdErrors &&
|
||||||
|
pwdErrors.reduce((acc, { path, type }) => {
|
||||||
|
if (!acc[path]) {
|
||||||
|
acc[path] = [];
|
||||||
|
}
|
||||||
|
acc[path].push(type);
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
const oldErrors = { ...errors };
|
||||||
|
if (name === "password") {
|
||||||
|
oldErrors.password = undefined;
|
||||||
|
} else if (name === "confirm") {
|
||||||
|
oldErrors.confirm = undefined;
|
||||||
|
}
|
||||||
|
const newErrors = { ...oldErrors, ...errorsByPath };
|
||||||
|
|
||||||
|
setErrors(newErrors);
|
||||||
|
|
||||||
|
const newFeedback = {
|
||||||
|
length: getFeedbackStatus(updatedForm, errorsByPath, "password", "string.min"),
|
||||||
|
special: getFeedbackStatus(updatedForm, errorsByPath, "password", "special"),
|
||||||
|
number: getFeedbackStatus(updatedForm, errorsByPath, "password", "number"),
|
||||||
|
uppercase: getFeedbackStatus(updatedForm, errorsByPath, "password", "uppercase"),
|
||||||
|
lowercase: getFeedbackStatus(updatedForm, errorsByPath, "password", "lowercase"),
|
||||||
|
confirm: getFeedbackStatus(updatedForm, errorsByPath, "confirm", "different"),
|
||||||
|
};
|
||||||
|
|
||||||
|
setFeedback(newFeedback);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
const toSubmit = {
|
||||||
|
...form,
|
||||||
|
role: superAdminExists ? form.role : ["superadmin"],
|
||||||
|
inviteToken: token ? token : "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const { error } = newOrChangedCredentials.validate(toSubmit, {
|
||||||
|
abortEarly: false,
|
||||||
|
context: { password: form.password },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
const formErrors = {};
|
||||||
|
for (const err of error.details) {
|
||||||
|
formErrors[err.path[0]] = err.message;
|
||||||
|
}
|
||||||
|
setErrors(formErrors);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete toSubmit.confirm;
|
||||||
|
|
||||||
|
const action = await dispatch(register({ user: toSubmit, token }));
|
||||||
|
if (action.payload.success) {
|
||||||
|
navigate("/uptime");
|
||||||
|
createToast({
|
||||||
|
body: t("auth.registration.toasts.success"),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (action.payload) {
|
||||||
|
createToast({
|
||||||
|
body: action.payload.msg,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
createToast({
|
||||||
|
body: t("common.toasts.unknownError"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AuthPageWrapper
|
||||||
|
heading={t("auth.registration.heading.user")}
|
||||||
|
welcome={t("auth.registration.welcome")}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
component="form"
|
||||||
|
width="100%"
|
||||||
|
padding={theme.spacing(8)}
|
||||||
|
gap={theme.spacing(8)}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
sx={{
|
||||||
|
width: {
|
||||||
|
sm: "80%",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography variant="h2">
|
||||||
|
{superAdminExists
|
||||||
|
? t("auth.registration.description.user")
|
||||||
|
: t("auth.registration.description.superAdmin")}
|
||||||
|
</Typography>
|
||||||
|
<Stack
|
||||||
|
direction={{ xs: "column", lg: "row" }}
|
||||||
|
justifyContent="space-between"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<TextInput
|
||||||
|
name="firstName"
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
label={t("auth.common.inputs.firstName.label")}
|
||||||
|
width="100%"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
isRequired={true}
|
||||||
|
placeholder={t("auth.common.inputs.firstName.placeholder")}
|
||||||
|
autoComplete="given-name"
|
||||||
|
value={form.firstName}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors.firstName ? true : false}
|
||||||
|
helperText={errors.firstName ? t(errors.firstName) : ""}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
name="lastName"
|
||||||
|
label={t("auth.common.inputs.lastName.label")}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
width="100%"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
isRequired={true}
|
||||||
|
placeholder={t("auth.common.inputs.lastName.placeholder")}
|
||||||
|
autoComplete="family-name"
|
||||||
|
value={form.lastName}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors.lastName ? true : false}
|
||||||
|
helperText={errors.lastName ? t(errors.lastName) : ""} // Localization keys are in validation.js
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<TextInput
|
||||||
|
type="email"
|
||||||
|
name="email"
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
label={t("auth.common.inputs.email.label")}
|
||||||
|
isRequired={true}
|
||||||
|
placeholder={t("auth.common.inputs.email.placeholder")}
|
||||||
|
autoComplete="email"
|
||||||
|
value={form.email}
|
||||||
|
onInput={(e) => (e.target.value = e.target.value.toLowerCase())}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors.email ? true : false}
|
||||||
|
helperText={errors.email ? t(errors.email) : ""} // Localization keys are in validation.js
|
||||||
|
/>
|
||||||
|
<PasswordTooltip
|
||||||
|
feedback={feedback}
|
||||||
|
form={form}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<TextInput
|
||||||
|
type="password"
|
||||||
|
id="register-password-input"
|
||||||
|
name="password"
|
||||||
|
label={t("auth.common.inputs.password.label")}
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
isRequired={true}
|
||||||
|
placeholder="••••••••••"
|
||||||
|
autoComplete="current-password"
|
||||||
|
value={form.password}
|
||||||
|
onChange={onPasswordChange}
|
||||||
|
error={errors.password && errors.password[0] ? true : false}
|
||||||
|
helperText={
|
||||||
|
errors.password === "auth.common.inputs.password.errors.empty"
|
||||||
|
? t(errors.password)
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</PasswordTooltip>
|
||||||
|
<TextInput
|
||||||
|
type="password"
|
||||||
|
id="register-confirm-input"
|
||||||
|
name="confirm"
|
||||||
|
label={t("auth.common.inputs.passwordConfirm.label")}
|
||||||
|
gap={theme.spacing(4)}
|
||||||
|
isRequired={true}
|
||||||
|
placeholder={t("auth.common.inputs.passwordConfirm.placeholder")}
|
||||||
|
autoComplete="current-password"
|
||||||
|
value={form.confirm}
|
||||||
|
onChange={onPasswordChange}
|
||||||
|
marginBottom={theme.spacing(4)}
|
||||||
|
error={errors.confirm && errors.confirm[0] ? true : false}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
disabled={isLoading}
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
type="submit"
|
||||||
|
sx={{
|
||||||
|
width: "100%",
|
||||||
|
alignSelf: "center",
|
||||||
|
fontWeight: 700,
|
||||||
|
mt: theme.spacing(10),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("auth.common.navigation.continue")}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</AuthPageWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Register.propTypes = {
|
||||||
|
superAdminExists: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Register;
|
||||||
@@ -1,162 +0,0 @@
|
|||||||
import { BaseAuthPage } from "@/Components/v2/design-elements";
|
|
||||||
import { Button, TextField } from "@/Components/v2/inputs";
|
|
||||||
import { useForm, Controller } from "react-hook-form";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
|
||||||
import { useRegisterForm } from "@/Hooks/useRegisterForm";
|
|
||||||
import type { RegisterFormData } from "@/Validation/register";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
|
||||||
import { setAuthState } from "@/Features/Auth/authSlice";
|
|
||||||
import { useDispatch } from "react-redux";
|
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
|
||||||
import type { AuthResponse } from "@/Types/User";
|
|
||||||
import { useEffect, useRef } from "react";
|
|
||||||
|
|
||||||
interface RegisterPayload {
|
|
||||||
user: Omit<RegisterFormData, "confirm">;
|
|
||||||
token?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface InviteVerifyResponse {
|
|
||||||
email: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RegisterPage = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { schema, defaults } = useRegisterForm();
|
|
||||||
const { post, loading } = usePost<RegisterPayload, AuthResponse>();
|
|
||||||
const dispatch = useDispatch();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const { token } = useParams<{ token?: string }>();
|
|
||||||
|
|
||||||
const { post: verifyToken } = usePost<{ token: string }, InviteVerifyResponse>();
|
|
||||||
const hasVerified = useRef(false);
|
|
||||||
|
|
||||||
const { control, handleSubmit, setError, reset } = useForm<RegisterFormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: defaults,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (!token || hasVerified.current) return;
|
|
||||||
hasVerified.current = true;
|
|
||||||
|
|
||||||
verifyToken("/invite/verify", { token }).then((result) => {
|
|
||||||
if (result?.success && result?.data) {
|
|
||||||
reset({
|
|
||||||
...defaults,
|
|
||||||
email: result.data.email ?? "",
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
navigate("/register", { replace: true });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}, [token]);
|
|
||||||
|
|
||||||
const onSubmit = async (data: RegisterFormData) => {
|
|
||||||
if (loading) return;
|
|
||||||
|
|
||||||
const { confirm, ...userData } = data;
|
|
||||||
const payload: RegisterPayload = { user: userData };
|
|
||||||
if (token) {
|
|
||||||
payload.token = token;
|
|
||||||
}
|
|
||||||
const result = await post("/auth/register", payload);
|
|
||||||
|
|
||||||
if (result?.success) {
|
|
||||||
dispatch(setAuthState(result));
|
|
||||||
navigate("/uptime");
|
|
||||||
} else if (result?.msg) {
|
|
||||||
if (result.msg.toLowerCase().includes("email")) {
|
|
||||||
setError("email", { message: result.msg });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BaseAuthPage
|
|
||||||
component="form"
|
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
|
||||||
title={t("pages.auth.register.title")}
|
|
||||||
subtitle={t("pages.auth.register.subtitle")}
|
|
||||||
>
|
|
||||||
<Controller
|
|
||||||
name="firstName"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
fieldLabel={t("pages.auth.register.form.option.name.label")}
|
|
||||||
placeholder={t("pages.auth.register.form.option.name.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="lastName"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
fieldLabel={t("pages.auth.register.form.option.surname.label")}
|
|
||||||
placeholder={t("pages.auth.register.form.option.surname.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="email"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
disabled={!!token}
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.email.label")}
|
|
||||||
placeholder={t("pages.auth.common.form.option.email.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="password"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="password"
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.password.label")}
|
|
||||||
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="confirm"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="password"
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.confirmPassword.label")}
|
|
||||||
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
type="submit"
|
|
||||||
loading={loading}
|
|
||||||
>
|
|
||||||
{t("pages.auth.register.submit")}
|
|
||||||
</Button>
|
|
||||||
</BaseAuthPage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RegisterPage;
|
|
||||||
+9
-13
@@ -1,32 +1,26 @@
|
|||||||
import Stack, { type StackProps } from "@mui/material/Stack";
|
// Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
import Typography from "@mui/material/Typography";
|
import Typography from "@mui/material/Typography";
|
||||||
import Logo from "@/assets/icons/checkmate-icon.svg?react";
|
import Logo from "@/assets/icons/checkmate-icon.svg?react";
|
||||||
import { LanguageSelector, SwitchTheme } from "@/Components/v2/inputs";
|
import LanguageSelector from "@/Components/LanguageSelector.jsx";
|
||||||
|
import ThemeSwitch from "@/Components/v1/ThemeSwitch/index.jsx";
|
||||||
|
|
||||||
|
// Utils
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
interface HeaderAuthControlsProps extends StackProps {
|
const AuthHeader = ({ hideLogo = false }) => {
|
||||||
hideLogo?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const HeaderAuthControls = ({
|
|
||||||
hideLogo = false,
|
|
||||||
...stackProps
|
|
||||||
}: HeaderAuthControlsProps) => {
|
|
||||||
// Hooks
|
// Hooks
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
width={"100%"}
|
|
||||||
direction="row"
|
direction="row"
|
||||||
alignItems="center"
|
alignItems="center"
|
||||||
justifyContent="space-between"
|
justifyContent="space-between"
|
||||||
px={theme.spacing(12)}
|
px={theme.spacing(12)}
|
||||||
gap={theme.spacing(4)}
|
gap={theme.spacing(4)}
|
||||||
{...stackProps}
|
|
||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -46,8 +40,10 @@ export const HeaderAuthControls = ({
|
|||||||
alignItems="center"
|
alignItems="center"
|
||||||
>
|
>
|
||||||
<LanguageSelector />
|
<LanguageSelector />
|
||||||
<SwitchTheme />
|
<ThemeSwitch />
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default AuthHeader;
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
import Background from "@/assets/Images/background-grid.svg?react";
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import Box from "@mui/material/Box";
|
||||||
|
import Typography from "@mui/material/Typography";
|
||||||
|
import AuthHeader from "./AuthHeader.jsx";
|
||||||
|
import { useTheme } from "@mui/material/styles";
|
||||||
|
import Logo from "@/assets/icons/checkmate-icon.svg?react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const AuthPageWrapper = ({ children, heading, welcome }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
gap={theme.spacing(10)}
|
||||||
|
minHeight="100vh"
|
||||||
|
position="relative"
|
||||||
|
backgroundColor={theme.palette.primary.main}
|
||||||
|
sx={{ overflow: "hidden" }}
|
||||||
|
>
|
||||||
|
<AuthHeader hideLogo={true} />
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
top: 0,
|
||||||
|
left: "0%",
|
||||||
|
transform: "translate(-40%, -40%)",
|
||||||
|
zIndex: 0,
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
"& svg g g:last-of-type path": {
|
||||||
|
stroke: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Background style={{ width: "100%" }} />
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
position: "absolute",
|
||||||
|
bottom: 0,
|
||||||
|
right: 0,
|
||||||
|
transform: "translate(45%, 55%)",
|
||||||
|
zIndex: 0,
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
"& svg g g:last-of-type path": {
|
||||||
|
stroke: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Background style={{ width: "100%" }} />
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
backgroundColor={theme.palette.primary.main}
|
||||||
|
sx={{
|
||||||
|
borderRadius: theme.spacing(8),
|
||||||
|
boxShadow: theme.palette.tertiary.cardShadow,
|
||||||
|
margin: "auto",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: theme.spacing(10),
|
||||||
|
padding: theme.spacing(20),
|
||||||
|
zIndex: 1,
|
||||||
|
position: "relative",
|
||||||
|
width: {
|
||||||
|
sm: "60%",
|
||||||
|
md: "50%",
|
||||||
|
lg: "40%",
|
||||||
|
xl: "30%",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
mb={theme.spacing(10)}
|
||||||
|
mt={theme.spacing(5)}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: { xs: 60, sm: 70, md: 80 },
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Logo style={{ width: "100%", height: "100%" }} />
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
mb={theme.spacing(4)}
|
||||||
|
textAlign="center"
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="h1"
|
||||||
|
mb={theme.spacing(2)}
|
||||||
|
>
|
||||||
|
{welcome}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="h1">{heading}</Typography>
|
||||||
|
</Stack>
|
||||||
|
{children}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AuthPageWrapper;
|
||||||
|
|
||||||
|
AuthPageWrapper.propTypes = {
|
||||||
|
children: PropTypes.node,
|
||||||
|
heading: PropTypes.node,
|
||||||
|
welcome: PropTypes.node,
|
||||||
|
};
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
import {
|
|
||||||
Table,
|
|
||||||
Pagination,
|
|
||||||
ValueLabel,
|
|
||||||
StatusLabel,
|
|
||||||
} from "@/Components/v2/design-elements";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import type { Header } from "@/Components/v2/design-elements/Table";
|
|
||||||
import type { Monitor, MonitorStatus } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
|
||||||
import { useNavigate } from "react-router";
|
|
||||||
import type { Check } from "@/Types/Check";
|
|
||||||
import type { RootState } from "@/Types/state";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
|
|
||||||
export const ChecksTable = ({
|
|
||||||
monitors,
|
|
||||||
checks,
|
|
||||||
checksCount,
|
|
||||||
page,
|
|
||||||
setPage,
|
|
||||||
rowsPerPage,
|
|
||||||
setRowsPerPage,
|
|
||||||
}: {
|
|
||||||
monitors: Monitor[] | null;
|
|
||||||
checks: Check[];
|
|
||||||
checksCount: number;
|
|
||||||
page: number;
|
|
||||||
setPage: (page: number) => void;
|
|
||||||
rowsPerPage: number;
|
|
||||||
setRowsPerPage: (rowsPerPage: number) => void;
|
|
||||||
}) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
|
|
||||||
const navigate = useNavigate();
|
|
||||||
|
|
||||||
const getHeaders = (t: Function, uiTimezone: string) => {
|
|
||||||
const headers: Header<Check>[] = [
|
|
||||||
{
|
|
||||||
id: "monitorName",
|
|
||||||
content: t("common.table.headers.monitor"),
|
|
||||||
render: (row) => {
|
|
||||||
return (
|
|
||||||
monitors?.find((monitor) => monitor.id === row.metadata.monitorId)?.name ||
|
|
||||||
"N/A"
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "status",
|
|
||||||
content: "Status",
|
|
||||||
render: (row) => {
|
|
||||||
return <StatusLabel status={row.status as MonitorStatus} />;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "date",
|
|
||||||
content: t("common.table.headers.dateTime"),
|
|
||||||
render: (row) => {
|
|
||||||
return formatDateWithTz(
|
|
||||||
row.createdAt,
|
|
||||||
"ddd, MMMM D, YYYY, HH:mm A",
|
|
||||||
uiTimezone
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "statusCode",
|
|
||||||
content: t("pages.checks.table.headers.statusCode"),
|
|
||||||
render: (row) => {
|
|
||||||
const code = row.statusCode;
|
|
||||||
if (!code) return "N/A";
|
|
||||||
const value = code < 300 ? "positive" : code < 400 ? "neutral" : "negative";
|
|
||||||
return (
|
|
||||||
<ValueLabel
|
|
||||||
value={value}
|
|
||||||
text={String(code)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "message",
|
|
||||||
content: t("common.table.headers.message"),
|
|
||||||
render: (row) => {
|
|
||||||
return row.message || "N/A";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
return headers;
|
|
||||||
};
|
|
||||||
|
|
||||||
const headers = getHeaders(t, uiTimezone);
|
|
||||||
|
|
||||||
const handlePageChange = (
|
|
||||||
_e: React.MouseEvent<HTMLButtonElement> | null,
|
|
||||||
newPage: number
|
|
||||||
) => {
|
|
||||||
setPage(newPage);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRowsPerPageChange = (
|
|
||||||
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
|
||||||
) => {
|
|
||||||
const value = Number(e.target.value);
|
|
||||||
setPage(0);
|
|
||||||
setRowsPerPage(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Table
|
|
||||||
headers={headers}
|
|
||||||
data={checks}
|
|
||||||
onRowClick={(row) => {
|
|
||||||
navigate(`/checks/${row.id}`);
|
|
||||||
}}
|
|
||||||
emptyViewText={t("pages.checks.table.empty")}
|
|
||||||
/>
|
|
||||||
<Pagination
|
|
||||||
component="div"
|
|
||||||
count={checksCount}
|
|
||||||
page={page}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
onPageChange={handlePageChange}
|
|
||||||
onRowsPerPageChange={handleRowsPerPageChange}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
//Components
|
||||||
|
import Stack from "@mui/material/Stack";
|
||||||
|
import DataTable from "@/Components/v1/Table/index.jsx";
|
||||||
|
import Table from "@mui/material/Table";
|
||||||
|
import TableBody from "@mui/material/TableBody";
|
||||||
|
import TableRow from "@mui/material/TableRow";
|
||||||
|
import TableCell from "@mui/material/TableCell";
|
||||||
|
import TableSkeleton from "@/Components/v1/Table/skeleton.jsx";
|
||||||
|
import Pagination from "@/Components/v1/Table/TablePagination/index.jsx";
|
||||||
|
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
||||||
|
import { HttpStatusLabel } from "@/Components/v1/HttpStatusLabel/index.jsx";
|
||||||
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { formatDateWithTz } from "@/Utils/timeUtilsLegacy.js";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { useState } from "react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useFetchChecksTeam, useFetchChecksByMonitor } from "@/Hooks/checkHooks.js";
|
||||||
|
import { Typography, useTheme } from "@mui/material";
|
||||||
|
import { lighten } from "@mui/material/styles";
|
||||||
|
|
||||||
|
const GetTooltip = (row) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const phases = row?.timings?.phases;
|
||||||
|
|
||||||
|
const phaseKeyFormattingMap = {
|
||||||
|
firstByte: "first byte",
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
backgroundColor={lighten(theme.palette.primary.main, 0.1)}
|
||||||
|
border={`1px solid ${theme.palette.primary.lowContrast}`}
|
||||||
|
borderRadius={theme.shape.borderRadius}
|
||||||
|
py={theme.spacing(2)}
|
||||||
|
px={theme.spacing(4)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
>{`Status code: ${row?.statusCode}`}</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
>{`Response time: ${row?.responseTime} ms`}</Typography>
|
||||||
|
{phases && (
|
||||||
|
<>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
>{`Request timing: `}</Typography>
|
||||||
|
<Table
|
||||||
|
size="small"
|
||||||
|
sx={{ ml: theme.spacing(2), mt: theme.spacing(2) }}
|
||||||
|
>
|
||||||
|
<TableBody>
|
||||||
|
{Object.keys(phases)?.map((phaseKey) => (
|
||||||
|
<TableRow key={phaseKey}>
|
||||||
|
<TableCell sx={{ border: "none", p: 0 }}>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
color="success"
|
||||||
|
>
|
||||||
|
{`${phaseKeyFormattingMap[phaseKey] || phaseKey}:`}
|
||||||
|
</Typography>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell sx={{ border: "none", p: 0 }}>
|
||||||
|
<Typography
|
||||||
|
color={theme.palette.primary.contrastText}
|
||||||
|
variant="body2"
|
||||||
|
>{`${phases[phaseKey]} ms`}</Typography>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const IncidentTable = ({
|
||||||
|
isLoading,
|
||||||
|
monitors,
|
||||||
|
selectedMonitor,
|
||||||
|
filter,
|
||||||
|
dateRange,
|
||||||
|
updateTrigger,
|
||||||
|
}) => {
|
||||||
|
//Redux state
|
||||||
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
|
||||||
|
//Local state
|
||||||
|
const [page, setPage] = useState(0);
|
||||||
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
|
const selectedMonitorDetails = monitors?.[selectedMonitor];
|
||||||
|
const selectedMonitorType = selectedMonitorDetails?.type;
|
||||||
|
|
||||||
|
//Hooks
|
||||||
|
const [checksMonitor, checksCountMonitor, isLoadingMonitor, networkErrorMonitor] =
|
||||||
|
useFetchChecksByMonitor({
|
||||||
|
monitorId: selectedMonitor === "0" ? undefined : selectedMonitor,
|
||||||
|
type: selectedMonitorType,
|
||||||
|
status: false,
|
||||||
|
sortOrder: "desc",
|
||||||
|
limit: null,
|
||||||
|
dateRange,
|
||||||
|
filter: filter === "resolved" ? "all" : filter,
|
||||||
|
ack: filter === "resolved" ? true : false,
|
||||||
|
page: page,
|
||||||
|
rowsPerPage: rowsPerPage,
|
||||||
|
enabled: selectedMonitor !== "0",
|
||||||
|
updateTrigger,
|
||||||
|
});
|
||||||
|
|
||||||
|
const [checksTeam, checksCountTeam, isLoadingTeam, networkErrorTeam] =
|
||||||
|
useFetchChecksTeam({
|
||||||
|
status: false,
|
||||||
|
sortOrder: "desc",
|
||||||
|
limit: null,
|
||||||
|
dateRange,
|
||||||
|
filter: filter === "resolved" ? "all" : filter,
|
||||||
|
ack: filter === "resolved" ? true : false,
|
||||||
|
page: page,
|
||||||
|
rowsPerPage: rowsPerPage,
|
||||||
|
enabled: selectedMonitor === "0",
|
||||||
|
updateTrigger,
|
||||||
|
});
|
||||||
|
|
||||||
|
const checks = selectedMonitor === "0" ? checksTeam : checksMonitor;
|
||||||
|
const checksCount = selectedMonitor === "0" ? checksCountTeam : checksCountMonitor;
|
||||||
|
isLoading = isLoadingTeam || isLoadingMonitor;
|
||||||
|
const networkError = selectedMonitor === "0" ? networkErrorTeam : networkErrorMonitor;
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
//Handlers
|
||||||
|
const handleChangePage = (_, newPage) => {
|
||||||
|
setPage(newPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChangeRowsPerPage = (event) => {
|
||||||
|
setRowsPerPage(event.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{
|
||||||
|
id: "monitorName",
|
||||||
|
content: t("incidentsTableMonitorName"),
|
||||||
|
render: (row) => {
|
||||||
|
return monitors?.[row.metadata?.monitorId]?.name || "N/A";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
content: t("incidentsTableStatus"),
|
||||||
|
render: (row) => {
|
||||||
|
const status = row.status === true ? "up" : "down";
|
||||||
|
return (
|
||||||
|
<StatusLabel
|
||||||
|
status={status}
|
||||||
|
text={status}
|
||||||
|
customStyles={{ textTransform: "capitalize" }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "dateTime",
|
||||||
|
content: t("incidentsTableDateTime"),
|
||||||
|
render: (row) => {
|
||||||
|
const formattedDate = formatDateWithTz(
|
||||||
|
row.createdAt,
|
||||||
|
"YYYY-MM-DD HH:mm:ss A",
|
||||||
|
uiTimezone
|
||||||
|
);
|
||||||
|
return formattedDate;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "statusCode",
|
||||||
|
content: t("incidentsTableStatusCode"),
|
||||||
|
render: (row) => <HttpStatusLabel status={row.statusCode} />,
|
||||||
|
},
|
||||||
|
{ id: "message", content: t("incidentsTableMessage"), render: (row) => row.message },
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isLoading) return <TableSkeleton />;
|
||||||
|
|
||||||
|
if (networkError) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
<NetworkError />
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoading && typeof checksCount === "undefined") {
|
||||||
|
return <GenericFallback>{t("incidentsTableNoIncidents")}</GenericFallback>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DataTable
|
||||||
|
headers={headers}
|
||||||
|
data={checks}
|
||||||
|
config={{ tooltipContent: GetTooltip }}
|
||||||
|
/>
|
||||||
|
<Pagination
|
||||||
|
paginationLabel={t("incidentsTablePaginationLabel")}
|
||||||
|
itemCount={checksCount}
|
||||||
|
page={page}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
handleChangePage={handleChangePage}
|
||||||
|
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
IncidentTable.propTypes = {
|
||||||
|
isLoading: PropTypes.bool,
|
||||||
|
monitors: PropTypes.object,
|
||||||
|
selectedMonitor: PropTypes.string,
|
||||||
|
filter: PropTypes.string,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
|
updateTrigger: PropTypes.bool,
|
||||||
|
setUpdateTrigger: PropTypes.func,
|
||||||
|
};
|
||||||
|
export default IncidentTable;
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack, Typography, Button, ButtonGroup } from "@mui/material";
|
||||||
|
import Select from "@/Components/v1/Inputs/Select/index.jsx";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import SkeletonLayout from "./skeleton.jsx";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
|
const OptionsHeader = ({
|
||||||
|
shouldRender,
|
||||||
|
selectedMonitor = 0,
|
||||||
|
setSelectedMonitor,
|
||||||
|
monitors,
|
||||||
|
filter = "all",
|
||||||
|
setFilter,
|
||||||
|
dateRange = "hour",
|
||||||
|
setDateRange,
|
||||||
|
}) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const monitorNames = typeof monitors !== "undefined" ? Object.values(monitors) : [];
|
||||||
|
const filterOptions = [
|
||||||
|
{ id: "all", name: t("incidentsOptionsHeaderFilterAll") },
|
||||||
|
{ id: "down", name: t("incidentsOptionsHeaderFilterDown") },
|
||||||
|
{ id: "resolve", name: t("incidentsOptionsHeaderFilterCannotResolve") },
|
||||||
|
{ id: "resolved", name: t("incidentsOptionsHeaderFilterResolved") },
|
||||||
|
];
|
||||||
|
|
||||||
|
// The stacks below which are three in number have the same style so
|
||||||
|
const stackStyles = {
|
||||||
|
direction: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: theme.spacing(6),
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!shouldRender) return <SkeletonLayout />;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<Stack {...stackStyles}>
|
||||||
|
<Typography
|
||||||
|
display="inline-block"
|
||||||
|
component="h1"
|
||||||
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeader")}
|
||||||
|
</Typography>
|
||||||
|
<Select
|
||||||
|
id="incidents-select-monitor"
|
||||||
|
placeholder={t("incidentsOptionsPlaceholderAllServers")}
|
||||||
|
value={selectedMonitor}
|
||||||
|
onChange={(e) => setSelectedMonitor(e.target.value)}
|
||||||
|
items={monitorNames}
|
||||||
|
sx={{
|
||||||
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
color: theme.palette.primary.contrastTextSecondary,
|
||||||
|
}}
|
||||||
|
maxWidth={250}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack {...stackStyles}>
|
||||||
|
<Typography
|
||||||
|
display="inline-block"
|
||||||
|
component="h1"
|
||||||
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeaderFilterBy")}
|
||||||
|
</Typography>
|
||||||
|
<Select
|
||||||
|
id="incidents-select-filter"
|
||||||
|
value={filter}
|
||||||
|
onChange={(e) => setFilter(e.target.value)}
|
||||||
|
items={filterOptions}
|
||||||
|
sx={{
|
||||||
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
color: theme.palette.primary.contrastTextSecondary,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack {...stackStyles}>
|
||||||
|
<Typography
|
||||||
|
display="inline-block"
|
||||||
|
component="h1"
|
||||||
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeaderShow")}
|
||||||
|
</Typography>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "hour").toString()}
|
||||||
|
onClick={() => setDateRange("hour")}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeaderLastHour")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "day").toString()}
|
||||||
|
onClick={() => setDateRange("day")}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeaderLastDay")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "week").toString()}
|
||||||
|
onClick={() => setDateRange("week")}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeaderLastWeek")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "all").toString()}
|
||||||
|
onClick={() => setDateRange("all")}
|
||||||
|
>
|
||||||
|
{t("incidentsOptionsHeaderFilterAll")}
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
OptionsHeader.propTypes = {
|
||||||
|
shouldRender: PropTypes.bool,
|
||||||
|
selectedMonitor: PropTypes.string,
|
||||||
|
setSelectedMonitor: PropTypes.func,
|
||||||
|
monitors: PropTypes.object,
|
||||||
|
filter: PropTypes.string,
|
||||||
|
setFilter: PropTypes.func,
|
||||||
|
dateRange: PropTypes.string,
|
||||||
|
setDateRange: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default OptionsHeader;
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { Stack, Skeleton } from "@mui/material";
|
||||||
|
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Skeleton height={40} />
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SkeletonLayout;
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import Background from "@/assets/Images/background-grid.svg?react";
|
||||||
|
import Icon from "@/Components/v1/Icon";
|
||||||
|
|
||||||
|
const StatusBox = ({ title, value, status }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
let sharedStyles = {
|
||||||
|
position: "absolute",
|
||||||
|
right: 8,
|
||||||
|
"& svg": {
|
||||||
|
width: 20,
|
||||||
|
height: 20,
|
||||||
|
opacity: 0.9,
|
||||||
|
"& path": { stroke: theme.palette.primary.contrastTextTertiary, strokeWidth: 1.7 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
let color;
|
||||||
|
let icon;
|
||||||
|
if (status === "up") {
|
||||||
|
color = theme.palette.success.lowContrast;
|
||||||
|
icon = (
|
||||||
|
<Box sx={{ ...sharedStyles, top: theme.spacing(6), right: theme.spacing(6) }}>
|
||||||
|
<Icon
|
||||||
|
name="CheckCircle"
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
} else if (status === "down") {
|
||||||
|
color = theme.palette.error.lowContrast;
|
||||||
|
icon = (
|
||||||
|
<Box sx={{ ...sharedStyles, top: theme.spacing(6), right: theme.spacing(6) }}>
|
||||||
|
<Icon
|
||||||
|
name="X"
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
} else if (status === "paused") {
|
||||||
|
color = theme.palette.warning.lowContrast;
|
||||||
|
icon = (
|
||||||
|
<Box sx={{ ...sharedStyles, top: theme.spacing(6), right: theme.spacing(6) }}>
|
||||||
|
<Icon
|
||||||
|
name="AlertTriangle"
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
color = theme.palette.accent.main;
|
||||||
|
icon = (
|
||||||
|
<Box sx={{ ...sharedStyles, top: theme.spacing(6), right: theme.spacing(6) }}>
|
||||||
|
<Icon
|
||||||
|
name="Bell"
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
position="relative"
|
||||||
|
flex={1}
|
||||||
|
border={1}
|
||||||
|
backgroundColor={theme.palette.primary.main}
|
||||||
|
borderColor={theme.palette.primary.lowContrast}
|
||||||
|
borderRadius={theme.shape.borderRadius}
|
||||||
|
p={theme.spacing(8)}
|
||||||
|
overflow="hidden"
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
position="absolute"
|
||||||
|
top="-10%"
|
||||||
|
left="5%"
|
||||||
|
>
|
||||||
|
<Background />
|
||||||
|
</Box>
|
||||||
|
<Stack direction="column">
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
mb={theme.spacing(8)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant={"h2"}
|
||||||
|
textTransform="uppercase"
|
||||||
|
color={theme.palette.primary.contrastTextTertiary}
|
||||||
|
>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
{icon}
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="flex-start"
|
||||||
|
fontSize={theme.typography.h1.fontSize}
|
||||||
|
fontWeight={600}
|
||||||
|
color={color}
|
||||||
|
gap={theme.spacing(1)}
|
||||||
|
>
|
||||||
|
{value}
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
fontSize={theme.typography.label.fontSize}
|
||||||
|
fontWeight={300}
|
||||||
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
|
sx={{
|
||||||
|
opacity: 0.3,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
#
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
StatusBox.propTypes = {
|
||||||
|
title: PropTypes.string.isRequired,
|
||||||
|
value: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
|
||||||
|
status: PropTypes.string,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default StatusBox;
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { Stack } from "@mui/material";
|
||||||
|
import StatusBox from "./StatusBox.jsx";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import SkeletonLayout from "./skeleton.jsx";
|
||||||
|
|
||||||
|
const StatusBoxes = ({ isLoading, summary }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
if (isLoading) return <SkeletonLayout shouldRender={isLoading} />;
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
gap={theme.spacing(12)}
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<StatusBox
|
||||||
|
title={t("incidentsOptionsHeaderTotalIncidents")}
|
||||||
|
value={summary?.totalChecks + summary?.cannotResolveChecks || 0}
|
||||||
|
/>
|
||||||
|
<StatusBox
|
||||||
|
title={t("incidentsOptionsHeaderFilterResolved")}
|
||||||
|
status="up"
|
||||||
|
value={summary?.resolvedChecks || 0}
|
||||||
|
/>
|
||||||
|
<StatusBox
|
||||||
|
title={t("incidentsOptionsHeaderFilterCannotResolve")}
|
||||||
|
status="paused"
|
||||||
|
value={summary?.cannotResolveChecks || 0}
|
||||||
|
/>
|
||||||
|
<StatusBox
|
||||||
|
title={t("incidentsOptionsHeaderFilterDown")}
|
||||||
|
status="down"
|
||||||
|
value={summary?.downChecks || 0}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
StatusBoxes.propTypes = {
|
||||||
|
isLoading: PropTypes.bool,
|
||||||
|
summary: PropTypes.object,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default StatusBoxes;
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { Skeleton, Stack } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
|
const SkeletonLayout = () => {
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
gap={theme.spacing(12)}
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={100}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={100}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={100}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={100}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SkeletonLayout;
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack } from "@mui/material";
|
||||||
|
import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
|
||||||
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
|
import IncidentTable from "./Components/IncidentTable/index.jsx";
|
||||||
|
import OptionsHeader from "./Components/OptionsHeader/index.jsx";
|
||||||
|
import StatusBoxes from "./Components/StatusBoxes/index.jsx";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useFetchMonitorsByTeamId } from "@/Hooks/monitorHooks.js";
|
||||||
|
import { useFetchChecksSummaryByTeamId } from "@/Hooks/checkHooks.js";
|
||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
|
||||||
|
//Constants
|
||||||
|
const Checks = () => {
|
||||||
|
// Redux state
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const BREADCRUMBS = [{ name: t("checksPageTitle"), path: "/checks" }];
|
||||||
|
|
||||||
|
// Local state
|
||||||
|
const [selectedMonitor, setSelectedMonitor] = useState("0");
|
||||||
|
const [filter, setFilter] = useState(undefined);
|
||||||
|
const [dateRange, setDateRange] = useState("hour");
|
||||||
|
const [monitorLookup, setMonitorLookup] = useState(undefined);
|
||||||
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
|
|
||||||
|
//Hooks
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
const theme = useTheme();
|
||||||
|
const [monitors, , isLoading, networkError] = useFetchMonitorsByTeamId({});
|
||||||
|
const [summary, isLoadingSummary, networkErrorSummary] = useFetchChecksSummaryByTeamId({
|
||||||
|
dateRange,
|
||||||
|
updateTrigger,
|
||||||
|
});
|
||||||
|
const { monitorId } = useParams();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (monitorId) {
|
||||||
|
setSelectedMonitor(monitorId);
|
||||||
|
}
|
||||||
|
}, [monitorId]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const monitorLookup = monitors?.reduce((acc, monitor) => {
|
||||||
|
acc[monitor.id] = {
|
||||||
|
id: monitor.id,
|
||||||
|
name: monitor.name,
|
||||||
|
type: monitor.type,
|
||||||
|
};
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
setMonitorLookup(monitorLookup);
|
||||||
|
}, [monitors]);
|
||||||
|
|
||||||
|
if (networkError || networkErrorSummary) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
<NetworkError />
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.spacing(10)}>
|
||||||
|
<Breadcrumbs list={BREADCRUMBS} />
|
||||||
|
|
||||||
|
<StatusBoxes
|
||||||
|
isLoading={isLoadingSummary}
|
||||||
|
summary={summary}
|
||||||
|
/>
|
||||||
|
<OptionsHeader
|
||||||
|
shouldRender={!isLoading}
|
||||||
|
monitors={monitorLookup}
|
||||||
|
selectedMonitor={selectedMonitor}
|
||||||
|
setSelectedMonitor={setSelectedMonitor}
|
||||||
|
filter={filter}
|
||||||
|
setFilter={setFilter}
|
||||||
|
dateRange={dateRange}
|
||||||
|
setDateRange={setDateRange}
|
||||||
|
/>
|
||||||
|
<IncidentTable
|
||||||
|
isLoading={isLoading}
|
||||||
|
monitors={monitorLookup ? monitorLookup : {}}
|
||||||
|
selectedMonitor={selectedMonitor}
|
||||||
|
filter={filter}
|
||||||
|
dateRange={dateRange}
|
||||||
|
updateTrigger={updateTrigger}
|
||||||
|
setUpdateTrigger={setUpdateTrigger}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Checks;
|
||||||
@@ -1,176 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import {
|
|
||||||
BasePage,
|
|
||||||
TotalChecksBox,
|
|
||||||
UpChecksBox,
|
|
||||||
DownChecksBox,
|
|
||||||
} from "@/Components/v2/design-elements";
|
|
||||||
import { HeaderTimeRange } from "@/Components/v2/common";
|
|
||||||
import { Select } from "@/Components/v2/inputs";
|
|
||||||
import { ChecksTable } from "./Components/ChecksTable";
|
|
||||||
|
|
||||||
import { MenuItem } from "@mui/material";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useState, useMemo } from "react";
|
|
||||||
import { useParams } from "react-router-dom";
|
|
||||||
import { useGet } from "@/Hooks/UseApi";
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
|
||||||
import type { ChecksSummary, ChecksResponse } from "@/Types/Check";
|
|
||||||
|
|
||||||
const Checks = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { monitorId } = useParams<{ monitorId?: string }>();
|
|
||||||
|
|
||||||
const [selectedMonitor, setSelectedMonitor] = useState<string>(monitorId || "0");
|
|
||||||
const [dateRange, setDateRange] = useState<string>("recent");
|
|
||||||
const [statusFilter, setStatusFilter] = useState<string>("down");
|
|
||||||
const [page, setPage] = useState<number>(0);
|
|
||||||
const [rowsPerPage, setRowsPerPage] = useState<number>(10);
|
|
||||||
|
|
||||||
const monitorsUrl = "/monitors/team";
|
|
||||||
const summaryUrl = `/checks/team/summary?dateRange=${dateRange}`;
|
|
||||||
|
|
||||||
const { data: monitorsResponse, isLoading: isLoadingMonitors } =
|
|
||||||
useGet<Monitor[]>(monitorsUrl);
|
|
||||||
|
|
||||||
const { data: summaryResponse, isLoading: isLoadingSummary } =
|
|
||||||
useGet<ChecksSummary>(summaryUrl);
|
|
||||||
|
|
||||||
const selectedMonitorType = monitorsResponse?.find(
|
|
||||||
(m) => m.id === selectedMonitor
|
|
||||||
)?.type;
|
|
||||||
|
|
||||||
const teamChecksUrl = useMemo(() => {
|
|
||||||
if (selectedMonitor !== "0") return null;
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("sortOrder", "desc");
|
|
||||||
if (dateRange) params.append("dateRange", dateRange);
|
|
||||||
if (statusFilter) params.append("filter", statusFilter);
|
|
||||||
params.append("page", String(page));
|
|
||||||
params.append("rowsPerPage", String(rowsPerPage));
|
|
||||||
return `/checks/team?${params.toString()}`;
|
|
||||||
}, [selectedMonitor, dateRange, statusFilter, page, rowsPerPage]);
|
|
||||||
|
|
||||||
const monitorChecksUrl = useMemo(() => {
|
|
||||||
if (selectedMonitor === "0" || !selectedMonitorType) return null;
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
params.append("type", selectedMonitorType);
|
|
||||||
params.append("sortOrder", "desc");
|
|
||||||
if (statusFilter) params.append("filter", statusFilter);
|
|
||||||
if (dateRange) params.append("dateRange", dateRange);
|
|
||||||
params.append("page", String(page));
|
|
||||||
params.append("rowsPerPage", String(rowsPerPage));
|
|
||||||
return `/checks/${selectedMonitor}?${params.toString()}`;
|
|
||||||
}, [selectedMonitor, selectedMonitorType, dateRange, statusFilter, page, rowsPerPage]);
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: teamChecksData,
|
|
||||||
isLoading: isLoadingTeamChecks,
|
|
||||||
isValidating: isValidatingTeamChecks,
|
|
||||||
} = useGet<ChecksResponse>(
|
|
||||||
teamChecksUrl,
|
|
||||||
{},
|
|
||||||
{ keepPreviousData: true, refreshInterval: 30000 }
|
|
||||||
);
|
|
||||||
const {
|
|
||||||
data: monitorChecksData,
|
|
||||||
isLoading: isLoadingMonitorChecks,
|
|
||||||
isValidating: isValidatingMonitorChecks,
|
|
||||||
} = useGet<ChecksResponse>(
|
|
||||||
monitorChecksUrl,
|
|
||||||
{},
|
|
||||||
{ keepPreviousData: true, refreshInterval: 30000 }
|
|
||||||
);
|
|
||||||
|
|
||||||
const checks =
|
|
||||||
selectedMonitor === "0"
|
|
||||||
? (teamChecksData?.checks ?? [])
|
|
||||||
: (monitorChecksData?.checks ?? []);
|
|
||||||
const checksCount =
|
|
||||||
selectedMonitor === "0"
|
|
||||||
? (teamChecksData?.checksCount ?? 0)
|
|
||||||
: (monitorChecksData?.checksCount ?? 0);
|
|
||||||
|
|
||||||
const isLoadingChecks =
|
|
||||||
isLoadingTeamChecks ||
|
|
||||||
isLoadingMonitorChecks ||
|
|
||||||
isValidatingTeamChecks ||
|
|
||||||
isValidatingMonitorChecks;
|
|
||||||
|
|
||||||
const isLoading = isLoadingMonitors || isLoadingSummary || isLoadingChecks;
|
|
||||||
const totalChecks = summaryResponse?.totalChecks || 0;
|
|
||||||
const downChecks = summaryResponse?.downChecks || 0;
|
|
||||||
const upChecks = totalChecks - (summaryResponse?.downChecks || 0);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BasePage>
|
|
||||||
<Stack
|
|
||||||
direction={{ xs: "column", md: "row" }}
|
|
||||||
gap={4}
|
|
||||||
>
|
|
||||||
<TotalChecksBox n={totalChecks} />
|
|
||||||
<UpChecksBox n={upChecks} />
|
|
||||||
<DownChecksBox n={downChecks || 0} />
|
|
||||||
</Stack>
|
|
||||||
|
|
||||||
<Stack
|
|
||||||
direction={{ xs: "column", md: "row" }}
|
|
||||||
justifyContent="space-between"
|
|
||||||
alignItems={{ xs: "stretch", md: "center" }}
|
|
||||||
gap={2}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
gap={2}
|
|
||||||
direction={{ xs: "column", md: "row" }}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
fullWidth
|
|
||||||
value={selectedMonitor}
|
|
||||||
onChange={(e: any) => {
|
|
||||||
setSelectedMonitor(e.target.value);
|
|
||||||
setPage(0);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MenuItem value="0">{t("pages.checks.selects.monitor.all")}</MenuItem>
|
|
||||||
{monitorsResponse?.map((monitor) => (
|
|
||||||
<MenuItem
|
|
||||||
key={monitor.id}
|
|
||||||
value={monitor.id}
|
|
||||||
>
|
|
||||||
{monitor.name}
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
<Select
|
|
||||||
value={statusFilter}
|
|
||||||
onChange={(e: any) => {
|
|
||||||
setStatusFilter(e.target.value);
|
|
||||||
setPage(0);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MenuItem value="all">{t("pages.checks.selects.status.all")}</MenuItem>
|
|
||||||
<MenuItem value="up">{t("pages.checks.selects.status.up")}</MenuItem>
|
|
||||||
<MenuItem value="down">{t("pages.checks.selects.status.down")}</MenuItem>
|
|
||||||
</Select>
|
|
||||||
</Stack>
|
|
||||||
<HeaderTimeRange
|
|
||||||
isLoading={isLoading || isLoadingChecks}
|
|
||||||
dateRange={dateRange}
|
|
||||||
setDateRange={setDateRange}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
|
|
||||||
<ChecksTable
|
|
||||||
monitors={monitorsResponse ?? null}
|
|
||||||
checks={checks}
|
|
||||||
checksCount={checksCount}
|
|
||||||
page={page}
|
|
||||||
setPage={setPage}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
setRowsPerPage={setRowsPerPage}
|
|
||||||
/>
|
|
||||||
</BasePage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Checks;
|
|
||||||
@@ -1,710 +0,0 @@
|
|||||||
import { useMemo, useState } from "react";
|
|
||||||
import { useEffect } from "react";
|
|
||||||
import { useParams, useLocation, useNavigate } from "react-router";
|
|
||||||
import { useForm, Controller } from "react-hook-form";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import RadioGroup from "@mui/material/RadioGroup";
|
|
||||||
import FormControl from "@mui/material/FormControl";
|
|
||||||
import { Trans, useTranslation } from "react-i18next";
|
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Link from "@mui/material/Link";
|
|
||||||
import Divider from "@mui/material/Divider";
|
|
||||||
import IconButton from "@mui/material/IconButton";
|
|
||||||
import { Trash2 } from "lucide-react";
|
|
||||||
import { HeaderDeleteControls } from "@/Components/v2/monitors";
|
|
||||||
|
|
||||||
import { BasePage, ConfigBox } from "@/Components/v2/design-elements";
|
|
||||||
import {
|
|
||||||
RadioWithDescription,
|
|
||||||
Button,
|
|
||||||
TextField,
|
|
||||||
Select,
|
|
||||||
Autocomplete,
|
|
||||||
SwitchComponent as Switch,
|
|
||||||
SliderWithLabel,
|
|
||||||
Dialog,
|
|
||||||
} from "@/Components/v2/inputs";
|
|
||||||
import { useGet, usePost, usePatch, useDelete } from "@/Hooks/UseApi";
|
|
||||||
import { useMonitorForm } from "@/Hooks/useMonitorForm";
|
|
||||||
import type { Monitor, MonitorType, GamesMap } from "@/Types/Monitor";
|
|
||||||
import type { Notification } from "@/Types/Notification";
|
|
||||||
import type { MonitorFormData } from "@/Validation/monitor";
|
|
||||||
|
|
||||||
interface GeneralSettingsConfig {
|
|
||||||
urlLabel: string;
|
|
||||||
urlPlaceholder: string;
|
|
||||||
namePlaceholder: string;
|
|
||||||
showUrl: boolean;
|
|
||||||
showPort: boolean;
|
|
||||||
showGameSelect: boolean;
|
|
||||||
showSecret: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getGeneralSettingsConfig = (
|
|
||||||
type: MonitorType,
|
|
||||||
t: (key: string) => string
|
|
||||||
): GeneralSettingsConfig => {
|
|
||||||
const configs: Record<string, GeneralSettingsConfig> = {
|
|
||||||
http: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: false,
|
|
||||||
showGameSelect: false,
|
|
||||||
showSecret: false,
|
|
||||||
},
|
|
||||||
ping: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.host.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.host.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: false,
|
|
||||||
showGameSelect: false,
|
|
||||||
showSecret: false,
|
|
||||||
},
|
|
||||||
docker: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.container.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.container.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: false,
|
|
||||||
showGameSelect: false,
|
|
||||||
showSecret: false,
|
|
||||||
},
|
|
||||||
port: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: true,
|
|
||||||
showGameSelect: false,
|
|
||||||
showSecret: false,
|
|
||||||
},
|
|
||||||
game: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: true,
|
|
||||||
showGameSelect: true,
|
|
||||||
showSecret: false,
|
|
||||||
},
|
|
||||||
pagespeed: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: false,
|
|
||||||
showGameSelect: false,
|
|
||||||
showSecret: false,
|
|
||||||
},
|
|
||||||
hardware: {
|
|
||||||
urlLabel: t("pages.createMonitor.form.general.option.url.label"),
|
|
||||||
urlPlaceholder: t("pages.createMonitor.form.general.option.url.placeholder"),
|
|
||||||
namePlaceholder: t("pages.createMonitor.form.general.option.name.placeholder"),
|
|
||||||
showUrl: true,
|
|
||||||
showPort: false,
|
|
||||||
showGameSelect: false,
|
|
||||||
showSecret: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return configs[type] || configs.http;
|
|
||||||
};
|
|
||||||
|
|
||||||
const CreateMonitorPage = () => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const { monitorId } = useParams();
|
|
||||||
const location = useLocation();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const isEditMode = Boolean(monitorId);
|
|
||||||
|
|
||||||
// Extract page type from URL path (e.g., /pagespeed/create -> pagespeed)
|
|
||||||
const pageType = useMemo(() => {
|
|
||||||
const pathSegments = location.pathname.split("/").filter(Boolean);
|
|
||||||
const firstSegment = pathSegments[0];
|
|
||||||
if (firstSegment === "pagespeed") return "pagespeed";
|
|
||||||
if (firstSegment === "infrastructure") return "hardware";
|
|
||||||
return "uptime";
|
|
||||||
}, [location.pathname]);
|
|
||||||
|
|
||||||
const showTypeSelector = pageType === "uptime" && !isEditMode;
|
|
||||||
const defaultType: MonitorType =
|
|
||||||
pageType === "pagespeed"
|
|
||||||
? "pagespeed"
|
|
||||||
: pageType === "hardware"
|
|
||||||
? "hardware"
|
|
||||||
: "http";
|
|
||||||
|
|
||||||
const { data: existingMonitor, refetch: refetchMonitor } = useGet<Monitor>(
|
|
||||||
isEditMode ? `/monitors/${monitorId}` : null
|
|
||||||
);
|
|
||||||
|
|
||||||
const { data: notifications } = useGet<Notification[]>("/notifications/team");
|
|
||||||
const { data: games } = useGet<GamesMap>("/monitors/games");
|
|
||||||
|
|
||||||
const { schema, defaults } = useMonitorForm({
|
|
||||||
data: existingMonitor ?? null,
|
|
||||||
defaultType,
|
|
||||||
});
|
|
||||||
|
|
||||||
const form = useForm<MonitorFormData>({
|
|
||||||
resolver: zodResolver(schema),
|
|
||||||
defaultValues: defaults,
|
|
||||||
});
|
|
||||||
const { control, watch, handleSubmit, clearErrors } = form;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
form.reset(defaults);
|
|
||||||
}, [defaults, form]);
|
|
||||||
|
|
||||||
const watchedType = watch("type") as MonitorType;
|
|
||||||
|
|
||||||
const watchedUseAdvancedMatching = watch("useAdvancedMatching") as boolean;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
clearErrors();
|
|
||||||
}, [watchedType, clearErrors]);
|
|
||||||
|
|
||||||
const generalSettingsConfig = useMemo(
|
|
||||||
() => getGeneralSettingsConfig(watchedType, t),
|
|
||||||
[watchedType, t]
|
|
||||||
);
|
|
||||||
|
|
||||||
const { post, loading: isCreating } = usePost<MonitorFormData, Monitor>();
|
|
||||||
const { patch, loading: isUpdating } = usePatch<MonitorFormData, Monitor>();
|
|
||||||
const isSubmitting = isCreating || isUpdating;
|
|
||||||
// Delete functionality
|
|
||||||
const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false);
|
|
||||||
const { deleteFn, loading: isDeleting } = useDelete();
|
|
||||||
|
|
||||||
const handleDeleteClick = () => {
|
|
||||||
setIsDeleteDialogOpen(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteConfirm = async () => {
|
|
||||||
if (!monitorId) return;
|
|
||||||
await deleteFn(`/monitors/${monitorId}`);
|
|
||||||
setIsDeleteDialogOpen(false);
|
|
||||||
// Navigate based on page type
|
|
||||||
if (pageType === "pagespeed") {
|
|
||||||
navigate("/pagespeed");
|
|
||||||
} else if (pageType === "hardware") {
|
|
||||||
navigate("/infrastructure");
|
|
||||||
} else {
|
|
||||||
navigate("/uptime");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDeleteCancel = () => {
|
|
||||||
setIsDeleteDialogOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSubmit = async (data: MonitorFormData) => {
|
|
||||||
let result;
|
|
||||||
if (isEditMode && monitorId) {
|
|
||||||
result = await patch(`/monitors/${monitorId}`, data);
|
|
||||||
} else {
|
|
||||||
result = await post("/monitors", data);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result?.success) {
|
|
||||||
if (pageType === "pagespeed") {
|
|
||||||
navigate("/pagespeed");
|
|
||||||
} else if (pageType === "hardware") {
|
|
||||||
navigate("/infrastructure");
|
|
||||||
} else {
|
|
||||||
navigate("/uptime");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onError = (errors: unknown) => {
|
|
||||||
console.log(errors);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<BasePage
|
|
||||||
component="form"
|
|
||||||
onSubmit={handleSubmit(onSubmit, onError)}
|
|
||||||
>
|
|
||||||
<HeaderDeleteControls
|
|
||||||
monitor={existingMonitor}
|
|
||||||
isAdmin={true}
|
|
||||||
refetch={refetchMonitor}
|
|
||||||
onDelete={handleDeleteClick}
|
|
||||||
/>
|
|
||||||
{/* Monitor Type Selection - only shown for uptime monitors */}
|
|
||||||
{showTypeSelector && (
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.type.title")}
|
|
||||||
subtitle={t("pages.createMonitor.form.type.description")}
|
|
||||||
rightContent={
|
|
||||||
<Controller
|
|
||||||
name="type"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<FormControl error={!!fieldState.error}>
|
|
||||||
<RadioGroup
|
|
||||||
{...field}
|
|
||||||
sx={{ gap: theme.spacing(6) }}
|
|
||||||
>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="http"
|
|
||||||
label={t("pages.createMonitor.form.type.optionHttp")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionHttpDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="ping"
|
|
||||||
label={t("pages.createMonitor.form.type.optionPing")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionPingDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="docker"
|
|
||||||
label={t("pages.createMonitor.form.type.optionDocker")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionDockerDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="port"
|
|
||||||
label={t("pages.createMonitor.form.type.optionPort")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionPortDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<RadioWithDescription
|
|
||||||
value="game"
|
|
||||||
label={t("pages.createMonitor.form.type.optionGame")}
|
|
||||||
description={t(
|
|
||||||
"pages.createMonitor.form.type.optionGameDescription"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</RadioGroup>
|
|
||||||
</FormControl>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.general.title")}
|
|
||||||
subtitle={t(`pages.createMonitor.form.general.description.${watchedType}`)}
|
|
||||||
rightContent={
|
|
||||||
<Stack spacing={theme.spacing(8)}>
|
|
||||||
{/* URL/Host/Container field - not shown for hardware */}
|
|
||||||
{generalSettingsConfig.showUrl && (
|
|
||||||
<Controller
|
|
||||||
name="url"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={generalSettingsConfig.urlLabel}
|
|
||||||
placeholder={generalSettingsConfig.urlPlaceholder}
|
|
||||||
fullWidth
|
|
||||||
disabled={isEditMode}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Port field - only for port and game types */}
|
|
||||||
{generalSettingsConfig.showPort && (
|
|
||||||
<Controller
|
|
||||||
name="port"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
onChange={(e) => field.onChange(Number(e.target.value) || 0)}
|
|
||||||
type="number"
|
|
||||||
fieldLabel={t("portToMonitor")}
|
|
||||||
placeholder="5173"
|
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Game select - only for game type */}
|
|
||||||
{generalSettingsConfig.showGameSelect && (
|
|
||||||
<Controller
|
|
||||||
name="gameId"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Select
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
fieldLabel={t("chooseGame")}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
>
|
|
||||||
<MenuItem value="">Select a game</MenuItem>
|
|
||||||
{games &&
|
|
||||||
Object.entries(games).map(([key, game]) => (
|
|
||||||
<MenuItem
|
|
||||||
key={key}
|
|
||||||
value={key}
|
|
||||||
>
|
|
||||||
{game.name}
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Secret field - only for hardware type */}
|
|
||||||
{generalSettingsConfig.showSecret && (
|
|
||||||
<Controller
|
|
||||||
name="secret"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={t("pages.createMonitor.form.general.option.secret.label")}
|
|
||||||
placeholder={t(
|
|
||||||
"pages.createMonitor.form.general.option.secret.placeholder"
|
|
||||||
)}
|
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Controller
|
|
||||||
name="name"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="text"
|
|
||||||
fieldLabel={t("pages.createMonitor.form.general.option.name.label")}
|
|
||||||
placeholder={generalSettingsConfig.namePlaceholder}
|
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.frequency.title")}
|
|
||||||
subtitle={t("pages.createMonitor.form.frequency.description")}
|
|
||||||
rightContent={
|
|
||||||
<Controller
|
|
||||||
name="interval"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<Select
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? 60000}
|
|
||||||
fieldLabel={t(
|
|
||||||
"pages.createMonitor.form.frequency.option.frequency.label"
|
|
||||||
)}
|
|
||||||
error={!!fieldState.error}
|
|
||||||
>
|
|
||||||
<MenuItem value={15000}>{t("time.fifteenSeconds")}</MenuItem>
|
|
||||||
<MenuItem value={30000}>{t("time.thirtySeconds")}</MenuItem>
|
|
||||||
<MenuItem value={60000}>{t("time.oneMinute")}</MenuItem>
|
|
||||||
<MenuItem value={120000}>{t("time.twoMinutes")}</MenuItem>
|
|
||||||
<MenuItem value={180000}>{t("time.threeMinutes")}</MenuItem>
|
|
||||||
<MenuItem value={240000}>{t("time.fourMinutes")}</MenuItem>
|
|
||||||
<MenuItem value={300000}>{t("time.fiveMinutes")}</MenuItem>
|
|
||||||
<MenuItem value={600000}>{t("time.tenMinutes")}</MenuItem>
|
|
||||||
<MenuItem value={900000}>{t("time.fifteenMinutes")}</MenuItem>
|
|
||||||
<MenuItem value={1800000}>{t("time.thirtyMinutes")}</MenuItem>
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.incidents.title")}
|
|
||||||
subtitle={t("pages.createMonitor.form.incidents.description")}
|
|
||||||
rightContent={
|
|
||||||
<Stack spacing={theme.spacing(12)}>
|
|
||||||
<Controller
|
|
||||||
name="statusWindowSize"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<SliderWithLabel
|
|
||||||
{...field}
|
|
||||||
sliderMaxWidth={{ xs: "100%", md: "50%" }}
|
|
||||||
fieldLabel={t("pages.createMonitor.form.incidents.option.checks.label")}
|
|
||||||
min={1}
|
|
||||||
max={25}
|
|
||||||
valueLabelDisplay="auto"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="statusWindowThreshold"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<SliderWithLabel
|
|
||||||
{...field}
|
|
||||||
sliderMaxWidth={{ xs: "100%", md: "50%" }}
|
|
||||||
fieldLabel={t(
|
|
||||||
"pages.createMonitor.form.incidents.option.percentage.label"
|
|
||||||
)}
|
|
||||||
min={1}
|
|
||||||
max={100}
|
|
||||||
valueLabelDisplay="auto"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.notifications.title")}
|
|
||||||
subtitle={t("pages.createMonitor.form.notifications.description")}
|
|
||||||
rightContent={
|
|
||||||
<Controller
|
|
||||||
name="notifications"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => {
|
|
||||||
// Map notifications to have 'name' property for v2 Autocomplete
|
|
||||||
const notificationOptions = (notifications ?? []).map((n) => ({
|
|
||||||
...n,
|
|
||||||
name: n.notificationName,
|
|
||||||
}));
|
|
||||||
const selectedNotifications = notificationOptions.filter((n) =>
|
|
||||||
(field.value ?? []).includes(n.id)
|
|
||||||
);
|
|
||||||
return (
|
|
||||||
<Stack spacing={theme.spacing(4)}>
|
|
||||||
<Autocomplete
|
|
||||||
multiple
|
|
||||||
options={notificationOptions}
|
|
||||||
value={selectedNotifications}
|
|
||||||
getOptionLabel={(option) => option.name}
|
|
||||||
onChange={(_: unknown, newValue: typeof notificationOptions) => {
|
|
||||||
field.onChange(newValue.map((n) => n.id));
|
|
||||||
}}
|
|
||||||
isOptionEqualToValue={(option, value) => option.id === value.id}
|
|
||||||
/>
|
|
||||||
{selectedNotifications.length > 0 && (
|
|
||||||
<Stack
|
|
||||||
flex={1}
|
|
||||||
width="100%"
|
|
||||||
>
|
|
||||||
{selectedNotifications.map((notification, index) => (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
key={notification.id}
|
|
||||||
width="100%"
|
|
||||||
>
|
|
||||||
<Typography flexGrow={1}>
|
|
||||||
{notification.notificationName}
|
|
||||||
</Typography>
|
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
onClick={() => {
|
|
||||||
field.onChange(
|
|
||||||
(field.value ?? []).filter(
|
|
||||||
(id: string) => id !== notification.id
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
aria-label="Remove notification"
|
|
||||||
>
|
|
||||||
<Trash2 size={16} />
|
|
||||||
</IconButton>
|
|
||||||
{index < selectedNotifications.length - 1 && <Divider />}
|
|
||||||
</Stack>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{watchedType === "http" && (
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.ignoreTls.title")}
|
|
||||||
subtitle={t("pages.createMonitor.form.ignoreTls.description")}
|
|
||||||
rightContent={
|
|
||||||
<Controller
|
|
||||||
name="ignoreTlsErrors"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
spacing={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Switch
|
|
||||||
checked={field.value ?? false}
|
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
|
||||||
/>
|
|
||||||
<Typography>
|
|
||||||
{t("pages.createMonitor.form.ignoreTls.option.tls.label")}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{watchedType === "http" && (
|
|
||||||
<ConfigBox
|
|
||||||
title={t("pages.createMonitor.form.advanced.title")}
|
|
||||||
subtitle={t("pages.createMonitor.form.advanced.description")}
|
|
||||||
rightContent={
|
|
||||||
<Stack spacing={theme.spacing(8)}>
|
|
||||||
<Controller
|
|
||||||
name="useAdvancedMatching"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
spacing={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Switch
|
|
||||||
checked={field.value ?? false}
|
|
||||||
onChange={(e) => field.onChange(e.target.checked)}
|
|
||||||
/>
|
|
||||||
<Typography>
|
|
||||||
{t(
|
|
||||||
"pages.createMonitor.form.advanced.option.advancedMatching.label"
|
|
||||||
)}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
{watchedUseAdvancedMatching && (
|
|
||||||
<Stack spacing={theme.spacing(8)}>
|
|
||||||
<Controller
|
|
||||||
name="matchMethod"
|
|
||||||
control={control}
|
|
||||||
render={({ field }) => (
|
|
||||||
<Select
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? "equal"}
|
|
||||||
fieldLabel={t(
|
|
||||||
"pages.createMonitor.form.advanced.option.matchMethod.label"
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<MenuItem value="equal">{t("matchMethodOptions.equal")}</MenuItem>
|
|
||||||
<MenuItem value="include">
|
|
||||||
{t("matchMethodOptions.include")}
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem value="regex">{t("matchMethodOptions.regex")}</MenuItem>
|
|
||||||
</Select>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="expectedValue"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
fieldLabel={t(
|
|
||||||
"pages.createMonitor.form.advanced.option.expectedValue.label"
|
|
||||||
)}
|
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="jsonPath"
|
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
value={field.value ?? ""}
|
|
||||||
fieldLabel={t(
|
|
||||||
"pages.createMonitor.form.advanced.option.jsonPath.label"
|
|
||||||
)}
|
|
||||||
fullWidth
|
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
color="text.secondary"
|
|
||||||
sx={{ opacity: 0.8 }}
|
|
||||||
>
|
|
||||||
<Trans
|
|
||||||
i18nKey="pages.createMonitor.form.advanced.option.jsonPath.description"
|
|
||||||
components={{
|
|
||||||
jmesLink: (
|
|
||||||
<Link
|
|
||||||
href="https://jmespath.org/"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
loading={isSubmitting}
|
|
||||||
type="submit"
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
>
|
|
||||||
{t("common.buttons.save")}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
<Dialog
|
|
||||||
open={isDeleteDialogOpen}
|
|
||||||
title={t("common.dialogs.delete.title")}
|
|
||||||
content={t("common.dialogs.delete.description")}
|
|
||||||
onConfirm={handleDeleteConfirm}
|
|
||||||
onCancel={handleDeleteCancel}
|
|
||||||
loading={isDeleting}
|
|
||||||
/>
|
|
||||||
</BasePage>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default CreateMonitorPage;
|
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import PanelSkeleton from "../IncidentsSummaryPanel/skeleton.jsx";
|
||||||
|
import Icon from "@/Components/v1/Icon";
|
||||||
|
import SummaryCard from "../SummaryCard/index.jsx";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActiveIncidentsPanel Component
|
||||||
|
*
|
||||||
|
* Displays a quick overview of currently active incidents.
|
||||||
|
* Shows only essential information: monitor name, status badge, and duration.
|
||||||
|
*
|
||||||
|
* @param {Object} props
|
||||||
|
* @param {Array} props.incidents - Array of active incidents
|
||||||
|
* @param {number} props.totalCount - Total count of active incidents (for badge)
|
||||||
|
* @param {boolean} props.isLoading - Loading state
|
||||||
|
* @param {Object} props.error - Error object if any
|
||||||
|
* @param {Function} props.onIncidentClick - Callback when incident is clicked (optional)
|
||||||
|
*/
|
||||||
|
const ActiveIncidentsPanel = ({ totalCount = 0, isLoading = false, error = null }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <PanelSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<SummaryCard>
|
||||||
|
<Typography
|
||||||
|
color="error"
|
||||||
|
align="center"
|
||||||
|
>
|
||||||
|
{t("incidentsPage.incidentsActivePanelError")}
|
||||||
|
</Typography>
|
||||||
|
</SummaryCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!totalCount || totalCount === 0) {
|
||||||
|
return (
|
||||||
|
<SummaryCard title={t("incidentsPage.incidentsActivePanelTitle")}>
|
||||||
|
<Stack
|
||||||
|
direction="column"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
|
padding={theme.spacing(6)}
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.success.main,
|
||||||
|
"& svg": {
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
"& path": { stroke: "currentColor", strokeWidth: 2 },
|
||||||
|
},
|
||||||
|
mb: theme.spacing(1),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="CheckCircle"
|
||||||
|
size={60}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: 13,
|
||||||
|
textTransform: "uppercase",
|
||||||
|
fontWeight: 500,
|
||||||
|
textAlign: "center",
|
||||||
|
color: theme.palette.success.lowContrast,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.allSystemsAreOperational")}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</SummaryCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SummaryCard title={t("incidentsPage.incidentsActivePanelTitle")}>
|
||||||
|
<Stack
|
||||||
|
direction="column"
|
||||||
|
alignItems="center"
|
||||||
|
justifyContent="center"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
color: theme.palette.error.lowContrast,
|
||||||
|
"& svg": {
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
"& path": { stroke: "currentColor", strokeWidth: 2 },
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="AlertTriangle"
|
||||||
|
size={60}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
|
fontSize: 32,
|
||||||
|
fontWeight: 600,
|
||||||
|
color: theme.palette.error.lowContrast,
|
||||||
|
lineHeight: 1,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{totalCount}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</SummaryCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
ActiveIncidentsPanel.propTypes = {
|
||||||
|
totalCount: PropTypes.number,
|
||||||
|
isLoading: PropTypes.bool,
|
||||||
|
error: PropTypes.object,
|
||||||
|
onIncidentClick: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ActiveIncidentsPanel;
|
||||||
@@ -1,195 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Grid from "@mui/material/Grid";
|
|
||||||
import Divider from "@mui/material/Divider";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import { BaseBox, ValueLabel } from "@/Components/v2/design-elements";
|
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import type { Incident } from "@/Types/Incident";
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import type { RootState } from "@/Types/state";
|
|
||||||
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
|
||||||
import { getIncidentsDuration } from "@/Pages/Incidents/utils";
|
|
||||||
|
|
||||||
interface CardDetailsProps {
|
|
||||||
incident: Incident | null;
|
|
||||||
monitor: Monitor | null;
|
|
||||||
sx?: object;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const CardDetails = ({ incident, monitor, sx }: CardDetailsProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
|
|
||||||
|
|
||||||
if (!incident) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
sx={sx}
|
|
||||||
>
|
|
||||||
<Typography textTransform={"uppercase"}>
|
|
||||||
{t("pages.incidents.dialog.details.title")}
|
|
||||||
</Typography>
|
|
||||||
<BaseBox padding={8}>
|
|
||||||
<Stack gap={theme.spacing(4)}>
|
|
||||||
<Typography textTransform={"uppercase"}>
|
|
||||||
{t("pages.incidents.dialog.details.overview")}
|
|
||||||
</Typography>
|
|
||||||
<Divider />
|
|
||||||
|
|
||||||
<Grid
|
|
||||||
container
|
|
||||||
spacing={theme.spacing(4)}
|
|
||||||
alignItems="center"
|
|
||||||
>
|
|
||||||
<Grid size={2}>{t("pages.incidents.dialog.details.status")}</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<ValueLabel
|
|
||||||
value={incident.status ? "negative" : "positive"}
|
|
||||||
text={
|
|
||||||
incident.status
|
|
||||||
? t("common.labels.active")
|
|
||||||
: t("common.labels.resolved")
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
{monitor && (
|
|
||||||
<>
|
|
||||||
<Grid size={2}>{t("pages.incidents.dialog.details.monitor")}</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<Typography>{monitor.name ?? "N/A"}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.url")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<Typography>{monitor.url ?? "N/A"}</Typography>
|
|
||||||
</Grid>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Grid>
|
|
||||||
</Stack>
|
|
||||||
</BaseBox>
|
|
||||||
<BaseBox padding={8}>
|
|
||||||
<Stack gap={theme.spacing(4)}>
|
|
||||||
<Typography textTransform={"uppercase"}>
|
|
||||||
{t("pages.incidents.dialog.details.analysis")}
|
|
||||||
</Typography>
|
|
||||||
<Divider />
|
|
||||||
<Grid
|
|
||||||
container
|
|
||||||
spacing={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Grid size={6}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.timeline")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={6}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.detailsLabel")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={6}>
|
|
||||||
<Divider></Divider>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={6}>
|
|
||||||
<Divider></Divider>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.startedAt")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={4}>
|
|
||||||
<Typography>
|
|
||||||
{formatDateWithTz(incident.startTime, "D MMM YYYY, h:mm A", uiTimezone)}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.statusCode")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={4}>
|
|
||||||
<Typography>{incident.statusCode ?? "N/A"}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.downtime")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={4}>
|
|
||||||
<Typography>{getIncidentsDuration(incident)}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.message")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={4}>
|
|
||||||
<Typography>{incident.message ?? "N/A"}</Typography>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Stack>
|
|
||||||
</BaseBox>
|
|
||||||
{!incident.status && (
|
|
||||||
<BaseBox padding={8}>
|
|
||||||
<Stack gap={theme.spacing(4)}>
|
|
||||||
<Typography textTransform={"uppercase"}>
|
|
||||||
{t("pages.incidents.dialog.details.resolutionDetails")}
|
|
||||||
</Typography>
|
|
||||||
<Divider />
|
|
||||||
<Grid
|
|
||||||
container
|
|
||||||
spacing={theme.spacing(2)}
|
|
||||||
alignItems="center"
|
|
||||||
>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.resolvedAt")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<Typography>
|
|
||||||
{incident.endTime
|
|
||||||
? formatDateWithTz(incident.endTime, "D MMM YYYY, h:mm A", uiTimezone)
|
|
||||||
: "N/A"}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>
|
|
||||||
{t("pages.incidents.dialog.details.resolutionType")}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<Typography>
|
|
||||||
{incident.resolutionType
|
|
||||||
? t(
|
|
||||||
`pages.incidents.dialog.details.resolutionTypes.${incident.resolutionType}`
|
|
||||||
)
|
|
||||||
: "N/A"}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
{incident.resolvedBy && (
|
|
||||||
<>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>
|
|
||||||
{t("pages.incidents.dialog.details.resolvedBy")}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<Typography>
|
|
||||||
{incident.resolvedByEmail ?? incident.resolvedBy}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{incident.comment && (
|
|
||||||
<>
|
|
||||||
<Grid size={2}>
|
|
||||||
<Typography>{t("pages.incidents.dialog.details.comment")}</Typography>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={10}>
|
|
||||||
<Typography>{incident.comment}</Typography>
|
|
||||||
</Grid>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Grid>
|
|
||||||
</Stack>
|
|
||||||
</BaseBox>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,247 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import Divider from "@mui/material/Divider";
|
|
||||||
import Grid from "@mui/material/Grid";
|
|
||||||
import { BaseBox, ValueLabel } from "@/Components/v2/design-elements";
|
|
||||||
import { CircleCheck, TriangleAlert, Bell, Wrench, Globe } from "lucide-react";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
import type { IncidentSummary, IncidentSummaryItem } from "@/Types/Incident";
|
|
||||||
import { getIncidentsDuration } from "@/Pages/Incidents/utils";
|
|
||||||
|
|
||||||
interface SummaryItemProps {
|
|
||||||
icon: React.ReactNode;
|
|
||||||
label: string;
|
|
||||||
value: string | number;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SummaryItem = ({ icon, label, value }: SummaryItemProps) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="space-between"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
alignItems="center"
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
<Typography variant="body2">{label}</Typography>
|
|
||||||
</Stack>
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
fontWeight={600}
|
|
||||||
>
|
|
||||||
{value}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface SummaryCardProps {
|
|
||||||
title: string;
|
|
||||||
sx?: React.CSSProperties;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SummaryCard = ({
|
|
||||||
title,
|
|
||||||
sx,
|
|
||||||
children,
|
|
||||||
}: React.PropsWithChildren<SummaryCardProps>) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
return (
|
|
||||||
<BaseBox
|
|
||||||
sx={{ ...sx }}
|
|
||||||
padding={8}
|
|
||||||
flex={1}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
height="100%"
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
sx={{
|
|
||||||
textTransform: "uppercase",
|
|
||||||
fontWeight: 500,
|
|
||||||
fontSize: 13,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</Typography>
|
|
||||||
<Divider />
|
|
||||||
{children}
|
|
||||||
</Stack>
|
|
||||||
</BaseBox>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface SummaryCardActiveIncidentsProps {
|
|
||||||
summary?: IncidentSummary | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SummaryCardActiveIncidents = ({
|
|
||||||
summary,
|
|
||||||
}: SummaryCardActiveIncidentsProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
if (!summary) return null;
|
|
||||||
|
|
||||||
const activeCount = summary.totalActive;
|
|
||||||
const hasActive = activeCount > 0;
|
|
||||||
const color = hasActive ? theme.palette.error.main : theme.palette.success.main;
|
|
||||||
const icon = hasActive ? (
|
|
||||||
<TriangleAlert color={color} />
|
|
||||||
) : (
|
|
||||||
<CircleCheck color={color} />
|
|
||||||
);
|
|
||||||
const msg = t("pages.incidents.summaryCard.activeIncidents.active", {
|
|
||||||
count: activeCount,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SummaryCard
|
|
||||||
title={t("pages.incidents.summaryCard.activeIncidents.title")}
|
|
||||||
sx={{ height: "100%" }}
|
|
||||||
>
|
|
||||||
<Stack
|
|
||||||
flex={1}
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="center"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
<Typography>{msg}</Typography>
|
|
||||||
</Stack>
|
|
||||||
</SummaryCard>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const SummaryIncidentItem = ({ incident }: { incident: IncidentSummaryItem }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const duration = getIncidentsDuration(incident);
|
|
||||||
return (
|
|
||||||
<Grid
|
|
||||||
container
|
|
||||||
alignItems="center"
|
|
||||||
spacing={2}
|
|
||||||
sx={{
|
|
||||||
width: "100%",
|
|
||||||
py: theme.spacing(0.5),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Grid
|
|
||||||
size={{ xs: 12, lg: 5 }}
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "flex-start",
|
|
||||||
gap: theme.spacing(2),
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Globe />
|
|
||||||
<Typography
|
|
||||||
variant="body1"
|
|
||||||
fontWeight={500}
|
|
||||||
noWrap
|
|
||||||
>
|
|
||||||
{incident.monitorName ?? t("common.labels.na")}
|
|
||||||
</Typography>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<Grid
|
|
||||||
size={{ xs: 12, md: 6, lg: 3 }}
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ValueLabel
|
|
||||||
value={incident.status ? "negative" : "positive"}
|
|
||||||
text={incident.status ? t("common.labels.active") : t("common.labels.resolved")}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
|
|
||||||
<Grid
|
|
||||||
size={{ xs: 12, md: 6, lg: 4 }}
|
|
||||||
sx={{
|
|
||||||
textAlign: { xs: "left", md: "right" },
|
|
||||||
fontWeight: 500,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="body1">{duration}</Typography>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface SummaryCardLatestIncidentsProps {
|
|
||||||
summary?: IncidentSummary | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SummaryCardLatestIncidents = ({
|
|
||||||
summary,
|
|
||||||
}: SummaryCardLatestIncidentsProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
|
|
||||||
const latestIncidents = summary?.latestIncidents ?? [];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<SummaryCard title={t("pages.incidents.summaryCard.latestIncidents.title")}>
|
|
||||||
<Stack gap={theme.spacing(4)}>
|
|
||||||
{latestIncidents.slice(0, 3).map((incident, index) => (
|
|
||||||
<Box key={incident.id}>
|
|
||||||
<SummaryIncidentItem incident={incident} />
|
|
||||||
{index < latestIncidents.length - 1 && (
|
|
||||||
<Divider sx={{ mt: theme.spacing(2) }} />
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
))}
|
|
||||||
</Stack>
|
|
||||||
</SummaryCard>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
interface SummaryCardStatsProps {
|
|
||||||
summary?: IncidentSummary | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SummaryCardStats = ({ summary }: SummaryCardStatsProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
if (!summary) return null;
|
|
||||||
const mostAffected =
|
|
||||||
!summary.total || summary.total === 0
|
|
||||||
? t("common.labels.na")
|
|
||||||
: summary.topMonitor?.monitorName || t("common.labels.na");
|
|
||||||
return (
|
|
||||||
<SummaryCard title={t("pages.incidents.summaryCard.incidentStats.title")}>
|
|
||||||
<SummaryItem
|
|
||||||
icon={<Bell size={18} />}
|
|
||||||
label={t("pages.incidents.summaryCard.incidentStats.totalIncidents")}
|
|
||||||
value={summary?.total || 0}
|
|
||||||
/>
|
|
||||||
<SummaryItem
|
|
||||||
icon={<TriangleAlert size={18} />}
|
|
||||||
label={t("pages.incidents.summaryCard.incidentStats.mostAffectedMonitor")}
|
|
||||||
value={mostAffected}
|
|
||||||
/>
|
|
||||||
<SummaryItem
|
|
||||||
icon={<Wrench size={18} />}
|
|
||||||
label={t("pages.incidents.summaryCard.incidentStats.avgResolutionTime")}
|
|
||||||
value={
|
|
||||||
summary.total > 0
|
|
||||||
? `${summary.avgResolutionTimeHours || 0} hours`
|
|
||||||
: t("common.labels.na")
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</SummaryCard>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
import Stack from "@mui/material/Stack";
|
|
||||||
import { Select, Button } from "@/Components/v2/inputs";
|
|
||||||
import MenuItem from "@mui/material/MenuItem";
|
|
||||||
import useMediaQuery from "@mui/material/useMediaQuery";
|
|
||||||
import { Typography, useTheme } from "@mui/material";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
const resolutionTypes = ["all", "manual", "automatic"];
|
|
||||||
|
|
||||||
interface ControlsIncidentFilterProps {
|
|
||||||
monitors?: Monitor[];
|
|
||||||
selectedMonitor: string;
|
|
||||||
setSelectedMonitor: React.Dispatch<React.SetStateAction<string>>;
|
|
||||||
selectedResolutionType: string;
|
|
||||||
setSelectedResolutionType: React.Dispatch<React.SetStateAction<string>>;
|
|
||||||
onClearFilters: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ControlsIncidentFilter = ({
|
|
||||||
monitors,
|
|
||||||
selectedMonitor,
|
|
||||||
setSelectedMonitor,
|
|
||||||
selectedResolutionType,
|
|
||||||
setSelectedResolutionType,
|
|
||||||
onClearFilters,
|
|
||||||
}: ControlsIncidentFilterProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
|
|
||||||
const isFilterActive =
|
|
||||||
selectedMonitor !== "0" ||
|
|
||||||
(selectedResolutionType !== "" && selectedResolutionType !== "all");
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Stack
|
|
||||||
direction={isSmall ? "column" : "row"}
|
|
||||||
gap={theme.spacing(2)}
|
|
||||||
>
|
|
||||||
<Select
|
|
||||||
placeholder={t("pages.incidents.filters.monitor")}
|
|
||||||
value={selectedMonitor}
|
|
||||||
onChange={(e) => setSelectedMonitor(e.target.value)}
|
|
||||||
>
|
|
||||||
<MenuItem value="0">
|
|
||||||
<Typography>{t("pages.incidents.filters.allMonitors")}</Typography>
|
|
||||||
</MenuItem>
|
|
||||||
{monitors?.map((monitor) => (
|
|
||||||
<MenuItem
|
|
||||||
key={monitor.id}
|
|
||||||
value={monitor.id}
|
|
||||||
>
|
|
||||||
<Typography>{monitor.name}</Typography>
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
<Select
|
|
||||||
placeholder={t("pages.incidents.filters.resolutionType")}
|
|
||||||
value={selectedResolutionType}
|
|
||||||
onChange={(e) => setSelectedResolutionType(e.target.value)}
|
|
||||||
>
|
|
||||||
{resolutionTypes.map((type) => (
|
|
||||||
<MenuItem
|
|
||||||
key={type}
|
|
||||||
value={type}
|
|
||||||
>
|
|
||||||
<Typography textTransform="capitalize">
|
|
||||||
{t(`pages.incidents.filters.resolutionTypes.${type}`)}
|
|
||||||
</Typography>
|
|
||||||
</MenuItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
{isFilterActive && (
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
onClick={onClearFilters}
|
|
||||||
>
|
|
||||||
{t("pages.incidents.filters.clearFilters")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
import { Dialog } from "@/Components/v2/inputs";
|
|
||||||
import { CardDetails } from "@/Pages/Incidents/Components/CardDetails";
|
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import type { Incident } from "@/Types/Incident";
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
|
||||||
|
|
||||||
interface DialogIncidentDetailsProps {
|
|
||||||
open: boolean;
|
|
||||||
incident: Incident | null;
|
|
||||||
monitor: Monitor | null;
|
|
||||||
onClose: () => void;
|
|
||||||
onResolve: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DialogIncidentDetails = ({
|
|
||||||
open,
|
|
||||||
incident,
|
|
||||||
monitor,
|
|
||||||
onClose,
|
|
||||||
onResolve,
|
|
||||||
}: DialogIncidentDetailsProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const isActive = incident?.status === true;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog
|
|
||||||
open={open}
|
|
||||||
onCancel={onClose}
|
|
||||||
onConfirm={isActive ? onResolve : undefined}
|
|
||||||
cancelText={t("common.buttons.close")}
|
|
||||||
confirmText={isActive ? t("pages.incidents.dialog.details.resolve") : undefined}
|
|
||||||
maxWidth="sm"
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
<CardDetails
|
|
||||||
incident={incident}
|
|
||||||
monitor={monitor}
|
|
||||||
/>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
import { useState, useEffect } from "react";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
import { Dialog, TextField } from "@/Components/v2/inputs";
|
|
||||||
import { usePut } from "@/Hooks/UseApi";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useTheme } from "@mui/material";
|
|
||||||
|
|
||||||
interface DialogResolutionProps {
|
|
||||||
open: boolean;
|
|
||||||
incidentId: string | null;
|
|
||||||
onClose: () => void;
|
|
||||||
onResolved?: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DialogResolution = ({
|
|
||||||
open,
|
|
||||||
incidentId,
|
|
||||||
onClose,
|
|
||||||
onResolved,
|
|
||||||
}: DialogResolutionProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const [comment, setComment] = useState("");
|
|
||||||
const { put: resolveIncident, loading: isResolving } = usePut();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (open) {
|
|
||||||
setComment("");
|
|
||||||
}
|
|
||||||
}, [open]);
|
|
||||||
|
|
||||||
const handleCancel = () => {
|
|
||||||
onClose();
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleConfirm = async () => {
|
|
||||||
if (!incidentId) return;
|
|
||||||
const body = comment.trim() ? { comment: comment.trim() } : {};
|
|
||||||
const result = await resolveIncident(`/incidents/${incidentId}/resolve`, body);
|
|
||||||
if (result) {
|
|
||||||
onClose();
|
|
||||||
onResolved?.();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog
|
|
||||||
open={open}
|
|
||||||
title={t("incidentsPage.resolveIncidentDialogTitle")}
|
|
||||||
onCancel={handleCancel}
|
|
||||||
onConfirm={handleConfirm}
|
|
||||||
confirmText={t("incidentsPage.resolveIncidentDialogConfirm")}
|
|
||||||
confirmColor="error"
|
|
||||||
cancelColor="primary"
|
|
||||||
loading={isResolving}
|
|
||||||
maxWidth="sm"
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
<Box sx={{ mt: theme.spacing(4) }}>
|
|
||||||
<TextField
|
|
||||||
fieldLabel={t("incidentsPage.resolveIncidentDialogCommentLabel")}
|
|
||||||
placeholder={t("incidentsPage.resolveIncidentDialogCommentPlaceholder")}
|
|
||||||
value={comment}
|
|
||||||
onChange={(e) => setComment(e.target.value)}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,413 @@
|
|||||||
|
// Components
|
||||||
|
import { Stack, Typography, Grid, Box, Button, Divider } from "@mui/material";
|
||||||
|
import { GenericDialog } from "@/Components/v1/Dialog/genericDialog.jsx";
|
||||||
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
|
import SummaryCard from "../SummaryCard/index.jsx";
|
||||||
|
import ResolveIncidentDialog from "../ResolveIncidentDialog/index.jsx";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { formatDateWithTz } from "@/Utils/timeUtilsLegacy.js";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
// Hooks
|
||||||
|
import useFetchIncidents from "../../hooks/useFetchIncidents.js";
|
||||||
|
import useGetIncidentsDuration from "../../hooks/useGetIncidentsDuration.js";
|
||||||
|
|
||||||
|
const IncidentDetailsModal = ({ open, incidentId, onClose, onResolved }) => {
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { fetchIncidentById, resolveIncident } = useFetchIncidents();
|
||||||
|
const [incidentData, setIncidentData] = useState(null);
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
const [isResolveDialogOpen, setIsResolveDialogOpen] = useState(false);
|
||||||
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
const isActive = incidentData?.incident?.status === true;
|
||||||
|
const duration = useGetIncidentsDuration(incidentData?.incident || null, isActive);
|
||||||
|
|
||||||
|
const statusColor = isActive ? theme.palette.error.main : theme.palette.success.main;
|
||||||
|
const toCapitalLetter = (text) =>
|
||||||
|
typeof text === "string" && text.length > 0
|
||||||
|
? text.charAt(0).toUpperCase() + text.slice(1)
|
||||||
|
: text;
|
||||||
|
|
||||||
|
const KeyValueRow = ({ label, value, sx = {} }) => (
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={2}
|
||||||
|
alignItems="flex-start"
|
||||||
|
sx={{ ...sx }}
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={4}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
sx={{ whiteSpace: "nowrap" }}
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs
|
||||||
|
sx={{ minWidth: 0 }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
textAlign="right"
|
||||||
|
sx={{
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{value ?? "-"}
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const loadIncident = async () => {
|
||||||
|
if (!incidentId || !open) {
|
||||||
|
setIncidentData(null);
|
||||||
|
setIsLoading(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const incidentData = await fetchIncidentById(incidentId);
|
||||||
|
setIncidentData(incidentData);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching incident:", error);
|
||||||
|
setIncidentData(null);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
loadIncident();
|
||||||
|
}, [incidentId, open, fetchIncidentById]);
|
||||||
|
|
||||||
|
const openResolveDialog = () => {
|
||||||
|
setIsResolveDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeResolveDialog = () => {
|
||||||
|
setIsResolveDialogOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAfterResolve = async () => {
|
||||||
|
if (!incidentId) return;
|
||||||
|
const updatedIncident = await fetchIncidentById(incidentId);
|
||||||
|
if (updatedIncident) {
|
||||||
|
setIncidentData(updatedIncident);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const renderContent = () => {
|
||||||
|
if (isLoading) {
|
||||||
|
return (
|
||||||
|
<GenericFallback
|
||||||
|
isLoading={true}
|
||||||
|
message={t("incidentsPage.loadingIncidentDetails")}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!incidentData) {
|
||||||
|
return (
|
||||||
|
<GenericFallback
|
||||||
|
isLoading={false}
|
||||||
|
message={t("incidentsPage.incidentNotFound")}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack gap={theme.spacing(8)}>
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={3}
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
md={12}
|
||||||
|
>
|
||||||
|
<SummaryCard title={t("incidentsPage.overview")}>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(2)}
|
||||||
|
sx={{ mb: theme.spacing(3) }}
|
||||||
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
width: 8,
|
||||||
|
height: 8,
|
||||||
|
borderRadius: "50%",
|
||||||
|
bgcolor: statusColor,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
sx={{
|
||||||
|
color: statusColor,
|
||||||
|
fontWeight: 700,
|
||||||
|
letterSpacing: 0.4,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isActive ? t("incidentsPage.active") : t("incidentsPage.resolved")}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
direction="column"
|
||||||
|
alignItems="start"
|
||||||
|
gap={theme.spacing(3)}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={2}
|
||||||
|
sx={{ alignItems: "baseline" }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
fontWeight={500}
|
||||||
|
sx={{ minWidth: 70 }}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.incidentItemMonitor")}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
>
|
||||||
|
{incidentData?.monitor?.name || t("incidentsPage.unknownMonitor")}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
gap={2}
|
||||||
|
sx={{ alignItems: "baseline" }}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
fontWeight={500}
|
||||||
|
sx={{ minWidth: 70 }}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.URL")}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
variant="body1"
|
||||||
|
sx={{ flex: 1, wordBreak: "break-word", fontFamily: "monospace" }}
|
||||||
|
>
|
||||||
|
{incidentData?.monitor?.url || "-"}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</SummaryCard>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={3}
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sm={12}
|
||||||
|
>
|
||||||
|
<SummaryCard title={t("incidentsPage.incidentAnalysis")}>
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={3}
|
||||||
|
alignItems="stretch"
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sm={6}
|
||||||
|
>
|
||||||
|
<Stack gap={theme.spacing(2)}>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle1"
|
||||||
|
fontWeight={700}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.timeline")}
|
||||||
|
</Typography>
|
||||||
|
<Divider sx={{ mt: 2 }} />
|
||||||
|
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.startedAt")}
|
||||||
|
value={
|
||||||
|
formatDateWithTz(
|
||||||
|
incidentData?.incident?.startTime,
|
||||||
|
"D MMM YYYY, h:mm A",
|
||||||
|
uiTimezone
|
||||||
|
) || "-"
|
||||||
|
}
|
||||||
|
sx={{ paddingBottom: theme.spacing(3) }}
|
||||||
|
/>
|
||||||
|
{!isActive && (
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.endedAt")}
|
||||||
|
value={
|
||||||
|
formatDateWithTz(
|
||||||
|
incidentData?.incident?.endTime,
|
||||||
|
"D MMM YYYY, h:mm A",
|
||||||
|
uiTimezone
|
||||||
|
) || "-"
|
||||||
|
}
|
||||||
|
sx={{ paddingBottom: theme.spacing(3) }}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.downtime")}
|
||||||
|
value={duration || "-"}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
sm="auto"
|
||||||
|
sx={{ display: { xs: "none", sm: "flex" } }}
|
||||||
|
>
|
||||||
|
<Divider
|
||||||
|
orientation="vertical"
|
||||||
|
flexItem
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sm
|
||||||
|
>
|
||||||
|
<Stack gap={theme.spacing(2)}>
|
||||||
|
<Typography
|
||||||
|
variant="subtitle1"
|
||||||
|
sx={{ letterSpacing: 0.6, fontWeight: 700 }}
|
||||||
|
>
|
||||||
|
{isActive
|
||||||
|
? t("incidentsPage.errorDetails")
|
||||||
|
: t("incidentsPage.resolutionDetails")}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Divider sx={{ mt: 2 }} />
|
||||||
|
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.statusCode")}
|
||||||
|
value={incidentData?.incident?.statusCode ?? "-"}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.message")}
|
||||||
|
value={incidentData?.incident?.message ?? "-"}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{!isActive && (
|
||||||
|
<>
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.resolutionMethod")}
|
||||||
|
value={
|
||||||
|
toCapitalLetter(incidentData?.incident?.resolutionType) || "-"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
{incidentData?.incident?.resolutionType === "manual" && (
|
||||||
|
<KeyValueRow
|
||||||
|
label={t("incidentsPage.comment")}
|
||||||
|
value={
|
||||||
|
incidentData?.incident.comment?.trim()
|
||||||
|
? incidentData.incident.comment
|
||||||
|
: t("incidentsPage.noCommentProvided")
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</SummaryCard>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<GenericDialog
|
||||||
|
open={open}
|
||||||
|
onClose={onClose}
|
||||||
|
theme={theme}
|
||||||
|
title={t("incidentsPage.incidentDetails")}
|
||||||
|
width={{ xs: "95%", md: "45%", lg: "40%", xl: "35%" }}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
gap={theme.spacing(6)}
|
||||||
|
sx={{ maxHeight: "70vh", overflowY: "auto", pr: 1 }}
|
||||||
|
>
|
||||||
|
{renderContent()}
|
||||||
|
{!isActive &&
|
||||||
|
incidentData?.incident?.resolutionType === "manual" &&
|
||||||
|
incidentData?.user?.email && (
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
sx={{
|
||||||
|
fontStyle: "italic",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.resolvedBy")}: {incidentData.user.email}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
gap={2}
|
||||||
|
sx={{ pt: theme.spacing(3) }}
|
||||||
|
>
|
||||||
|
{isActive && (
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
color="error"
|
||||||
|
onClick={openResolveDialog}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.incidentsTableActionResolveManually")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
onClick={onClose}
|
||||||
|
>
|
||||||
|
{t("close")}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
<ResolveIncidentDialog
|
||||||
|
open={isResolveDialogOpen}
|
||||||
|
incidentId={incidentId}
|
||||||
|
onClose={closeResolveDialog}
|
||||||
|
onResolve={resolveIncident}
|
||||||
|
onAfterResolve={handleAfterResolve}
|
||||||
|
onResolved={onResolved}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</GenericDialog>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
IncidentDetailsModal.propTypes = {
|
||||||
|
open: PropTypes.bool.isRequired,
|
||||||
|
incidentId: PropTypes.string,
|
||||||
|
onClose: PropTypes.func.isRequired,
|
||||||
|
onResolved: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IncidentDetailsModal;
|
||||||
@@ -1,222 +0,0 @@
|
|||||||
import { Table } from "@/Components/v2/design-elements";
|
|
||||||
import { Pagination } from "@/Components/v2/design-elements/Table";
|
|
||||||
import type { Header } from "@/Components/v2/design-elements/Table";
|
|
||||||
import { ValueLabel } from "@/Components/v2/design-elements";
|
|
||||||
import type { ValueType } from "@/Components/v2/design-elements/StatusLabel";
|
|
||||||
import { ActionsMenu } from "@/Components/v2/actions-menu";
|
|
||||||
import type { Incident } from "@/Types/Incident";
|
|
||||||
import type { Monitor } from "@/Types/Monitor";
|
|
||||||
import type { ActionMenuItem } from "@/Components/v2/actions-menu";
|
|
||||||
import { useTranslation } from "react-i18next";
|
|
||||||
import { useNavigate } from "react-router-dom";
|
|
||||||
import { TypeToPathMap } from "@/Utils/monitorUtilsLegacy.js";
|
|
||||||
import { formatDateWithTz } from "@/Utils/TimeUtils";
|
|
||||||
import { useSelector } from "react-redux";
|
|
||||||
import type { RootState } from "@/Types/state";
|
|
||||||
import Typography from "@mui/material/Typography";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
|
||||||
import Box from "@mui/material/Box";
|
|
||||||
|
|
||||||
interface IncidentsTableProps {
|
|
||||||
title?: string;
|
|
||||||
incidents?: Incident[];
|
|
||||||
monitors?: Monitor[];
|
|
||||||
incidentsCount: number;
|
|
||||||
page: number;
|
|
||||||
setPage: (page: number) => void;
|
|
||||||
rowsPerPage: number;
|
|
||||||
setRowsPerPage: (rowsPerPage: number) => void;
|
|
||||||
onOpenDetails?: (incidentId: string) => void;
|
|
||||||
onResolve?: (incidentId: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const IncidentsTable = ({
|
|
||||||
incidents,
|
|
||||||
monitors,
|
|
||||||
incidentsCount,
|
|
||||||
page,
|
|
||||||
setPage,
|
|
||||||
rowsPerPage,
|
|
||||||
setRowsPerPage,
|
|
||||||
onOpenDetails,
|
|
||||||
onResolve,
|
|
||||||
}: IncidentsTableProps) => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const theme = useTheme();
|
|
||||||
const navigate = useNavigate();
|
|
||||||
const uiTimezone = useSelector((state: RootState) => state.ui.timezone);
|
|
||||||
|
|
||||||
const getActions = (incident: Incident): ActionMenuItem[] => {
|
|
||||||
const monitor = monitors?.find((m) => m.id === incident.monitorId);
|
|
||||||
const isActive = incident.status === true;
|
|
||||||
|
|
||||||
const actions: ActionMenuItem[] = [
|
|
||||||
{
|
|
||||||
id: "details",
|
|
||||||
label: t("pages.incidents.table.actions.details"),
|
|
||||||
action: () => onOpenDetails?.(incident.id),
|
|
||||||
closeMenu: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "goToMonitor",
|
|
||||||
label: t("pages.incidents.table.actions.goToMonitor"),
|
|
||||||
action: () => {
|
|
||||||
if (monitor) {
|
|
||||||
const path = TypeToPathMap[monitor.type as keyof typeof TypeToPathMap];
|
|
||||||
if (path && monitor.id) {
|
|
||||||
navigate(`/${path}/${monitor.id}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
closeMenu: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (isActive) {
|
|
||||||
actions.push({
|
|
||||||
id: "resolve",
|
|
||||||
label: t("pages.incidents.table.actions.resolveManually"),
|
|
||||||
action: () => onResolve?.(incident.id),
|
|
||||||
closeMenu: true,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return actions;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getHeaders = (): Header<Incident>[] => {
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: "monitorName",
|
|
||||||
content: t("common.table.headers.monitor"),
|
|
||||||
render: (row) => {
|
|
||||||
const monitor = monitors?.find((m) => m.id === row.monitorId);
|
|
||||||
return monitor?.name || "N/A";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "status",
|
|
||||||
content: t("common.table.headers.status"),
|
|
||||||
render: (row) => {
|
|
||||||
const isActive = row.status === true;
|
|
||||||
return (
|
|
||||||
<ValueLabel
|
|
||||||
value={isActive ? "negative" : "positive"}
|
|
||||||
text={
|
|
||||||
isActive
|
|
||||||
? t("pages.incidents.table.status.active")
|
|
||||||
: t("pages.incidents.table.status.resolved")
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "startTime",
|
|
||||||
content: t("pages.incidents.table.headers.startTime"),
|
|
||||||
render: (row) => {
|
|
||||||
return formatDateWithTz(row.createdAt, "YYYY-MM-DD HH:mm:ss A", uiTimezone);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "endTime",
|
|
||||||
content: t("pages.incidents.table.headers.endTime"),
|
|
||||||
render: (row) => {
|
|
||||||
if (row.endTime) {
|
|
||||||
return formatDateWithTz(row.endTime, "YYYY-MM-DD HH:mm:ss A", uiTimezone);
|
|
||||||
}
|
|
||||||
return "-";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "resolutionType",
|
|
||||||
content: t("pages.incidents.table.headers.resolutionType"),
|
|
||||||
render: (row) => {
|
|
||||||
if (row.resolutionType) {
|
|
||||||
return (
|
|
||||||
<Typography
|
|
||||||
variant="body2"
|
|
||||||
sx={{
|
|
||||||
textTransform: "capitalize",
|
|
||||||
color:
|
|
||||||
row.resolutionType === "manual"
|
|
||||||
? theme.palette.warning.main
|
|
||||||
: theme.palette.success.main,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{row.resolutionType}
|
|
||||||
</Typography>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return "-";
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "statusCode",
|
|
||||||
content: t("pages.incidents.table.headers.statusCode"),
|
|
||||||
render: (row) => {
|
|
||||||
const code = row.statusCode;
|
|
||||||
if (!code) return "N/A";
|
|
||||||
let value: ValueType = "neutral";
|
|
||||||
if (code < 300) value = "positive";
|
|
||||||
else if (code >= 400) value = "negative";
|
|
||||||
return (
|
|
||||||
<ValueLabel
|
|
||||||
value={value}
|
|
||||||
text={String(code)}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "message",
|
|
||||||
content: t("common.table.headers.message"),
|
|
||||||
render: (row) => row.message || "-",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "actions",
|
|
||||||
content: t("common.table.headers.actions"),
|
|
||||||
render: (row) => <ActionsMenu items={getActions(row)} />,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePageChange = (
|
|
||||||
_e: React.MouseEvent<HTMLButtonElement> | null,
|
|
||||||
newPage: number
|
|
||||||
) => {
|
|
||||||
setPage(newPage);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleRowsPerPageChange = (
|
|
||||||
e: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>
|
|
||||||
) => {
|
|
||||||
const value = Number(e.target.value);
|
|
||||||
setPage(0);
|
|
||||||
setRowsPerPage(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!incidents || !monitors) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Table
|
|
||||||
headers={getHeaders()}
|
|
||||||
data={incidents}
|
|
||||||
onRowClick={(row) => onOpenDetails?.(row.id)}
|
|
||||||
emptyViewText={t("common.table.empty")}
|
|
||||||
/>
|
|
||||||
<Pagination
|
|
||||||
component="div"
|
|
||||||
count={incidentsCount}
|
|
||||||
page={page}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
onPageChange={handlePageChange}
|
|
||||||
onRowsPerPageChange={handleRowsPerPageChange}
|
|
||||||
itemsOnPage={incidents.length}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
// Components
|
||||||
|
import IconButton from "@mui/material/IconButton";
|
||||||
|
import Menu from "@mui/material/Menu";
|
||||||
|
import MenuItem from "@mui/material/MenuItem";
|
||||||
|
import Icon from "@/Components/v1/Icon/index.jsx";
|
||||||
|
import ResolveIncidentDialog from "../ResolveIncidentDialog/index.jsx";
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import { useState } from "react";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { TypeToPathMap } from "@/Utils/monitorUtilsLegacy.js";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
const IncidentActionsMenu = ({ incident, monitor, onResolve, onOpenDetails }) => {
|
||||||
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
|
const theme = useTheme();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const openMenu = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
setAnchorEl(event.currentTarget);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeMenu = (e) => {
|
||||||
|
if (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
setAnchorEl(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const openResolveDialog = (e) => {
|
||||||
|
closeMenu(e);
|
||||||
|
setIsDialogOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeDialog = (e) => {
|
||||||
|
if (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
setIsDialogOpen(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isActive = incident.status === true;
|
||||||
|
const handleGoToDetails = (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
closeMenu(e);
|
||||||
|
if (onOpenDetails) {
|
||||||
|
onOpenDetails(incident.id);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGoToMonitor = async (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
closeMenu(e);
|
||||||
|
try {
|
||||||
|
if (monitor) {
|
||||||
|
const path = TypeToPathMap[monitor.type];
|
||||||
|
if (path && monitor.id) {
|
||||||
|
navigate(`/${path}/${monitor.id}`);
|
||||||
|
} else {
|
||||||
|
console.error(`Monitor type not found`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.error("Monitor information not found in incident data");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching incident details:", error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<IconButton
|
||||||
|
aria-label="incident actions"
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
openMenu(event);
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
"&:focus": {
|
||||||
|
outline: "none",
|
||||||
|
},
|
||||||
|
"& svg path": {
|
||||||
|
stroke: theme.palette.primary.contrastTextTertiary,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Icon
|
||||||
|
name="Settings"
|
||||||
|
size={20}
|
||||||
|
/>
|
||||||
|
</IconButton>
|
||||||
|
|
||||||
|
<Menu
|
||||||
|
className="incident-actions-menu"
|
||||||
|
anchorEl={anchorEl}
|
||||||
|
open={Boolean(anchorEl)}
|
||||||
|
onClose={closeMenu}
|
||||||
|
disableScrollLock
|
||||||
|
slotProps={{
|
||||||
|
paper: {
|
||||||
|
sx: {
|
||||||
|
"& ul": {
|
||||||
|
p: theme.spacing(2.5),
|
||||||
|
backgroundColor: theme.palette.primary.main,
|
||||||
|
},
|
||||||
|
"& li": { m: 0, color: theme.palette.primary.contrastTextSecondary },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MenuItem onClick={handleGoToDetails}>
|
||||||
|
{t("incidentsPage.incidentsTableActionDetails", "Details")}
|
||||||
|
</MenuItem>
|
||||||
|
<MenuItem onClick={handleGoToMonitor}>
|
||||||
|
{t("incidentsPage.incidentsTableActionGoToMonitor", "Go to monitor")}
|
||||||
|
</MenuItem>
|
||||||
|
{isActive && (
|
||||||
|
<MenuItem
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
openResolveDialog(e);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("incidentsPage.incidentsTableActionResolveManually")}
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
|
</Menu>
|
||||||
|
<ResolveIncidentDialog
|
||||||
|
open={isDialogOpen}
|
||||||
|
incidentId={incident.id}
|
||||||
|
onClose={closeDialog}
|
||||||
|
onResolve={onResolve}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
IncidentActionsMenu.propTypes = {
|
||||||
|
incident: PropTypes.shape({
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
status: PropTypes.bool.isRequired,
|
||||||
|
}).isRequired,
|
||||||
|
monitor: PropTypes.shape({
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
type: PropTypes.string.isRequired,
|
||||||
|
}).isRequired,
|
||||||
|
onResolve: PropTypes.func.isRequired,
|
||||||
|
onOpenDetails: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IncidentActionsMenu;
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
//Components
|
||||||
|
import DataTable from "@/Components/v1/Table/index.jsx";
|
||||||
|
import TableSkeleton from "@/Components/v1/Table/skeleton.jsx";
|
||||||
|
import Pagination from "@/Components/v1/Table/TablePagination/index.jsx";
|
||||||
|
import { StatusLabel } from "@/Components/v1/Label/index.jsx";
|
||||||
|
import { HttpStatusLabel } from "@/Components/v1/HttpStatusLabel/index.jsx";
|
||||||
|
import GenericFallback from "@/Components/v1/GenericFallback/index.jsx";
|
||||||
|
import NetworkError from "@/Components/v1/GenericFallback/NetworkError.jsx";
|
||||||
|
import IncidentActionsMenu from "./IncidentActionsMenu.jsx";
|
||||||
|
|
||||||
|
//Utils
|
||||||
|
import { formatDateWithTz } from "../../../../Utils/timeUtilsLegacy.js";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { Typography, useTheme } from "@mui/material";
|
||||||
|
|
||||||
|
const IncidentTable = ({
|
||||||
|
monitors = [],
|
||||||
|
incidents = [],
|
||||||
|
incidentsCount = 0,
|
||||||
|
isLoading = false,
|
||||||
|
networkError = false,
|
||||||
|
page = 0,
|
||||||
|
rowsPerPage = 10,
|
||||||
|
handleChangePage,
|
||||||
|
handleChangeRowsPerPage,
|
||||||
|
resolveIncident,
|
||||||
|
handleUpdateTrigger,
|
||||||
|
onOpenDetails,
|
||||||
|
}) => {
|
||||||
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const handleResolveIncident = async (incidentId, options = {}) => {
|
||||||
|
try {
|
||||||
|
await resolveIncident(incidentId, options);
|
||||||
|
handleUpdateTrigger();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(t("incidentsPage.errorResolvingIncident"), error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const headers = [
|
||||||
|
{
|
||||||
|
id: "monitorName",
|
||||||
|
content: t("incidentsTableMonitorName"),
|
||||||
|
render: (row) => {
|
||||||
|
const monitor = monitors.find((monitor) => monitor.id === row.monitorId);
|
||||||
|
return monitor ? monitor.name : "N/A";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
content: t("incidentsTableStatus"),
|
||||||
|
render: (row) => {
|
||||||
|
const status = row.status === true ? "down" : "up";
|
||||||
|
const statusText =
|
||||||
|
row.status === true ? t("incidentsPage.active") : t("incidentsPage.resolved");
|
||||||
|
return (
|
||||||
|
<StatusLabel
|
||||||
|
status={status}
|
||||||
|
text={statusText}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "startTime",
|
||||||
|
content: t("incidentsPage.startTime"),
|
||||||
|
render: (row) => {
|
||||||
|
const formattedDate = formatDateWithTz(
|
||||||
|
row.startTime || row.createdAt,
|
||||||
|
"YYYY-MM-DD HH:mm:ss A",
|
||||||
|
uiTimezone
|
||||||
|
);
|
||||||
|
return formattedDate;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "endTime",
|
||||||
|
content: t("incidentsPage.endTime"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.endTime) {
|
||||||
|
return formatDateWithTz(row.endTime, "YYYY-MM-DD HH:mm:ss A", uiTimezone);
|
||||||
|
}
|
||||||
|
return "-";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "resolutionType",
|
||||||
|
content: t("incidentsPage.resolutionType"),
|
||||||
|
render: (row) => {
|
||||||
|
if (row.resolutionType) {
|
||||||
|
return (
|
||||||
|
<Typography
|
||||||
|
variant="body2"
|
||||||
|
sx={{
|
||||||
|
textTransform: "capitalize",
|
||||||
|
color:
|
||||||
|
row.resolutionType === "manual"
|
||||||
|
? theme.palette.accent.main
|
||||||
|
: theme.palette.success.main,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{row.resolutionType}
|
||||||
|
</Typography>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return "-";
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "statusCode",
|
||||||
|
content: t("incidentsTableStatusCode"),
|
||||||
|
render: (row) => <HttpStatusLabel status={row.statusCode} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "message",
|
||||||
|
content: t("incidentsTableMessage"),
|
||||||
|
render: (row) => row.message || "-",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "action",
|
||||||
|
content: t("actions"),
|
||||||
|
render: (row) => {
|
||||||
|
return (
|
||||||
|
<IncidentActionsMenu
|
||||||
|
incident={row}
|
||||||
|
monitor={monitors.find((monitor) => monitor.id === row.monitorId)}
|
||||||
|
onResolve={handleResolveIncident}
|
||||||
|
onOpenDetails={onOpenDetails}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isLoading) return <TableSkeleton />;
|
||||||
|
|
||||||
|
if (networkError) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
<NetworkError />
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoading && !networkError && incidents?.length === 0) {
|
||||||
|
return (
|
||||||
|
<GenericFallback>
|
||||||
|
{t("incidentsTableNoIncidents", "No incidents found")}
|
||||||
|
</GenericFallback>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const incidentsData = Array.isArray(incidents) ? incidents : [];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DataTable
|
||||||
|
headers={headers}
|
||||||
|
data={incidentsData}
|
||||||
|
/>
|
||||||
|
<Pagination
|
||||||
|
paginationLabel={t("incidentsTablePaginationLabel", "Incidents")}
|
||||||
|
itemCount={incidentsCount || 0}
|
||||||
|
page={page}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
handleChangePage={handleChangePage}
|
||||||
|
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
IncidentTable.propTypes = {
|
||||||
|
incidents: PropTypes.array.isRequired, // Array of incident objects
|
||||||
|
incidentsCount: PropTypes.number.isRequired, // Total count for pagination
|
||||||
|
isLoading: PropTypes.bool.isRequired, // Loading state
|
||||||
|
networkError: PropTypes.bool, // Network error object
|
||||||
|
page: PropTypes.number.isRequired, // Current page number
|
||||||
|
rowsPerPage: PropTypes.number.isRequired, // Number of rows per page
|
||||||
|
handleChangePage: PropTypes.func.isRequired, // Handler for page change
|
||||||
|
handleChangeRowsPerPage: PropTypes.func.isRequired, // Handler for rows per page change
|
||||||
|
resolveIncident: PropTypes.func.isRequired,
|
||||||
|
handleUpdateTrigger: PropTypes.func.isRequired,
|
||||||
|
onOpenDetails: PropTypes.func,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default IncidentTable;
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
import { useEffect, useState } from "react";
|
||||||
|
// Hooks
|
||||||
|
import useFetchIncidents from "../../hooks/useFetchIncidents.js";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
// Components
|
||||||
|
import { Grid } from "@mui/material";
|
||||||
|
import ActiveIncidentsPanel from "../ActiveIncidentsPanel/index.jsx";
|
||||||
|
import LatestIncidentsPanel from "../LatestIncidentsPanel/index.jsx";
|
||||||
|
import StatisticsPanel from "../StatisticsPanel/index.jsx";
|
||||||
|
|
||||||
|
const IncidentsSummaryPanel = ({ updateTrigger }) => {
|
||||||
|
const { fetchIncidentSummary } = useFetchIncidents();
|
||||||
|
const [summary, setSummary] = useState({
|
||||||
|
totalActive: 0,
|
||||||
|
avgResolutionTimeHours: 0,
|
||||||
|
total: 0,
|
||||||
|
topMonitor: null,
|
||||||
|
totalManualResolutions: 0,
|
||||||
|
totalAutomaticResolutions: 0,
|
||||||
|
latestIncidents: [],
|
||||||
|
});
|
||||||
|
|
||||||
|
const [isLoadingSummary, setIsLoadingSummary] = useState(false);
|
||||||
|
const [summaryError, setSummaryError] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchSummary = async () => {
|
||||||
|
setIsLoadingSummary(true);
|
||||||
|
setSummaryError(null);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const summaryData = await fetchIncidentSummary({
|
||||||
|
limit: 3,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (summaryData) {
|
||||||
|
setSummary(summaryData);
|
||||||
|
} else {
|
||||||
|
setSummaryError(new Error("Failed to fetch summary"));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching incident summary:", error);
|
||||||
|
setSummaryError(error);
|
||||||
|
} finally {
|
||||||
|
setIsLoadingSummary(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchSummary();
|
||||||
|
}, [fetchIncidentSummary, updateTrigger]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Grid
|
||||||
|
container
|
||||||
|
spacing={"16px"}
|
||||||
|
>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sm={4}
|
||||||
|
>
|
||||||
|
<ActiveIncidentsPanel
|
||||||
|
totalCount={summary.totalActive || 0}
|
||||||
|
isLoading={isLoadingSummary}
|
||||||
|
error={summaryError}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sm={4}
|
||||||
|
>
|
||||||
|
<LatestIncidentsPanel
|
||||||
|
incidents={summary.latestIncidents || []}
|
||||||
|
isLoading={isLoadingSummary}
|
||||||
|
error={summaryError}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
|
||||||
|
<Grid
|
||||||
|
item
|
||||||
|
xs={12}
|
||||||
|
sm={4}
|
||||||
|
>
|
||||||
|
<StatisticsPanel
|
||||||
|
summary={summary}
|
||||||
|
isLoading={isLoadingSummary}
|
||||||
|
error={summaryError}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
IncidentsSummaryPanel.propTypes = {
|
||||||
|
updateTrigger: PropTypes.bool.isRequired,
|
||||||
|
};
|
||||||
|
export default IncidentsSummaryPanel;
|
||||||
Loaded 100 of 327 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user