add notificaions channel to Uptime Configure
This commit is contained in:
1 parent
e36abfa9a6
commit
04ab4e23db
1 file changed
+414
-495
@@ -1,7 +1,7 @@
|
|||||||
import { useNavigate, useParams } from "react-router";
|
import { useNavigate, useParams } from "react-router";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useEffect, useState } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Stack,
|
Stack,
|
||||||
@@ -13,31 +13,26 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import ConfigBox from "../../../Components/ConfigBox";
|
import ConfigBox from "../../../Components/ConfigBox";
|
||||||
import {
|
import {
|
||||||
updateUptimeMonitor,
|
updateUptimeMonitor,
|
||||||
pauseUptimeMonitor,
|
|
||||||
getUptimeMonitorById,
|
|
||||||
deleteUptimeMonitor,
|
deleteUptimeMonitor,
|
||||||
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import TextInput from "../../../Components/Inputs/TextInput";
|
import TextInput from "../../../Components/Inputs/TextInput";
|
||||||
import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
|
||||||
import PauseIcon from "../../../assets/icons/pause-icon.svg?react";
|
|
||||||
import ResumeIcon from "../../../assets/icons/resume-icon.svg?react";
|
|
||||||
import Select from "../../../Components/Inputs/Select";
|
import Select from "../../../Components/Inputs/Select";
|
||||||
import Checkbox from "../../../Components/Inputs/Checkbox";
|
|
||||||
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
import PulseDot from "../../../Components/Animated/PulseDot";
|
import PulseDot from "../../../Components/Animated/PulseDot";
|
||||||
import SkeletonLayout from "./skeleton";
|
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import Dialog from "../../../Components/Dialog";
|
import Dialog from "../../../Components/Dialog";
|
||||||
import NotificationIntegrationModal from "../../../Components/NotificationIntegrationModal/Components/NotificationIntegrationModal";
|
|
||||||
import { usePauseMonitor } from "../../../Hooks/useMonitorControls";
|
import { usePauseMonitor } from "../../../Hooks/useMonitorControls";
|
||||||
import PauseOutlinedIcon from "@mui/icons-material/PauseOutlined";
|
import PauseOutlinedIcon from "@mui/icons-material/PauseOutlined";
|
||||||
import PlayArrowOutlinedIcon from "@mui/icons-material/PlayArrowOutlined";
|
import PlayArrowOutlinedIcon from "@mui/icons-material/PlayArrowOutlined";
|
||||||
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
|
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
|
||||||
|
import { useFetchUptimeMonitorById } from "../../../Hooks/useFetchUptimeMonitorById";
|
||||||
|
import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications";
|
||||||
|
import NotificationsConfig from "../../../Components/NotificationConfig";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a URL string and returns a URL object.
|
* Parses a URL string and returns a URL object.
|
||||||
@@ -58,22 +53,41 @@ const parseUrl = (url) => {
|
|||||||
* @component
|
* @component
|
||||||
*/
|
*/
|
||||||
const Configure = () => {
|
const Configure = () => {
|
||||||
|
const { monitorId } = useParams();
|
||||||
|
|
||||||
|
// Local state
|
||||||
|
const [form, setForm] = useState({
|
||||||
|
ignoreTlsErrors: false,
|
||||||
|
interval: 60000,
|
||||||
|
matchMethod: "equal",
|
||||||
|
expectedValue: "",
|
||||||
|
jsonPath: "",
|
||||||
|
notifications: [],
|
||||||
|
port: "",
|
||||||
|
type: "http",
|
||||||
|
});
|
||||||
|
const [useAdvancedMatching, setUseAdvancedMatching] = useState(false);
|
||||||
|
const [updateTrigger, setUpdateTrigger] = useState(false);
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
|
const triggerUpdate = () => {
|
||||||
|
setUpdateTrigger(!updateTrigger);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Network
|
||||||
|
const [monitor, isLoading, error] = useFetchUptimeMonitorById(monitorId, updateTrigger);
|
||||||
|
const [notifications, notificationsAreLoading, notificationsError] =
|
||||||
|
useGetNotificationsByTeamId();
|
||||||
|
const [pauseMonitor, isPausing, pauseError] = usePauseMonitor({
|
||||||
|
monitorId: monitor?._id,
|
||||||
|
triggerUpdate,
|
||||||
|
});
|
||||||
|
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { user } = useSelector((state) => state.auth);
|
|
||||||
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
|
||||||
const [monitor, setMonitor] = useState({});
|
|
||||||
const [errors, setErrors] = useState({});
|
|
||||||
const { monitorId } = useParams();
|
|
||||||
const idMap = {
|
|
||||||
"monitor-url": "url",
|
|
||||||
"monitor-name": "name",
|
|
||||||
"monitor-checks-http": "type",
|
|
||||||
"monitor-checks-ping": "type",
|
|
||||||
"notify-email-default": "notification-email",
|
|
||||||
};
|
|
||||||
|
|
||||||
const matchMethodOptions = [
|
const matchMethodOptions = [
|
||||||
{ _id: "equal", name: "Equal" },
|
{ _id: "equal", name: "Equal" },
|
||||||
@@ -81,106 +95,28 @@ const Configure = () => {
|
|||||||
{ _id: "regex", name: "Regex" },
|
{ _id: "regex", name: "Regex" },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const frequencies = [
|
||||||
|
{ _id: 1, name: "1 minute" },
|
||||||
|
{ _id: 2, name: "2 minutes" },
|
||||||
|
{ _id: 3, name: "3 minutes" },
|
||||||
|
{ _id: 4, name: "4 minutes" },
|
||||||
|
{ _id: 5, name: "5 minutes" },
|
||||||
|
];
|
||||||
|
|
||||||
const expectedValuePlaceholders = {
|
const expectedValuePlaceholders = {
|
||||||
regex: "^(success|ok)$",
|
regex: "^(success|ok)$",
|
||||||
equal: "success",
|
equal: "success",
|
||||||
include: "ok",
|
include: "ok",
|
||||||
};
|
};
|
||||||
|
|
||||||
const [trigger, setTrigger] = useState(false);
|
// Handlers
|
||||||
const triggerUpdate = () => {
|
const handlePause = async () => {
|
||||||
setTrigger(!trigger);
|
const res = await pauseMonitor();
|
||||||
};
|
if (typeof res !== "undefined") {
|
||||||
const [pauseMonitor, isPausing, error] = usePauseMonitor({
|
triggerUpdate();
|
||||||
monitorId: monitor?._id,
|
|
||||||
triggerUpdate,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchMonitor = async () => {
|
|
||||||
try {
|
|
||||||
const action = await dispatch(getUptimeMonitorById({ monitorId }));
|
|
||||||
if (getUptimeMonitorById.fulfilled.match(action)) {
|
|
||||||
const monitor = action.payload.data;
|
|
||||||
setMonitor(monitor);
|
|
||||||
} else if (getUptimeMonitorById.rejected.match(action)) {
|
|
||||||
throw new Error(action.error.message);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
logger.error("Error fetching monitor of id: " + monitorId);
|
|
||||||
navigate("/not-found", { replace: true });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
fetchMonitor();
|
|
||||||
}, [monitorId, navigate, trigger]);
|
|
||||||
|
|
||||||
const handleChange = (event, name) => {
|
|
||||||
let { checked, value, id } = event.target;
|
|
||||||
if (!name) name = idMap[id];
|
|
||||||
|
|
||||||
if (name.includes("notification-")) {
|
|
||||||
name = name.replace("notification-", "");
|
|
||||||
let hasNotif = monitor.notifications.some(
|
|
||||||
(notification) => notification.type === name
|
|
||||||
);
|
|
||||||
setMonitor((prev) => {
|
|
||||||
const notifs = [...prev.notifications];
|
|
||||||
if (hasNotif) {
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
notifications: notifs.filter((notif) => notif.type !== name),
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
...prev,
|
|
||||||
notifications: [
|
|
||||||
...notifs,
|
|
||||||
name === "email"
|
|
||||||
? { type: name, address: value }
|
|
||||||
: // TODO - phone number
|
|
||||||
{ type: name, phone: value },
|
|
||||||
],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (name === "interval") {
|
|
||||||
value = value * MS_PER_MINUTE;
|
|
||||||
}
|
|
||||||
if (name === "ignoreTlsErrors") {
|
|
||||||
value = checked;
|
|
||||||
}
|
|
||||||
setMonitor((prev) => ({
|
|
||||||
...prev,
|
|
||||||
[name]: value,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const validation = monitorValidation.validate(
|
|
||||||
{ [name]: value },
|
|
||||||
{ abortEarly: false }
|
|
||||||
);
|
|
||||||
|
|
||||||
setErrors((prev) => {
|
|
||||||
const updatedErrors = { ...prev };
|
|
||||||
|
|
||||||
if (validation.error) updatedErrors[name] = validation.error.details[0].message;
|
|
||||||
else delete updatedErrors[name];
|
|
||||||
return updatedErrors;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (event) => {
|
|
||||||
event.preventDefault();
|
|
||||||
const action = await dispatch(updateUptimeMonitor({ monitor: monitor }));
|
|
||||||
if (action.meta.requestStatus === "fulfilled") {
|
|
||||||
createToast({ body: "Monitor updated successfully!" });
|
|
||||||
} else {
|
|
||||||
createToast({ body: "Failed to update monitor." });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const action = await dispatch(deleteUptimeMonitor({ monitor }));
|
const action = await dispatch(deleteUptimeMonitor({ monitor }));
|
||||||
@@ -191,403 +127,393 @@ const Configure = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const frequencies = [
|
const onChange = (event) => {
|
||||||
{ _id: 1, name: "1 minute" },
|
let { name, value, checked } = event.target;
|
||||||
{ _id: 2, name: "2 minutes" },
|
|
||||||
{ _id: 3, name: "3 minutes" },
|
if (name === "ignoreTlsErrors") {
|
||||||
{ _id: 4, name: "4 minutes" },
|
value = checked;
|
||||||
{ _id: 5, name: "5 minutes" },
|
}
|
||||||
];
|
|
||||||
|
if (name === "interval") {
|
||||||
|
value = value * MS_PER_MINUTE;
|
||||||
|
}
|
||||||
|
setForm({ ...form, [name]: value });
|
||||||
|
|
||||||
|
const validation = monitorValidation.validate(
|
||||||
|
{ [name]: value },
|
||||||
|
{ abortEarly: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
setErrors((prev) => {
|
||||||
|
const updatedErrors = { ...prev };
|
||||||
|
|
||||||
|
if (validation.error) updatedErrors[name] = validation.error.details[0].message;
|
||||||
|
else delete updatedErrors[name];
|
||||||
|
return updatedErrors;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSubmit = async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const toSubmit = {
|
||||||
|
_id: form._id,
|
||||||
|
url: form.url,
|
||||||
|
name: form.name,
|
||||||
|
type: form.type,
|
||||||
|
matchMethod: form.matchMethod,
|
||||||
|
expectedValue: form.expectedValue,
|
||||||
|
jsonPath: form.jsonPath,
|
||||||
|
interval: form.interval,
|
||||||
|
teamId: form.teamId,
|
||||||
|
userId: form.userId,
|
||||||
|
port: form.port,
|
||||||
|
ignoreTlsErrors: form.ignoreTlsErrors,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!useAdvancedMatching) {
|
||||||
|
toSubmit.matchMethod = "";
|
||||||
|
toSubmit.expectedValue = "";
|
||||||
|
toSubmit.jsonPath = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
const validation = monitorValidation.validate(toSubmit, {
|
||||||
|
abortEarly: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validation.error) {
|
||||||
|
const newErrors = {};
|
||||||
|
error.details.forEach((err) => {
|
||||||
|
newErrors[err.path[0]] = err.message;
|
||||||
|
});
|
||||||
|
setErrors(newErrors);
|
||||||
|
createToast({ body: "Please check the form for errors." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toSubmit.notifications = form.notifications;
|
||||||
|
const action = await dispatch(updateUptimeMonitor({ monitor: toSubmit }));
|
||||||
|
if (action.meta.requestStatus === "fulfilled") {
|
||||||
|
createToast({ body: "Monitor updated successfully!" });
|
||||||
|
} else {
|
||||||
|
createToast({ body: "Failed to update monitor." });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Effects
|
||||||
|
useEffect(() => {
|
||||||
|
if (monitor?.matchMethod) {
|
||||||
|
setUseAdvancedMatching(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
setForm({
|
||||||
|
...monitor,
|
||||||
|
});
|
||||||
|
}, [monitor, notifications]);
|
||||||
|
|
||||||
// Parse the URL
|
// Parse the URL
|
||||||
const parsedUrl = parseUrl(monitor?.url);
|
const parsedUrl = parseUrl(monitor?.url);
|
||||||
const protocol = parsedUrl?.protocol?.replace(":", "") || "";
|
const protocol = parsedUrl?.protocol?.replace(":", "") || "";
|
||||||
|
|
||||||
// Notification modal state
|
|
||||||
const [isNotificationModalOpen, setIsNotificationModalOpen] = useState(false);
|
|
||||||
|
|
||||||
const handleOpenNotificationModal = () => {
|
|
||||||
setIsNotificationModalOpen(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleClosenNotificationModal = () => {
|
|
||||||
setIsNotificationModalOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { determineState, statusColor } = useMonitorUtils();
|
const { determineState, statusColor } = useMonitorUtils();
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack
|
<Stack gap={theme.spacing(10)}>
|
||||||
className="configure-monitor"
|
<Breadcrumbs
|
||||||
gap={theme.spacing(10)}
|
list={[
|
||||||
>
|
{ name: "uptime", path: "/uptime" },
|
||||||
{Object.keys(monitor).length === 0 ? (
|
{ name: "details", path: `/uptime/${monitorId}` },
|
||||||
<SkeletonLayout />
|
{ name: "configure", path: `/uptime/configure/${monitorId}` },
|
||||||
) : (
|
]}
|
||||||
<>
|
/>
|
||||||
<Breadcrumbs
|
<Stack
|
||||||
list={[
|
component="form"
|
||||||
{ name: "uptime", path: "/uptime" },
|
onSubmit={onSubmit}
|
||||||
{ name: "details", path: `/uptime/${monitorId}` },
|
noValidate
|
||||||
{ name: "configure", path: `/uptime/configure/${monitorId}` },
|
spellCheck="false"
|
||||||
]}
|
gap={theme.spacing(12)}
|
||||||
/>
|
flex={1}
|
||||||
<Stack
|
>
|
||||||
component="form"
|
<Stack
|
||||||
noValidate
|
direction="row"
|
||||||
spellCheck="false"
|
gap={theme.spacing(12)}
|
||||||
gap={theme.spacing(12)}
|
>
|
||||||
flex={1}
|
<Box>
|
||||||
>
|
<Typography
|
||||||
|
component="h1"
|
||||||
|
variant="monitorName"
|
||||||
|
>
|
||||||
|
{form.name}
|
||||||
|
</Typography>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
height="fit-content"
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
<Box>
|
<Tooltip
|
||||||
<Typography
|
title={t(`statusMsg.${[determineState(form)]}`)}
|
||||||
component="h1"
|
disableInteractive
|
||||||
variant="monitorName"
|
slotProps={{
|
||||||
>
|
popper: {
|
||||||
{monitor.name}
|
modifiers: [
|
||||||
</Typography>
|
{
|
||||||
<Stack
|
name: "offset",
|
||||||
direction="row"
|
options: {
|
||||||
alignItems="center"
|
offset: [0, -8],
|
||||||
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: 4,
|
|
||||||
height: 4,
|
|
||||||
borderRadius: "50%",
|
|
||||||
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
|
||||||
opacity: 0.8,
|
|
||||||
left: -10,
|
|
||||||
top: "50%",
|
|
||||||
transform: "translateY(-50%)",
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t("editing")}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
<Box
|
|
||||||
justifyContent="space-between"
|
|
||||||
sx={{
|
|
||||||
alignSelf: "flex-end",
|
|
||||||
ml: "auto",
|
|
||||||
display: "flex",
|
|
||||||
gap: theme.spacing(2),
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Box>
|
||||||
variant="contained"
|
<PulseDot color={statusColor[determineState(form)]} />
|
||||||
color="secondary"
|
|
||||||
loading={isPausing}
|
|
||||||
startIcon={
|
|
||||||
monitor?.isActive ? <PauseOutlinedIcon /> : <PlayArrowOutlinedIcon />
|
|
||||||
}
|
|
||||||
onClick={() => {
|
|
||||||
pauseMonitor();
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{monitor?.isActive ? t("pause") : t("resume")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
loading={isLoading}
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
sx={{ px: theme.spacing(8) }}
|
|
||||||
onClick={() => setIsOpen(true)}
|
|
||||||
>
|
|
||||||
{t("remove")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</Stack>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("settingsGeneralSettings")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">
|
|
||||||
{t("distributedUptimeCreateSelectURL")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<TextInput
|
|
||||||
type={monitor?.type === "http" ? "url" : "text"}
|
|
||||||
https={protocol === "https"}
|
|
||||||
startAdornment={
|
|
||||||
monitor?.type === "http" && (
|
|
||||||
<HttpAdornment https={protocol === "https"} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
id="monitor-url"
|
|
||||||
label={t("urlMonitor")}
|
|
||||||
placeholder="google.com"
|
|
||||||
value={parsedUrl?.host || monitor?.url || ""}
|
|
||||||
disabled={true}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
type="number"
|
|
||||||
id="monitor-port"
|
|
||||||
label={t("portToMonitor")}
|
|
||||||
placeholder="5173"
|
|
||||||
value={monitor.port || ""}
|
|
||||||
onChange={(event) => handleChange(event, "port")}
|
|
||||||
error={errors["port"] ? true : false}
|
|
||||||
helperText={errors["port"]}
|
|
||||||
hidden={monitor.type !== "port"}
|
|
||||||
/>
|
|
||||||
<TextInput
|
|
||||||
type="text"
|
|
||||||
id="monitor-name"
|
|
||||||
label={t("displayName")}
|
|
||||||
isOptional={true}
|
|
||||||
placeholder="Google"
|
|
||||||
value={monitor?.name || ""}
|
|
||||||
onChange={handleChange}
|
|
||||||
error={errors["name"] ? true : false}
|
|
||||||
helperText={errors["name"]}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("distributedUptimeCreateIncidentNotification")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">
|
|
||||||
{t("distributedUptimeCreateIncidentDescription")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(6)}>
|
|
||||||
<Typography component="p">{t("whenNewIncident")}</Typography>
|
|
||||||
{/* {Leaving components commented for future funtionality implimentation} */}
|
|
||||||
{/* <Checkbox
|
|
||||||
id="notify-sms"
|
|
||||||
label="Notify via SMS (coming soon)"
|
|
||||||
isChecked={false}
|
|
||||||
value=""
|
|
||||||
onChange={() => logger.warn("disabled")}
|
|
||||||
isDisabled={true}
|
|
||||||
/> */}
|
|
||||||
<Checkbox
|
|
||||||
id="notify-email-default"
|
|
||||||
label={`Notify via email (to ${user.email})`}
|
|
||||||
isChecked={
|
|
||||||
monitor?.notifications?.some(
|
|
||||||
(notification) => notification.type === "email"
|
|
||||||
) || false
|
|
||||||
}
|
|
||||||
value={user?.email}
|
|
||||||
onChange={(event) => handleChange(event)}
|
|
||||||
/>
|
|
||||||
<Box mt={theme.spacing(2)}>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
onClick={handleOpenNotificationModal}
|
|
||||||
>
|
|
||||||
{t("notifications.integrationButton")}
|
|
||||||
</Button>
|
|
||||||
</Box>
|
</Box>
|
||||||
{/* <Checkbox
|
</Tooltip>
|
||||||
id="notify-email"
|
<Typography
|
||||||
label="Also notify via email to multiple addresses (coming soon)"
|
component="h2"
|
||||||
isChecked={false}
|
variant="monitorUrl"
|
||||||
value=""
|
|
||||||
onChange={() => logger.warn("disabled")}
|
|
||||||
isDisabled={true}
|
|
||||||
/> */}
|
|
||||||
{/* {monitor?.notifications?.some(
|
|
||||||
(notification) => notification.type === "emails"
|
|
||||||
) ? (
|
|
||||||
<Box mx={theme.spacing(16)}>
|
|
||||||
<TextInput
|
|
||||||
id="notify-email-list"
|
|
||||||
type="text"
|
|
||||||
placeholder="name@gmail.com"
|
|
||||||
value=""
|
|
||||||
onChange={() => logger.warn("disabled")}
|
|
||||||
/>
|
|
||||||
<Typography mt={theme.spacing(4)}>
|
|
||||||
You can separate multiple emails with a comma
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
) : (
|
|
||||||
""
|
|
||||||
)} */}
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("ignoreTLSError")}
|
|
||||||
</Typography>
|
|
||||||
<Typography component="p">{t("ignoreTLSErrorDescription")}</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack>
|
|
||||||
<FormControlLabel
|
|
||||||
sx={{ marginLeft: 0 }}
|
|
||||||
control={
|
|
||||||
<Switch
|
|
||||||
name="ignore-error"
|
|
||||||
checked={monitor.ignoreTlsErrors}
|
|
||||||
onChange={(event) => handleChange(event, "ignoreTlsErrors")}
|
|
||||||
sx={{ mr: theme.spacing(2) }}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
label={t("tlsErrorIgnored")}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<ConfigBox>
|
|
||||||
<Box>
|
|
||||||
<Typography
|
|
||||||
component="h2"
|
|
||||||
variant="h2"
|
|
||||||
>
|
|
||||||
{t("distributedUptimeCreateAdvancedSettings")}
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
<Stack gap={theme.spacing(20)}>
|
|
||||||
<Select
|
|
||||||
id="monitor-interval-configure"
|
|
||||||
label={t("checkFrequency")}
|
|
||||||
value={monitor?.interval / MS_PER_MINUTE || 1}
|
|
||||||
onChange={(event) => handleChange(event, "interval")}
|
|
||||||
items={frequencies}
|
|
||||||
/>
|
|
||||||
{monitor.type === "http" && (
|
|
||||||
<>
|
|
||||||
<Select
|
|
||||||
id="match-method"
|
|
||||||
label={t("matchMethod")}
|
|
||||||
value={monitor.matchMethod || "equal"}
|
|
||||||
onChange={(event) => handleChange(event, "matchMethod")}
|
|
||||||
items={matchMethodOptions}
|
|
||||||
/>
|
|
||||||
<Stack>
|
|
||||||
<TextInput
|
|
||||||
type="text"
|
|
||||||
id="expected-value"
|
|
||||||
label={t("expectedValue")}
|
|
||||||
isOptional={true}
|
|
||||||
placeholder={
|
|
||||||
expectedValuePlaceholders[monitor.matchMethod || "equal"]
|
|
||||||
}
|
|
||||||
value={monitor.expectedValue}
|
|
||||||
onChange={(event) => handleChange(event, "expectedValue")}
|
|
||||||
error={errors["expectedValue"] ? true : false}
|
|
||||||
helperText={errors["expectedValue"]}
|
|
||||||
/>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
color={theme.palette.primary.contrastTextTertiary}
|
|
||||||
opacity={0.8}
|
|
||||||
>
|
|
||||||
{t("uptimeCreate")}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
<Stack>
|
|
||||||
<TextInput
|
|
||||||
type="text"
|
|
||||||
id="json-path"
|
|
||||||
label="JSON Path"
|
|
||||||
isOptional={true}
|
|
||||||
placeholder="data.status"
|
|
||||||
value={monitor.jsonPath}
|
|
||||||
onChange={(event) => handleChange(event, "jsonPath")}
|
|
||||||
error={errors["jsonPath"] ? true : false}
|
|
||||||
helperText={errors["jsonPath"]}
|
|
||||||
/>
|
|
||||||
<Typography
|
|
||||||
component="span"
|
|
||||||
color={theme.palette.primary.contrastTextTertiary}
|
|
||||||
opacity={0.8}
|
|
||||||
>
|
|
||||||
{t("uptimeCreateJsonPath")}
|
|
||||||
<Typography
|
|
||||||
component="a"
|
|
||||||
href="https://jmespath.org/"
|
|
||||||
target="_blank"
|
|
||||||
color="info"
|
|
||||||
>
|
|
||||||
jmespath.org
|
|
||||||
</Typography>
|
|
||||||
{t("uptimeCreateJsonPathQuery")}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
</ConfigBox>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
justifyContent="flex-end"
|
|
||||||
mt="auto"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="accent"
|
|
||||||
loading={isLoading}
|
|
||||||
sx={{ px: theme.spacing(12) }}
|
|
||||||
onClick={handleSubmit}
|
|
||||||
>
|
>
|
||||||
{t("settingsSave")}
|
{form.url?.replace(/^https?:\/\//, "") || "..."}
|
||||||
</Button>
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
position="relative"
|
||||||
|
variant="body2"
|
||||||
|
ml={theme.spacing(6)}
|
||||||
|
mt={theme.spacing(1)}
|
||||||
|
sx={{
|
||||||
|
"&:before": {
|
||||||
|
position: "absolute",
|
||||||
|
content: `""`,
|
||||||
|
width: 4,
|
||||||
|
height: 4,
|
||||||
|
borderRadius: "50%",
|
||||||
|
backgroundColor: theme.palette.primary.contrastTextTertiary,
|
||||||
|
opacity: 0.8,
|
||||||
|
left: -10,
|
||||||
|
top: "50%",
|
||||||
|
transform: "translateY(-50%)",
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("editing")}
|
||||||
|
</Typography>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
<Box
|
||||||
|
justifyContent="space-between"
|
||||||
|
sx={{
|
||||||
|
alignSelf: "flex-end",
|
||||||
|
ml: "auto",
|
||||||
|
display: "flex",
|
||||||
|
gap: theme.spacing(2),
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
loading={isPausing}
|
||||||
|
startIcon={
|
||||||
|
form?.isActive ? <PauseOutlinedIcon /> : <PlayArrowOutlinedIcon />
|
||||||
|
}
|
||||||
|
onClick={handlePause}
|
||||||
|
>
|
||||||
|
{form?.isActive ? t("pause") : t("resume")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
loading={isLoading}
|
||||||
|
variant="contained"
|
||||||
|
color="error"
|
||||||
|
sx={{ px: theme.spacing(8) }}
|
||||||
|
onClick={() => setIsOpen(true)}
|
||||||
|
>
|
||||||
|
{t("remove")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
</Stack>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
>
|
||||||
|
{t("settingsGeneralSettings")}
|
||||||
|
</Typography>
|
||||||
|
<Typography component="p">{t("distributedUptimeCreateSelectURL")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
<TextInput
|
||||||
|
type={form?.type === "http" ? "url" : "text"}
|
||||||
|
https={protocol === "https"}
|
||||||
|
startAdornment={
|
||||||
|
form?.type === "http" && <HttpAdornment https={protocol === "https"} />
|
||||||
|
}
|
||||||
|
id="monitor-url"
|
||||||
|
label={t("urlMonitor")}
|
||||||
|
placeholder="google.com"
|
||||||
|
value={parsedUrl?.host || form?.url || ""}
|
||||||
|
disabled={true}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
name="port"
|
||||||
|
type="number"
|
||||||
|
label={t("portToMonitor")}
|
||||||
|
placeholder="5173"
|
||||||
|
value={form.port || ""}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors["port"] ? true : false}
|
||||||
|
helperText={errors["port"]}
|
||||||
|
hidden={form.type !== "port"}
|
||||||
|
/>
|
||||||
|
<TextInput
|
||||||
|
name="name"
|
||||||
|
type="text"
|
||||||
|
label={t("displayName")}
|
||||||
|
isOptional={true}
|
||||||
|
placeholder="Google"
|
||||||
|
value={form?.name || ""}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors["name"] ? true : false}
|
||||||
|
helperText={errors["name"]}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</ConfigBox>
|
||||||
)}
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Notifications</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
Select the notifications you want to send out
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<NotificationsConfig
|
||||||
|
notifications={notifications}
|
||||||
|
setMonitor={setForm}
|
||||||
|
setNotifications={form.notifications}
|
||||||
|
/>
|
||||||
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
>
|
||||||
|
{t("ignoreTLSError")}
|
||||||
|
</Typography>
|
||||||
|
<Typography component="p">{t("ignoreTLSErrorDescription")}</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack>
|
||||||
|
<FormControlLabel
|
||||||
|
sx={{ marginLeft: 0 }}
|
||||||
|
control={
|
||||||
|
<Switch
|
||||||
|
name="ignoreTlsErrors"
|
||||||
|
checked={form.ignoreTlsErrors ?? false}
|
||||||
|
onChange={onChange}
|
||||||
|
sx={{ mr: theme.spacing(2) }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
label={t("tlsErrorIgnored")}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography
|
||||||
|
component="h2"
|
||||||
|
variant="h2"
|
||||||
|
>
|
||||||
|
{t("distributedUptimeCreateAdvancedSettings")}
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(20)}>
|
||||||
|
<Select
|
||||||
|
name="interval"
|
||||||
|
label={t("checkFrequency")}
|
||||||
|
value={form?.interval / MS_PER_MINUTE || 1}
|
||||||
|
onChange={onChange}
|
||||||
|
items={frequencies}
|
||||||
|
/>
|
||||||
|
{form.type === "http" && (
|
||||||
|
<>
|
||||||
|
<Select
|
||||||
|
name="matchMethod"
|
||||||
|
label={t("matchMethod")}
|
||||||
|
value={form.matchMethod || "equal"}
|
||||||
|
onChange={onChange}
|
||||||
|
items={matchMethodOptions}
|
||||||
|
/>
|
||||||
|
<Stack>
|
||||||
|
<TextInput
|
||||||
|
type="text"
|
||||||
|
name="expectedValue"
|
||||||
|
label={t("expectedValue")}
|
||||||
|
isOptional={true}
|
||||||
|
placeholder={expectedValuePlaceholders[form.matchMethod || "equal"]}
|
||||||
|
value={form.expectedValue}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors["expectedValue"] ? true : false}
|
||||||
|
helperText={errors["expectedValue"]}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
color={theme.palette.primary.contrastTextTertiary}
|
||||||
|
opacity={0.8}
|
||||||
|
>
|
||||||
|
{t("uptimeCreate")}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Stack>
|
||||||
|
<TextInput
|
||||||
|
name="jsonPath"
|
||||||
|
type="text"
|
||||||
|
label="JSON Path"
|
||||||
|
isOptional={true}
|
||||||
|
placeholder="data.status"
|
||||||
|
value={form.jsonPath}
|
||||||
|
onChange={onChange}
|
||||||
|
error={errors["jsonPath"] ? true : false}
|
||||||
|
helperText={errors["jsonPath"]}
|
||||||
|
/>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
color={theme.palette.primary.contrastTextTertiary}
|
||||||
|
opacity={0.8}
|
||||||
|
>
|
||||||
|
{t("uptimeCreateJsonPath")}
|
||||||
|
<Typography
|
||||||
|
component="a"
|
||||||
|
href="https://jmespath.org/"
|
||||||
|
target="_blank"
|
||||||
|
color="info"
|
||||||
|
>
|
||||||
|
jmespath.org
|
||||||
|
</Typography>
|
||||||
|
{t("uptimeCreateJsonPathQuery")}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
mt="auto"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
color="accent"
|
||||||
|
loading={isLoading}
|
||||||
|
sx={{ px: theme.spacing(12) }}
|
||||||
|
>
|
||||||
|
{t("settingsSave")}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
<Dialog
|
<Dialog
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
@@ -598,13 +524,6 @@ const Configure = () => {
|
|||||||
onConfirm={handleRemove}
|
onConfirm={handleRemove}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<NotificationIntegrationModal
|
|
||||||
open={isNotificationModalOpen}
|
|
||||||
onClose={handleClosenNotificationModal}
|
|
||||||
monitor={monitor}
|
|
||||||
setMonitor={setMonitor}
|
|
||||||
/>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user