diff --git a/client/src/Hooks/useMonitorUtils.js b/client/src/Hooks/useMonitorUtils.js index 417c6eadd..b57c11a12 100644 --- a/client/src/Hooks/useMonitorUtils.js +++ b/client/src/Hooks/useMonitorUtils.js @@ -6,18 +6,18 @@ const useMonitorUtils = () => { let uptimePercentage = ""; let percentageColor = ""; - if (monitor.uptimePercentage !== undefined) { + if (monitor?.uptimePercentage !== undefined) { uptimePercentage = - monitor.uptimePercentage === 0 + monitor?.uptimePercentage === 0 ? "0" - : (monitor.uptimePercentage * 100).toFixed(2); + : (monitor?.uptimePercentage * 100).toFixed(2); percentageColor = - monitor.uptimePercentage < 0.25 + monitor?.uptimePercentage < 0.25 ? theme.palette.error.main - : monitor.uptimePercentage < 0.5 + : monitor?.uptimePercentage < 0.5 ? theme.palette.warning.main - : monitor.uptimePercentage < 0.75 + : monitor?.uptimePercentage < 0.75 ? theme.palette.success.main : theme.palette.success.main; } @@ -32,7 +32,7 @@ const useMonitorUtils = () => { const determineState = useCallback((monitor) => { if (typeof monitor === "undefined") return "pending"; - if (monitor.isActive === false) return "paused"; + if (monitor?.isActive === false) return "paused"; if (monitor?.status === undefined) return "pending"; return monitor?.status == true ? "up" : "down"; }, []); diff --git a/client/src/Pages/Uptime/Configure/index.jsx b/client/src/Pages/Uptime/Configure/index.jsx index 2dacc26ab..061db6ac0 100644 --- a/client/src/Pages/Uptime/Configure/index.jsx +++ b/client/src/Pages/Uptime/Configure/index.jsx @@ -163,18 +163,18 @@ const Configure = () => { 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, + _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) { @@ -197,7 +197,7 @@ const Configure = () => { return; } - toSubmit.notifications = form.notifications; + toSubmit.notifications = form?.notifications; await updateMonitor({ monitor: toSubmit, redirect: "/uptime" }); }; @@ -235,7 +235,7 @@ const Configure = () => { component="h1" variant="monitorName" > - {form.name} + {form?.name} { component="h2" variant="monitorUrl" > - {form.url?.replace(/^https?:\/\//, "") || "..."} + {form?.url?.replace(/^https?:\/\//, "") || "..."} { type="number" label={t("portToMonitor")} placeholder="5173" - value={form.port || ""} + value={form?.port || ""} onChange={onChange} error={errors["port"] ? true : false} helperText={errors["port"]} - hidden={form.type !== "port"} + hidden={form?.type !== "port"} /> { @@ -398,7 +398,7 @@ const Configure = () => { control={ @@ -430,12 +430,12 @@ const Configure = () => { isChecked={useAdvancedMatching} onChange={onChange} /> - {form.type === "http" && useAdvancedMatching && ( + {form?.type === "http" && useAdvancedMatching && ( <>