diff --git a/client/src/Pages/Uptime/Create/index.jsx b/client/src/Pages/Uptime/Create/index.jsx
index c6caeacb1..fcf81f1c3 100644
--- a/client/src/Pages/Uptime/Create/index.jsx
+++ b/client/src/Pages/Uptime/Create/index.jsx
@@ -1,13 +1,13 @@
//Components
import {
- Box,
- Button,
- ButtonGroup,
- FormControlLabel,
- Stack,
- Switch,
- Tooltip,
- Typography,
+ Box,
+ Button,
+ ButtonGroup,
+ FormControlLabel,
+ Stack,
+ Switch,
+ Tooltip,
+ Typography,
} from "@mui/material";
import Breadcrumbs from "../../../Components/Breadcrumbs";
import TextInput from "../../../Components/Inputs/TextInput";
@@ -30,20 +30,19 @@ import { monitorValidation } from "../../../Validation/validation";
import { createToast } from "../../../Utils/toastUtils";
import { useTranslation } from "react-i18next";
import {
- PauseOutlined as PauseOutlinedIcon,
- PlayArrowOutlined as PlayArrowOutlinedIcon,
+ PauseOutlined as PauseOutlinedIcon,
+ PlayArrowOutlined as PlayArrowOutlinedIcon,
} from "@mui/icons-material";
import { useMonitorUtils } from "../../../Hooks/useMonitorUtils";
import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications";
import { useCreateMonitor, useFetchMonitorById } from "../../../Hooks/monitorHooks";
import { useParams } from "react-router-dom";
import {
- useDeleteMonitor,
- useUpdateMonitor,
- usePauseMonitor,
- useFetchMonitorById,
+ useDeleteMonitor,
+ useUpdateMonitor,
+ usePauseMonitor,
+ useFetchMonitorById,
} from "../../../Hooks/monitorHooks";
-import { useCreateMonitor } from "../../../Hooks/monitorHooks";
/**
* Parses a URL string and returns a URL object.
@@ -52,11 +51,11 @@ import { useCreateMonitor } from "../../../Hooks/monitorHooks";
* @returns {URL} - The parsed URL object if valid, otherwise an empty string.
*/
const parseUrl = (url) => {
- try {
- return new URL(url);
- } catch (error) {
- return null;
- }
+ try {
+ return new URL(url);
+ } catch (error) {
+ return null;
+ }
};
/**
@@ -64,661 +63,661 @@ const parseUrl = (url) => {
* @component
*/
const UptimeCreate = () => {
- const { monitorId } = useParams();
- const isCreate = typeof monitorId === "undefined";
+ const { monitorId } = useParams();
+ const isCreate = typeof monitorId === "undefined";
- // States
- const [monitor, setMonitor] = useState({
- type: "http",
- matchMethod: "equal",
- expectedValue: "",
- jsonPath: "",
- notifications: [],
- interval: 60000,
- ignoreTlsErrors: false,
- ...(isCreate ? { url: "", name: "" } : { port: undefined }),
- });
- const [errors, setErrors] = useState({});
- const [https, setHttps] = useState(true);
- const [isOpen, setIsOpen] = useState(false);
- const [useAdvancedMatching, setUseAdvancedMatching] = useState(false);
- const [updateTrigger, setUpdateTrigger] = useState(false);
- const triggerUpdate = () => {
- setUpdateTrigger(!updateTrigger);
- };
+ // States
+ const [monitor, setMonitor] = useState({
+ type: "http",
+ matchMethod: "equal",
+ expectedValue: "",
+ jsonPath: "",
+ notifications: [],
+ interval: 60000,
+ ignoreTlsErrors: false,
+ ...(isCreate ? { url: "", name: "" } : { port: undefined }),
+ });
+ const [errors, setErrors] = useState({});
+ const [https, setHttps] = useState(true);
+ const [isOpen, setIsOpen] = useState(false);
+ const [useAdvancedMatching, setUseAdvancedMatching] = useState(false);
+ const [updateTrigger, setUpdateTrigger] = useState(false);
+ const triggerUpdate = () => {
+ setUpdateTrigger(!updateTrigger);
+ };
- // Hooks
- const [notifications, notificationsAreLoading, notificationsError] =
- useGetNotificationsByTeamId();
- const { determineState, statusColor } = useMonitorUtils();
- // Network
- const [isLoading] = useFetchMonitorById({
- monitorId,
- setMonitor: formatAndSet,
- updateTrigger: true,
- });
- const [createMonitor, isCreating] = useCreateMonitor();
- const [pauseMonitor, isPausing] = usePauseMonitor({});
- const [deleteMonitor, isDeleting] = useDeleteMonitor();
- const [updateMonitor, isUpdating] = useUpdateMonitor();
+ // Hooks
+ const [notifications, notificationsAreLoading, notificationsError] =
+ useGetNotificationsByTeamId();
+ const { determineState, statusColor } = useMonitorUtils();
+ // Network
+ const [isLoading] = useFetchMonitorById({
+ monitorId,
+ setMonitor: formatAndSet,
+ updateTrigger: true,
+ });
+ const [createMonitor, isCreating] = useCreateMonitor();
+ const [pauseMonitor, isPausing] = usePauseMonitor({});
+ const [deleteMonitor, isDeleting] = useDeleteMonitor();
+ const [updateMonitor, isUpdating] = useUpdateMonitor();
- // Setup
- const theme = useTheme();
- const { t } = useTranslation();
- const formatAndSet = (monitor) => {
- monitor.interval = monitor.interval / MS_PER_MINUTE;
- setMonitor(monitor);
- };
+ // Setup
+ const theme = useTheme();
+ const { t } = useTranslation();
- // Constants
- const MS_PER_MINUTE = 60000;
- const FREQUENCIES = [
- { _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") },
- ];
- 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 = [
- { _id: "equal", name: t("matchMethodOptions.equal") },
- { _id: "include", name: t("matchMethodOptions.include") },
- { _id: "regex", name: t("matchMethodOptions.regex") },
- ];
- const expectedValuePlaceholders = {
- regex: t("matchMethodOptions.regexPlaceholder"),
- equal: t("matchMethodOptions.equalPlaceholder"),
- include: t("matchMethodOptions.includePlaceholder"),
- };
- const monitorTypeMaps = {
- http: {
- label: t("monitorType.http.label"),
- placeholder: t("monitorType.http.placeholder"),
- namePlaceholder: t("monitorType.http.namePlaceholder"),
- },
- ping: {
- label: t("monitorType.ping.label"),
- placeholder: t("monitorType.ping.placeholder"),
- namePlaceholder: t("monitorType.ping.namePlaceholder"),
- },
- docker: {
- label: t("monitorType.docker.label"),
- placeholder: t("monitorType.docker.placeholder"),
- namePlaceholder: t("monitorType.docker.namePlaceholder"),
- },
- port: {
- label: t("monitorType.port.label"),
- placeholder: t("monitorType.port.placeholder"),
- namePlaceholder: t("monitorType.port.namePlaceholder"),
- },
- };
+ // Constants
+ const MS_PER_MINUTE = 60000;
+ const FREQUENCIES = [
+ { _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") },
+ ];
+ 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 = [
+ { _id: "equal", name: t("matchMethodOptions.equal") },
+ { _id: "include", name: t("matchMethodOptions.include") },
+ { _id: "regex", name: t("matchMethodOptions.regex") },
+ ];
+ const expectedValuePlaceholders = {
+ regex: t("matchMethodOptions.regexPlaceholder"),
+ equal: t("matchMethodOptions.equalPlaceholder"),
+ include: t("matchMethodOptions.includePlaceholder"),
+ };
+ const monitorTypeMaps = {
+ http: {
+ label: t("monitorType.http.label"),
+ placeholder: t("monitorType.http.placeholder"),
+ namePlaceholder: t("monitorType.http.namePlaceholder"),
+ },
+ ping: {
+ label: t("monitorType.ping.label"),
+ placeholder: t("monitorType.ping.placeholder"),
+ namePlaceholder: t("monitorType.ping.namePlaceholder"),
+ },
+ docker: {
+ label: t("monitorType.docker.label"),
+ placeholder: t("monitorType.docker.placeholder"),
+ namePlaceholder: t("monitorType.docker.namePlaceholder"),
+ },
+ port: {
+ label: t("monitorType.port.label"),
+ placeholder: t("monitorType.port.placeholder"),
+ namePlaceholder: t("monitorType.port.namePlaceholder"),
+ },
+ };
+ const formatAndSet = (monitor) => {
+ monitor.interval = monitor.interval / MS_PER_MINUTE;
+ setMonitor(monitor);
+ };
- // Handlers
- const onSubmit = async (event) => {
- event.preventDefault();
- const { notifications, ...rest } = monitor;
+ // Handlers
+ const onSubmit = async (event) => {
+ event.preventDefault();
+ const { notifications, ...rest } = monitor;
- let form = {};
- if (isCreate) {
- form = {
- ...rest,
- url:
- monitor.type === "http"
- ? `http${https ? "s" : ""}://` + monitor.url
- : monitor.url,
- port: monitor.type === "port" ? monitor.port : undefined,
- name: monitor.name || monitor.url.substring(0, 50),
- type: monitor.type,
- interval: monitor.interval,
- };
- } else {
- form = {
- _id: monitor._id,
- url: monitor.url,
- name: monitor.name || monitor.url.substring(0, 50),
- type: monitor.type,
- matchMethod: monitor.matchMethod,
- expectedValue: monitor.expectedValue,
- jsonPath: monitor.jsonPath,
- interval: monitor.interval,
- teamId: monitor.teamId,
- userId: monitor.userId,
- port: monitor.type === "port" ? monitor.port : undefined,
- ignoreTlsErrors: monitor.ignoreTlsErrors,
- };
- }
- if (!useAdvancedMatching) {
- form.matchMethod = isCreate ? undefined : "";
- form.expectedValue = isCreate ? undefined : "";
- form.jsonPath = isCreate ? undefined : "";
- }
+ let form = {};
+ if (isCreate) {
+ form = {
+ ...rest,
+ url:
+ monitor.type === "http"
+ ? `http${https ? "s" : ""}://` + monitor.url
+ : monitor.url,
+ port: monitor.type === "port" ? monitor.port : undefined,
+ name: monitor.name || monitor.url.substring(0, 50),
+ type: monitor.type,
+ interval: monitor.interval,
+ };
+ } else {
+ form = {
+ _id: monitor._id,
+ url: monitor.url,
+ name: monitor.name || monitor.url.substring(0, 50),
+ type: monitor.type,
+ matchMethod: monitor.matchMethod,
+ expectedValue: monitor.expectedValue,
+ jsonPath: monitor.jsonPath,
+ interval: monitor.interval,
+ teamId: monitor.teamId,
+ userId: monitor.userId,
+ port: monitor.type === "port" ? monitor.port : undefined,
+ ignoreTlsErrors: monitor.ignoreTlsErrors,
+ };
+ }
+ if (!useAdvancedMatching) {
+ form.matchMethod = isCreate ? undefined : "";
+ form.expectedValue = isCreate ? undefined : "";
+ form.jsonPath = isCreate ? undefined : "";
+ }
- const { error } = monitorValidation.validate(form, {
- abortEarly: false,
- });
+ const { error } = monitorValidation.validate(form, {
+ abortEarly: false,
+ });
- if (error) {
- const newErrors = {};
- error.details.forEach((err) => {
- newErrors[err.path[0]] = err.message;
- });
- setErrors(newErrors);
- createToast({ body: t("checkFormError") });
- return;
- }
+ if (error) {
+ const newErrors = {};
+ error.details.forEach((err) => {
+ newErrors[err.path[0]] = err.message;
+ });
+ setErrors(newErrors);
+ createToast({ body: t("checkFormError") });
+ return;
+ }
- form = {
- ...form,
- description: monitor.name || monitor.url,
- notifications: monitor.notifications,
- };
+ form = {
+ ...form,
+ description: monitor.name || monitor.url,
+ notifications: monitor.notifications,
+ };
- if (isCreate) {
- await createMonitor({ monitor: form, redirect: "/uptime" });
- } else {
- await updateMonitor({ monitor: form, redirect: "/uptime" });
- }
- };
+ if (isCreate) {
+ await createMonitor({ monitor: form, redirect: "/uptime" });
+ } else {
+ await updateMonitor({ monitor: form, redirect: "/uptime" });
+ }
+ };
- const onChange = (event) => {
- let { name, value, checked } = event.target;
+ const onChange = (event) => {
+ let { name, value, checked } = event.target;
- if (name === "ignoreTlsErrors") {
- value = checked;
- }
+ if (name === "ignoreTlsErrors") {
+ value = checked;
+ }
- if (name === "useAdvancedMatching") {
- setUseAdvancedMatching(checked);
- return;
- }
+ if (name === "useAdvancedMatching") {
+ setUseAdvancedMatching(checked);
+ return;
+ }
- if (name === "interval") {
- value = value * MS_PER_MINUTE;
- }
+ if (name === "interval") {
+ value = value * MS_PER_MINUTE;
+ }
- setMonitor((prev) => ({ ...prev, [name]: value }));
+ setMonitor((prev) => ({ ...prev, [name]: value }));
- const { error } = monitorValidation.validate(
- { type: monitor.type, [name]: value },
- { abortEarly: false }
- );
+ const { error } = monitorValidation.validate(
+ { type: monitor.type, [name]: value },
+ { abortEarly: false }
+ );
- setErrors((prev) => ({
- ...prev,
- ...(error ? { [name]: error.details[0].message } : { [name]: undefined }),
- }));
- };
+ setErrors((prev) => ({
+ ...prev,
+ ...(error ? { [name]: error.details[0].message } : { [name]: undefined }),
+ }));
+ };
- const handlePause = async () => {
- await pauseMonitor({ monitorId, triggerUpdate });
- };
+ const handlePause = async () => {
+ await pauseMonitor({ monitorId, triggerUpdate });
+ };
- const handleRemove = async (event) => {
- event.preventDefault();
- await deleteMonitor({ monitor, redirect: "/uptime" });
- };
+ const handleRemove = async (event) => {
+ event.preventDefault();
+ await deleteMonitor({ monitor, redirect: "/uptime" });
+ };
- const isBusy = isLoading || isCreating || isDeleting || isUpdating || isPausing;
- const parsedUrl = parseUrl(monitor?.url);
- const protocol = parsedUrl?.protocol?.replace(":", "") || "";
+ const isBusy = isLoading || isCreating || isDeleting || isUpdating || isPausing;
+ const parsedUrl = parseUrl(monitor?.url);
+ const protocol = parsedUrl?.protocol?.replace(":", "") || "";
- if (Object.keys(monitor).length === 0) {
- return ;
- }
- useEffect(() => {
- if (!isCreate) {
- if (monitor.matchMethod) {
- setUseAdvancedMatching(true);
- } else {
- setUseAdvancedMatching(false);
- }
- }
- }, [monitor]);
+ if (Object.keys(monitor).length === 0) {
+ return ;
+ }
+ useEffect(() => {
+ if (!isCreate) {
+ if (monitor.matchMethod) {
+ setUseAdvancedMatching(true);
+ } else {
+ setUseAdvancedMatching(false);
+ }
+ }
+ }, [monitor]);
- return (
-
-
+ return (
+
+
-
-
-
-
-
- {!isCreate ? monitor.name : t("createYour") + " "}
-
- {isCreate && (
-
- {t("monitor")}
-
- )}
-
- {!isCreate && (
-
-
-
-
-
-
-
- {monitor.url?.replace(/^https?:\/\//, "") || "..."}
-
-
- {t("editing")}
-
-
- )}
-
- {!isCreate && (
-
- :
- }
- onClick={handlePause}
- >
- {monitor?.isActive ? t("pause") : t("resume")}
-
-
-
- )}
-
- {isCreate && (
-
-
-
- {t("distributedUptimeCreateChecks")}
-
-
- {t("distributedUptimeCreateChecksDescription")}
-
-
-
-
-
- {monitor.type === "http" ? (
-
-
-
-
- ) : (
- ""
- )}
-
-
-
-
- {errors["type"] ? (
-
-
- {errors["type"]}
-
-
- ) : (
- ""
- )}
-
-
- )}
-
-
-
- {t("settingsGeneralSettings")}
-
-
- {isCreate
- ? t(`uptimeGeneralInstructions.${monitor.type}`)
- : t("distributedUptimeCreateSelectURL")}
-
-
-
-
- )
- }
- helperText={errors["url"]}
- onChange={onChange}
- disabled={!isCreate}
- />
-
-
-
-
-
-
- {t("notificationConfig.title")}
- {t("notificationConfig.description")}
-
-
-
-
-
-
- {t("ignoreTLSError")}
-
- {t("ignoreTLSErrorDescription")}
-
-
-
- }
- label={t("tlsErrorIgnored")}
- />
-
-
-
-
-
- {t("distributedUptimeCreateAdvancedSettings")}
-
-
-
-
- {monitor.type === "http" && (
-
- )}
- {monitor.type === "http" && useAdvancedMatching && (
- <>
-
-
-
-
- {t("uptimeCreate")}
-
-
-
-
-
- {t("uptimeCreateJsonPath") + " "}
-
- jmespath.org
-
- {" " + t("uptimeCreateJsonPathQuery")}
-
-
- >
- )}
-
-
-
-
-
-
+
+
+
+
+
+ {!isCreate ? monitor.name : t("createYour") + " "}
+
+ {isCreate && (
+
+ {t("monitor")}
+
+ )}
+
+ {!isCreate && (
+
+
+
+
+
+
+
+ {monitor.url?.replace(/^https?:\/\//, "") || "..."}
+
+
+ {t("editing")}
+
+
+ )}
+
+ {!isCreate && (
+
+ :
+ }
+ onClick={handlePause}
+ >
+ {monitor?.isActive ? t("pause") : t("resume")}
+
+
+
+ )}
+
+ {isCreate && (
+
+
+
+ {t("distributedUptimeCreateChecks")}
+
+
+ {t("distributedUptimeCreateChecksDescription")}
+
+
+
+
+
+ {monitor.type === "http" ? (
+
+
+
+
+ ) : (
+ ""
+ )}
+
+
+
+
+ {errors["type"] ? (
+
+
+ {errors["type"]}
+
+
+ ) : (
+ ""
+ )}
+
+
+ )}
+
+
+
+ {t("settingsGeneralSettings")}
+
+
+ {isCreate
+ ? t(`uptimeGeneralInstructions.${monitor.type}`)
+ : t("distributedUptimeCreateSelectURL")}
+
+
+
+
+ )
+ }
+ helperText={errors["url"]}
+ onChange={onChange}
+ disabled={!isCreate}
+ />
+
+
+
+
+
+
+ {t("notificationConfig.title")}
+ {t("notificationConfig.description")}
+
+
+
+
+
+
+ {t("ignoreTLSError")}
+
+ {t("ignoreTLSErrorDescription")}
+
+
+
+ }
+ label={t("tlsErrorIgnored")}
+ />
+
+
+
+
+
+ {t("distributedUptimeCreateAdvancedSettings")}
+
+
+
+
+ {monitor.type === "http" && (
+
+ )}
+ {monitor.type === "http" && useAdvancedMatching && (
+ <>
+
+
+
+
+ {t("uptimeCreate")}
+
+
+
+
+
+ {t("uptimeCreateJsonPath") + " "}
+
+ jmespath.org
+
+ {" " + t("uptimeCreateJsonPathQuery")}
+
+
+ >
+ )}
+
+
+
+
+
+
- {!isCreate && (
-
- );
+ {!isCreate && (
+
+ );
};
export default UptimeCreate;