Files
Checkmate/client/src/Pages/Uptime/Create/index.jsx
T

825 lines
22 KiB
React
Raw Normal View History

2024-12-03 15:29:19 +08:00
//Components
import {
2025-07-23 20:01:39 -04:00
Box,
Button,
ButtonGroup,
FormControlLabel,
Stack,
Switch,
Tooltip,
Typography,
} from "@mui/material";
2025-09-27 14:54:55 -07:00
import Breadcrumbs from "@/Components/v1/Breadcrumbs/index.jsx";
import TextInput from "@/Components/v1/Inputs/TextInput/index.jsx";
import { HttpAdornment } from "@/Components/v1/Inputs/TextInput/Adornments/index.jsx";
import Radio from "@/Components/v1/Inputs/Radio/index.jsx";
import Select from "@/Components/v1/Inputs/Select/index.jsx";
import ConfigBox from "@/Components/v1/ConfigBox/index.jsx";
import NotificationsConfig from "@/Components/v1/NotificationConfig/index.jsx";
import Checkbox from "@/Components/v1/Inputs/Checkbox/index.jsx";
import Dialog from "@/Components/v1/Dialog/index.jsx";
import PulseDot from "@/Components/v1/Animated/PulseDot.jsx";
2025-09-25 10:11:41 -07:00
import SkeletonLayout from "./skeleton.jsx";
2025-06-12 12:44:46 +08:00
// Utils
import PropTypes from "prop-types";
2025-06-12 12:44:46 +08:00
import { useTheme } from "@emotion/react";
2025-07-23 15:31:26 -07:00
import { useEffect, useState } from "react";
2025-06-12 12:44:46 +08:00
import { useTranslation } from "react-i18next";
2026-01-12 23:57:39 +00:00
import { monitorValidation } from "../../../Validation/validation.js";
import { createToast } from "../../../Utils/toastUtils.jsx";
import Icon from "@/Components/v1/Icon";
2026-01-12 23:57:39 +00:00
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils.js";
import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications.js";
2025-07-23 15:31:26 -07:00
import { useParams } from "react-router-dom";
import {
useCreateMonitor,
2025-07-23 20:01:39 -04:00
useDeleteMonitor,
useUpdateMonitor,
usePauseMonitor,
useFetchMonitorById,
2025-08-03 13:19:55 +03:00
useFetchMonitorGames,
2026-01-12 23:57:39 +00:00
} from "../../../Hooks/monitorHooks.js";
2025-06-09 12:55:45 +08:00
/**
* Create page renders monitor creation or configuration views.
* @component
*/
const UptimeCreate = ({ isClone = false }) => {
2025-07-23 20:01:39 -04:00
const { monitorId } = useParams();
const isCreate = typeof monitorId === "undefined" || isClone;
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
// States
2025-06-09 12:55:45 +08:00
const [monitor, setMonitor] = useState({
type: "http",
2025-08-18 15:34:30 -07:00
statusWindowSize: 5,
statusWindowThreshold: 60,
2025-06-09 12:55:45 +08:00
matchMethod: "equal",
expectedValue: "",
jsonPath: "",
2025-06-09 12:55:45 +08:00
notifications: [],
2025-07-23 20:01:39 -04:00
interval: 60000,
2025-06-09 12:55:45 +08:00
ignoreTlsErrors: false,
2025-07-23 20:01:39 -04:00
...(isCreate ? { url: "", name: "" } : { port: undefined }),
2025-06-09 12:55:45 +08:00
});
2025-07-23 20:01:39 -04:00
const [errors, setErrors] = useState({});
const [https, setHttps] = useState(true);
const [isOpen, setIsOpen] = useState(false);
const [useAdvancedMatching, setUseAdvancedMatching] = useState(false);
const [updateTrigger, setUpdateTrigger] = useState(false);
2025-08-03 13:19:55 +03:00
const [games, setGames] = useState({});
2025-07-23 20:01:39 -04:00
const triggerUpdate = () => {
setUpdateTrigger(!updateTrigger);
2025-07-23 15:31:26 -07:00
};
2025-07-23 20:01:39 -04:00
// Hooks
const [notifications, notificationsAreLoading, notificationsError] =
useGetNotificationsByTeamId();
const { determineState, statusColor } = useMonitorUtils();
2025-08-03 13:19:55 +03:00
// Fetch monitor details
const [isFetchingMonitor] = useFetchMonitorById({
2025-07-23 15:31:26 -07:00
monitorId,
setMonitor,
2025-07-23 15:31:26 -07:00
updateTrigger: true,
});
2025-08-03 13:19:55 +03:00
// Fetch games
const [isFetchingGames] = useFetchMonitorGames({
setGames,
triggerUpdate: true,
});
// Combine the loading states
const isLoading = isFetchingMonitor || isFetchingGames;
2025-07-23 20:01:39 -04:00
const [createMonitor, isCreating] = useCreateMonitor();
const [pauseMonitor, isPausing] = usePauseMonitor({});
const [deleteMonitor, isDeleting] = useDeleteMonitor();
const [updateMonitor, isUpdating] = useUpdateMonitor();
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
// Setup
const theme = useTheme();
const { t } = useTranslation();
2024-12-03 15:29:19 +08:00
2025-07-23 20:01:39 -04:00
// Constants
const MS_PER_MINUTE = 60000;
const FREQUENCIES = [
2026-01-14 22:43:25 -05:00
{ _id: 0.25, name: t("time.fifteenSeconds") },
{ _id: 0.5, name: t("time.thirtySeconds") },
2025-07-23 20:01:39 -04:00
{ _id: 1, name: t("time.oneMinute") },
{ _id: 2, name: t("time.twoMinutes") },
{ _id: 3, name: t("time.threeMinutes") },
{ _id: 4, name: t("time.fourMinutes") },
{ _id: 5, name: t("time.fiveMinutes") },
2026-01-14 22:43:25 -05:00
{ _id: 10, name: t("time.tenMinutes") },
{ _id: 15, name: t("time.fifteenMinutes") },
{ _id: 30, name: t("time.thirtyMinutes") },
2025-07-23 20:01:39 -04:00
];
2025-08-02 02:25:58 +03:00
2025-08-03 13:19:55 +03:00
const GAMELIST = Object.entries(games).map(([key, value]) => ({
2025-08-02 02:04:06 +03:00
_id: key,
2025-08-02 02:25:58 +03:00
name: value.name,
2025-08-02 02:04:06 +03:00
}));
2025-07-23 20:01:39 -04:00
const CRUMBS = [
{ name: "uptime", path: "/uptime" },
...(isCreate
? [{ name: "create", path: `/uptime/create` }]
: [
{ name: "details", path: `/uptime/${monitorId}` },
{ name: "configure", path: `/uptime/configure/${monitorId}` },
]),
];
const matchMethodOptions = [
2025-07-23 20:01:39 -04:00
{ _id: "equal", name: t("matchMethodOptions.equal") },
{ _id: "include", name: t("matchMethodOptions.include") },
{ _id: "regex", name: t("matchMethodOptions.regex") },
];
const expectedValuePlaceholders = {
2025-07-23 20:01:39 -04:00
regex: t("matchMethodOptions.regexPlaceholder"),
equal: t("matchMethodOptions.equalPlaceholder"),
include: t("matchMethodOptions.includePlaceholder"),
};
const monitorTypeMaps = {
http: {
2025-07-23 20:01:39 -04:00
label: t("monitorType.http.label"),
placeholder: t("monitorType.http.placeholder"),
namePlaceholder: t("monitorType.http.namePlaceholder"),
},
ping: {
2025-07-23 20:01:39 -04:00
label: t("monitorType.ping.label"),
placeholder: t("monitorType.ping.placeholder"),
namePlaceholder: t("monitorType.ping.namePlaceholder"),
},
docker: {
2025-07-23 20:01:39 -04:00
label: t("monitorType.docker.label"),
placeholder: t("monitorType.docker.placeholder"),
namePlaceholder: t("monitorType.docker.namePlaceholder"),
},
2024-12-27 11:16:58 -08:00
port: {
2025-07-23 20:01:39 -04:00
label: t("monitorType.port.label"),
placeholder: t("monitorType.port.placeholder"),
namePlaceholder: t("monitorType.port.namePlaceholder"),
2024-12-27 11:16:58 -08:00
},
2025-08-02 02:04:06 +03:00
game: {
label: t("monitorType.game.label"),
placeholder: t("monitorType.game.placeholder"),
namePlaceholder: t("monitorType.game.namePlaceholder"),
2025-08-02 02:25:58 +03:00
},
};
2025-06-09 12:55:45 +08:00
// Handlers
const onSubmit = async (event) => {
event.preventDefault();
2025-06-09 12:55:45 +08:00
const { notifications, ...rest } = monitor;
2025-07-23 20:01:39 -04:00
let form = {};
if (isCreate) {
form = {
url:
monitor.type === "http" && !isClone
2025-07-23 20:01:39 -04:00
? `http${https ? "s" : ""}://` + monitor.url
: monitor.url,
name: monitor.name || monitor.url.substring(0, 50),
2025-08-18 15:34:30 -07:00
statusWindowSize: monitor.statusWindowSize,
statusWindowThreshold: monitor.statusWindowThreshold,
2025-07-23 20:01:39 -04:00
type: monitor.type,
2025-08-18 15:34:30 -07:00
2025-08-02 02:25:58 +03:00
port:
monitor.type === "port" || monitor.type === "game" ? monitor.port : undefined,
2025-07-23 20:01:39 -04:00
interval: monitor.interval,
matchMethod: monitor.matchMethod,
expectedValue: monitor.expectedValue,
jsonPath: monitor.jsonPath,
ignoreTlsErrors: monitor.ignoreTlsErrors,
2025-08-02 02:04:06 +03:00
gameId: monitor.gameId || undefined,
2025-07-23 20:01:39 -04:00
};
} else {
form = {
2026-01-15 18:21:36 +00:00
id: monitor.id,
2025-07-23 20:01:39 -04:00
url: monitor.url,
name: monitor.name || monitor.url.substring(0, 50),
2025-08-18 15:34:30 -07:00
statusWindowSize: monitor.statusWindowSize,
statusWindowThreshold: monitor.statusWindowThreshold,
2025-07-23 20:01:39 -04:00
type: monitor.type,
matchMethod: monitor.matchMethod,
expectedValue: monitor.expectedValue,
jsonPath: monitor.jsonPath,
interval: monitor.interval,
teamId: monitor.teamId,
userId: monitor.userId,
2025-08-02 02:25:58 +03:00
port:
monitor.type === "port" || monitor.type === "game" ? monitor.port : undefined,
2025-07-23 20:01:39 -04:00
ignoreTlsErrors: monitor.ignoreTlsErrors,
2025-08-02 02:04:06 +03:00
gameId: monitor.gameId || undefined,
2025-07-23 20:01:39 -04:00
};
}
2025-06-09 12:55:45 +08:00
if (!useAdvancedMatching) {
2025-07-23 20:01:39 -04:00
form.matchMethod = isCreate ? undefined : "";
form.expectedValue = isCreate ? undefined : "";
form.jsonPath = isCreate ? undefined : "";
2025-02-13 00:54:24 +00:00
}
const { error } = monitorValidation.validate(form, {
abortEarly: false,
});
2024-07-18 12:11:27 -07:00
if (error) {
const newErrors = {};
error.details.forEach((err) => {
newErrors[err.path[0]] = err.message;
});
setErrors(newErrors);
2025-07-23 20:01:39 -04:00
createToast({ body: t("checkFormError") });
2024-12-03 15:29:19 +08:00
return;
}
form = {
...form,
2025-02-01 22:14:27 +08:00
description: monitor.name || monitor.url,
2024-12-03 15:29:19 +08:00
notifications: monitor.notifications,
};
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
if (isCreate) {
await createMonitor({ monitor: form, redirect: "/uptime" });
} else {
await updateMonitor({ monitor: form, redirect: "/uptime" });
}
2024-12-03 15:29:19 +08:00
};
2025-06-09 12:55:45 +08:00
const onChange = (event) => {
2025-07-23 20:01:39 -04:00
let { name, value, checked } = event.target;
2025-06-18 10:10:14 +08:00
2025-06-09 12:55:45 +08:00
if (name === "ignoreTlsErrors") {
2025-07-23 20:01:39 -04:00
value = checked;
2025-06-09 12:55:45 +08:00
}
if (name === "useAdvancedMatching") {
setUseAdvancedMatching(checked);
return;
}
2025-07-23 20:01:39 -04:00
if (name === "interval") {
value = value * MS_PER_MINUTE;
}
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
setMonitor((prev) => ({ ...prev, [name]: value }));
2024-12-03 15:29:19 +08:00
if (name === "type") {
setErrors({});
return;
}
2024-12-03 15:29:19 +08:00
const { error } = monitorValidation.validate(
2025-07-23 20:01:39 -04:00
{ type: monitor.type, [name]: value },
2024-12-03 15:29:19 +08:00
{ abortEarly: false }
);
2025-06-09 12:55:45 +08:00
setErrors((prev) => ({
2024-12-03 15:29:19 +08:00
...prev,
...(error && error.details[0].path[0] === name
? { [name]: error.details[0].message }
: { [name]: undefined }),
2024-12-03 15:29:19 +08:00
}));
};
2024-06-27 16:44:56 -04:00
2025-07-23 20:01:39 -04:00
const handlePause = async () => {
await pauseMonitor({ monitorId, triggerUpdate });
};
2025-07-23 20:01:39 -04:00
const handleRemove = async (event) => {
event.preventDefault();
2026-01-15 18:21:36 +00:00
const TEMP_MONITOR = { id: monitor.id };
2026-01-12 23:57:39 +00:00
await deleteMonitor({ monitor: TEMP_MONITOR, redirect: "/uptime" });
2025-07-23 20:01:39 -04:00
};
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
const isBusy = isLoading || isCreating || isDeleting || isUpdating || isPausing;
const displayInterval = monitor?.interval / MS_PER_MINUTE || 1;
2025-08-19 01:11:56 +05:30
const parsedUrl = monitor?.url;
2025-07-23 20:01:39 -04:00
const protocol = parsedUrl?.protocol?.replace(":", "") || "";
2024-12-03 15:29:19 +08:00
2025-07-23 20:01:39 -04:00
useEffect(() => {
if (!isCreate || isClone) {
2025-07-23 20:01:39 -04:00
if (monitor.matchMethod) {
setUseAdvancedMatching(true);
} else {
setUseAdvancedMatching(false);
}
}
}, [monitor, isCreate]);
if (Object.keys(monitor).length === 0) {
return <SkeletonLayout />;
}
return (
2025-06-09 12:55:45 +08:00
<Stack gap={theme.spacing(10)}>
2025-07-23 20:01:39 -04:00
<Breadcrumbs list={CRUMBS} />
2025-06-09 12:55:45 +08:00
<Stack
component="form"
2025-07-23 20:01:39 -04:00
onSubmit={onSubmit}
2025-06-09 12:55:45 +08:00
noValidate
2025-07-23 20:01:39 -04:00
spellCheck="false"
gap={theme.spacing(12)}
2025-07-23 20:01:39 -04:00
flex={1}
>
2025-07-23 20:01:39 -04:00
<Stack
direction="row"
gap={theme.spacing(12)}
>
<Box>
2025-05-27 09:10:32 -07:00
<Typography
2025-07-23 20:01:39 -04:00
component="h1"
variant="h1"
2025-05-27 09:10:32 -07:00
>
2025-07-23 20:01:39 -04:00
<Typography
component="span"
fontSize="inherit"
color={
!isCreate ? theme.palette.primary.contrastTextSecondary : undefined
}
>
{!isCreate ? monitor.name : t("createYour") + " "}
</Typography>
{isCreate && (
<Typography
component="span"
fontSize="inherit"
fontWeight="inherit"
color={theme.palette.primary.contrastTextSecondary}
>
{t("monitor")}
</Typography>
)}
</Typography>
2025-07-23 20:01:39 -04:00
{!isCreate && (
<Stack
direction="row"
alignItems="center"
height="fit-content"
gap={theme.spacing(2)}
>
<Tooltip
title={t(`statusMsg.${[determineState(monitor)]}`)}
disableInteractive
slotProps={{
popper: {
modifiers: [
{
name: "offset",
options: {
offset: [0, -8],
},
},
],
},
}}
>
<Box>
<PulseDot color={statusColor[determineState(monitor)]} />
</Box>
</Tooltip>
<Typography
component="h2"
variant="monitorUrl"
>
{monitor.url?.replace(/^https?:\/\//, "") || "..."}
</Typography>
<Typography
position="relative"
variant="body2"
ml={theme.spacing(6)}
mt={theme.spacing(1)}
sx={{
"&:before": {
position: "absolute",
content: `""`,
width: theme.spacing(2),
height: theme.spacing(2),
2025-07-23 20:01:39 -04:00
borderRadius: "50%",
backgroundColor: theme.palette.primary.contrastTextTertiary,
opacity: 0.8,
left: theme.spacing(-5),
2025-07-23 20:01:39 -04:00
top: "50%",
transform: "translateY(-50%)",
},
}}
>
{t("editing")}
</Typography>
</Stack>
)}
</Box>
2025-07-23 20:01:39 -04:00
{!isCreate && (
<Box
justifyContent="space-between"
sx={{
alignSelf: "flex-end",
ml: "auto",
display: "flex",
gap: theme.spacing(2),
}}
>
<Button
variant="contained"
color="secondary"
loading={isBusy}
startIcon={
2026-01-15 23:39:26 -05:00
monitor?.isActive ? (
<Icon
name="Pause"
size={18}
/>
) : (
<Icon
name="Play"
size={18}
/>
)
2025-07-23 20:01:39 -04:00
}
onClick={handlePause}
>
{monitor?.isActive ? t("pause") : t("resume")}
</Button>
<Button
loading={isBusy}
variant="contained"
color="error"
sx={{ px: theme.spacing(8) }}
onClick={() => setIsOpen(true)}
>
{t("remove")}
</Button>
</Box>
)}
</Stack>
{isCreate && (
<ConfigBox>
<Box>
<Typography
component="h2"
variant="h2"
>
{t("distributedUptimeCreateChecks")}
</Typography>
<Typography component="p">
{t("distributedUptimeCreateChecksDescription")}
</Typography>
</Box>
<Stack gap={theme.spacing(12)}>
<Stack gap={theme.spacing(6)}>
<Radio
name="type"
title={t("websiteMonitoring")}
desc={t("websiteMonitoringDescription")}
size="small"
value="http"
checked={monitor.type === "http"}
onChange={onChange}
/>
{monitor.type === "http" ? (
<ButtonGroup sx={{ ml: theme.spacing(16) }}>
<Button
variant="group"
filled={https.toString()}
onClick={() => setHttps(true)}
>
{t("https")}
</Button>
<Button
variant="group"
filled={(!https).toString()}
onClick={() => setHttps(false)}
>
{t("http")}
</Button>
</ButtonGroup>
) : (
""
)}
</Stack>
<Radio
2025-06-09 12:55:45 +08:00
name="type"
2025-07-23 20:01:39 -04:00
title={t("pingMonitoring")}
desc={t("pingMonitoringDescription")}
size="small"
2025-07-23 20:01:39 -04:00
value="ping"
checked={monitor.type === "ping"}
2025-06-09 12:55:45 +08:00
onChange={onChange}
/>
2025-07-23 20:01:39 -04:00
<Radio
name="type"
title={t("dockerContainerMonitoring")}
desc={t("dockerContainerMonitoringDescription")}
size="small"
value="docker"
checked={monitor.type === "docker"}
onChange={onChange}
/>
<Radio
name="type"
title={t("portMonitoring")}
desc={t("portMonitoringDescription")}
size="small"
value="port"
checked={monitor.type === "port"}
onChange={onChange}
/>
2025-08-02 02:04:06 +03:00
<Radio
name="type"
title={t("gameServerMonitoring")}
desc={t("gameServerMonitoringDescription")}
size="small"
value="game"
checked={monitor.type === "game"}
onChange={onChange}
/>
2025-07-23 20:01:39 -04:00
{errors["type"] ? (
<Box className="error-container">
<Typography
component="p"
className="input-error"
color={theme.palette.error.contrastText}
>
2025-07-23 20:01:39 -04:00
{errors["type"]}
</Typography>
</Box>
) : (
""
)}
</Stack>
2025-07-23 20:01:39 -04:00
</ConfigBox>
)}
<ConfigBox>
<Box>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
{t("settingsGeneralSettings")}
</Typography>
2025-06-08 08:14:17 +08:00
<Typography component="p">
2025-07-23 20:01:39 -04:00
{isCreate
? t(`uptimeGeneralInstructions.${monitor.type}`)
: t("distributedUptimeCreateSelectURL")}
2025-06-08 08:14:17 +08:00
</Typography>
</Box>
2025-07-23 20:01:39 -04:00
<Stack gap={theme.spacing(20)}>
<TextInput
2025-07-23 20:01:39 -04:00
id="monitor-url"
2025-06-09 12:55:45 +08:00
name="url"
2025-07-23 20:01:39 -04:00
type={monitor?.type === "http" ? "url" : "text"}
label={
(monitor.type === "http" || monitor.type === "port") && !isCreate
? t("url")
: monitorTypeMaps[monitor.type].label || t("urlMonitor")
}
placeholder={monitorTypeMaps[monitor.type].placeholder || ""}
value={parsedUrl?.host + parsedUrl?.pathname || monitor?.url || ""}
2025-07-23 20:01:39 -04:00
https={isCreate ? https : protocol === "https"}
startAdornment={
monitor?.type === "http" && (
<HttpAdornment https={isCreate ? https : protocol === "https"} />
)
}
helperText={errors["url"]}
2025-07-23 20:01:39 -04:00
onChange={onChange}
disabled={!isCreate}
/>
<TextInput
2025-06-09 12:55:45 +08:00
name="port"
type="number"
2025-03-17 01:16:42 +05:30
label={t("portToMonitor")}
placeholder="5173"
2025-07-23 20:01:39 -04:00
value={monitor.port || ""}
2025-06-09 12:55:45 +08:00
onChange={onChange}
error={errors["port"] ? true : false}
helperText={errors["port"]}
2025-08-02 02:04:06 +03:00
hidden={monitor.type !== "port" && monitor.type !== "game"}
/>
2025-08-02 02:25:58 +03:00
{monitor.type === "game" && (
<Select
name="gameId"
label={t("chooseGame")}
value={monitor.gameId || ""}
placeholder={t("chooseGame")}
onChange={onChange}
items={GAMELIST}
error={errors["gameId"] ? true : false}
2025-08-02 02:25:58 +03:00
/>
)}
<TextInput
2025-06-09 12:55:45 +08:00
name="name"
type="text"
2025-03-17 01:16:42 +05:30
label={t("displayName")}
isOptional={true}
2025-07-23 20:01:39 -04:00
placeholder={monitorTypeMaps[monitor.type].namePlaceholder}
value={monitor.name || ""}
2025-06-09 12:55:45 +08:00
onChange={onChange}
error={errors["name"] ? true : false}
helperText={errors["name"]}
/>
</Stack>
</ConfigBox>
2025-08-18 15:34:30 -07:00
<ConfigBox>
<Box>
<Typography
component="h2"
variant="h2"
>
2025-08-18 15:46:41 -07:00
{t("createMonitorPage.incidentConfigTitle")}
2025-08-18 15:34:30 -07:00
</Typography>
<Typography component="p">
2025-08-18 15:46:41 -07:00
{t("createMonitorPage.incidentConfigDescription")}
2025-08-18 15:34:30 -07:00
</Typography>
</Box>
<Stack gap={theme.spacing(20)}>
<TextInput
name="statusWindowSize"
2025-08-18 15:46:41 -07:00
label={t("createMonitorPage.incidentConfigStatusWindowLabel")}
2025-08-18 15:34:30 -07:00
type="number"
value={monitor.statusWindowSize}
onChange={onChange}
error={errors["statusWindowSize"] ? true : false}
helperText={errors["statusWindowSize"]}
/>
<TextInput
name="statusWindowThreshold"
2025-08-18 15:46:41 -07:00
label={t("createMonitorPage.incidentConfigStatusWindowThresholdLabel")}
2025-08-18 15:34:30 -07:00
type="number"
value={monitor.statusWindowThreshold}
onChange={onChange}
error={errors["statusWindowThreshold"] ? true : false}
helperText={errors["statusWindowThreshold"]}
/>
</Stack>
</ConfigBox>
<ConfigBox>
<Box>
2025-07-28 16:28:44 -04:00
<Typography
component="h2"
variant="h2"
>
{t("notificationConfig.title")}
</Typography>
2025-06-09 14:22:11 +08:00
<Typography component="p">{t("notificationConfig.description")}</Typography>
</Box>
2025-06-09 12:55:45 +08:00
<NotificationsConfig
notifications={notifications}
setMonitor={setMonitor}
2025-07-23 20:01:39 -04:00
setNotifications={isCreate ? null : monitor.notifications}
2025-06-09 12:55:45 +08:00
/>
</ConfigBox>
2025-05-08 15:28:44 +05:30
<ConfigBox>
<Box>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
{t("ignoreTLSError")}
</Typography>
2025-05-08 15:47:20 +05:30
<Typography component="p">{t("ignoreTLSErrorDescription")}</Typography>
2025-05-08 15:28:44 +05:30
</Box>
<Stack>
<FormControlLabel
2025-07-23 20:01:39 -04:00
sx={{ marginLeft: theme.spacing(0) }}
2025-05-08 15:28:44 +05:30
control={
<Switch
2025-06-09 12:55:45 +08:00
name="ignoreTlsErrors"
2025-05-08 15:28:44 +05:30
checked={monitor.ignoreTlsErrors}
2025-06-09 12:55:45 +08:00
onChange={onChange}
2025-05-08 15:28:44 +05:30
sx={{ mr: theme.spacing(2) }}
/>
}
2025-05-08 15:47:20 +05:30
label={t("tlsErrorIgnored")}
2025-05-08 15:28:44 +05:30
/>
</Stack>
</ConfigBox>
<ConfigBox>
<Box>
2025-05-27 09:10:32 -07:00
<Typography
component="h2"
variant="h2"
>
2025-03-19 09:02:30 -07:00
{t("distributedUptimeCreateAdvancedSettings")}
</Typography>
</Box>
2025-07-23 20:01:39 -04:00
<Stack gap={theme.spacing(20)}>
<Select
2025-06-09 12:55:45 +08:00
name="interval"
2025-07-23 20:01:39 -04:00
label={t("checkFrequency")}
value={displayInterval}
onChange={onChange}
2025-07-23 20:01:39 -04:00
items={FREQUENCIES}
/>
2025-07-23 20:01:39 -04:00
{monitor.type === "http" && (
<Checkbox
name="useAdvancedMatching"
label={t("advancedMatching")}
isChecked={useAdvancedMatching}
onChange={onChange}
/>
)}
{monitor.type === "http" && useAdvancedMatching && (
2025-02-24 14:33:25 -08:00
<>
2025-02-13 00:54:24 +00:00
<Select
2025-06-09 12:55:45 +08:00
name="matchMethod"
2025-07-23 20:01:39 -04:00
label={t("matchMethod")}
2025-02-13 00:54:24 +00:00
value={monitor.matchMethod || "equal"}
2025-06-09 12:55:45 +08:00
onChange={onChange}
items={matchMethodOptions}
2025-02-13 00:54:24 +00:00
/>
<Stack>
<TextInput
type="text"
2025-07-23 20:01:39 -04:00
name="expectedValue"
label={t("expectedValue")}
2025-02-13 00:54:24 +00:00
isOptional={true}
2025-02-24 14:33:25 -08:00
placeholder={
expectedValuePlaceholders[monitor.matchMethod || "equal"]
}
2025-02-13 00:54:24 +00:00
value={monitor.expectedValue}
2025-06-09 12:55:45 +08:00
onChange={onChange}
2025-02-13 00:54:24 +00:00
error={errors["expectedValue"] ? true : false}
helperText={errors["expectedValue"]}
/>
<Typography
component="span"
color={theme.palette.primary.contrastTextTertiary}
opacity={0.8}
>
2025-03-17 01:16:42 +05:30
{t("uptimeCreate")}
2025-02-13 00:54:24 +00:00
</Typography>
</Stack>
<Stack>
<TextInput
2025-06-09 12:55:45 +08:00
name="jsonPath"
2025-02-13 00:54:24 +00:00
type="text"
2025-07-23 20:01:39 -04:00
label={t("uptimeAdvancedMatching.jsonPath")}
2025-02-13 00:54:24 +00:00
isOptional={true}
2025-03-25 20:54:50 -04:00
placeholder="data.status"
2025-02-13 00:54:24 +00:00
value={monitor.jsonPath}
2025-06-09 12:55:45 +08:00
onChange={onChange}
2025-02-13 00:54:24 +00:00
error={errors["jsonPath"] ? true : false}
helperText={errors["jsonPath"]}
/>
<Typography
component="span"
color={theme.palette.primary.contrastTextTertiary}
opacity={0.8}
>
2025-07-23 20:01:39 -04:00
{t("uptimeCreateJsonPath") + " "}
2025-02-24 14:33:25 -08:00
<Typography
component="a"
href="https://jmespath.org/"
target="_blank"
color="info"
>
2025-02-13 00:54:24 +00:00
jmespath.org
</Typography>
2025-07-23 20:01:39 -04:00
{" " + t("uptimeCreateJsonPathQuery")}
2025-02-13 00:54:24 +00:00
</Typography>
</Stack>
</>
2025-02-24 14:33:25 -08:00
)}
</Stack>
</ConfigBox>
<Stack
direction="row"
justifyContent="flex-end"
>
2025-02-13 15:20:12 -08:00
<Button
2025-06-09 12:55:45 +08:00
type="submit"
variant="contained"
2025-01-14 08:09:03 -05:00
color="accent"
2024-12-03 15:29:19 +08:00
disabled={!Object.values(errors).every((value) => value === undefined)}
2025-07-23 20:01:39 -04:00
loading={isBusy}
sx={{ px: theme.spacing(12) }}
>
2025-07-23 20:01:39 -04:00
{t("settingsSave")}
2025-02-13 15:20:12 -08:00
</Button>
</Stack>
</Stack>
2025-06-09 12:55:45 +08:00
2025-07-23 20:01:39 -04:00
{!isCreate && (
<Dialog
open={isOpen}
theme={theme}
title={t("deleteDialogTitle")}
description={t("deleteDialogDescription")}
onCancel={() => setIsOpen(false)}
confirmationButtonLabel={t("delete")}
onConfirm={handleRemove}
isLoading={isLoading}
/>
)}
2025-06-09 12:55:45 +08:00
</Stack>
);
2024-06-18 22:39:58 +03:30
};
UptimeCreate.propTypes = {
isClone: PropTypes.bool,
};
export default UptimeCreate;