diff --git a/client/src/Hooks/monitorHooks.js b/client/src/Hooks/monitorHooks.js index d59d88c74..4f0e9c049 100644 --- a/client/src/Hooks/monitorHooks.js +++ b/client/src/Hooks/monitorHooks.js @@ -205,6 +205,10 @@ const useFetchStatsByMonitorId = ({ const useFetchMonitorById = ({ monitorId, setMonitor, updateTrigger }) => { const [isLoading, setIsLoading] = useState(true); useEffect(() => { + if (typeof monitorId === "undefined") { + setIsLoading(false); + return; + } const fetchMonitor = async () => { try { setIsLoading(true); diff --git a/client/src/Pages/PageSpeed/Configure/index.css b/client/src/Pages/PageSpeed/Configure/index.css deleted file mode 100644 index 89a7c3466..000000000 --- a/client/src/Pages/PageSpeed/Configure/index.css +++ /dev/null @@ -1,9 +0,0 @@ -.configure-pagespeed button { - height: var(--env-var-height-2); -} - -.configure-pagespeed .field, -.configure-pagespeed .section-disabled, -.configure-pagespeed .select-wrapper { - flex: 1; -} diff --git a/client/src/Pages/PageSpeed/Configure/index.jsx b/client/src/Pages/PageSpeed/Configure/index.jsx deleted file mode 100644 index 71e1e111e..000000000 --- a/client/src/Pages/PageSpeed/Configure/index.jsx +++ /dev/null @@ -1,351 +0,0 @@ -// Components -import { Box, Stack, Tooltip, Typography, Button } from "@mui/material"; -import ConfigBox from "../../../Components/ConfigBox"; -import Select from "../../../Components/Inputs/Select"; -import TextInput from "../../../Components/Inputs/TextInput"; -import PauseCircleOutlineIcon from "@mui/icons-material/PauseCircleOutline"; -import Breadcrumbs from "../../../Components/Breadcrumbs"; -import PulseDot from "../../../Components/Animated/PulseDot"; -import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineRounded"; -import SkeletonLayout from "./skeleton"; -import NotificationsConfig from "../../../Components/NotificationConfig"; -import Dialog from "../../../Components/Dialog"; - -// Utils -import { useState } from "react"; -import { useTheme } from "@emotion/react"; -import { useParams } from "react-router"; -import { monitorValidation } from "../../../Validation/validation"; -import { useTranslation } from "react-i18next"; -import { useMonitorUtils } from "../../../Hooks/useMonitorUtils"; -import { useGetNotificationsByTeamId } from "../../../Hooks/useNotifications"; -import { - useFetchMonitorById, - useDeleteMonitor, - useUpdateMonitor, - usePauseMonitor, -} from "../../../Hooks/monitorHooks"; -const PageSpeedConfigure = () => { - // Redux state - - // Local state - const [monitor, setMonitor] = useState({}); - const [errors, setErrors] = useState({}); - const [isOpen, setIsOpen] = useState(false); - const [updateTrigger, setUpdateTrigger] = useState(false); - - // Utils - const theme = useTheme(); - const { t } = useTranslation(); - const MS_PER_MINUTE = 60000; - const { monitorId } = useParams(); - const { statusColor, pagespeedStatusMsg, determineState } = useMonitorUtils(); - - const [notifications, notificationsAreLoading, notificationsError] = - useGetNotificationsByTeamId(); - - const [isLoading] = useFetchMonitorById({ monitorId, setMonitor, updateTrigger }); - const [deleteMonitor, isDeleting] = useDeleteMonitor(); - const [updateMonitor, isUpdating] = useUpdateMonitor(); - const [pauseMonitor, isPausing] = usePauseMonitor(); - - const frequencies = [ - { _id: 3, name: "3 minutes" }, - { _id: 5, name: "5 minutes" }, - { _id: 10, name: "10 minutes" }, - { _id: 20, name: "20 minutes" }, - { _id: 60, name: "1 hour" }, - { _id: 1440, name: "1 day" }, - { _id: 10080, name: "1 week" }, - ]; - - // Handlers - const triggerUpdate = () => { - setUpdateTrigger(!updateTrigger); - }; - - const onChange = (event) => { - let { value, name } = event.target; - - if (name === "interval") { - value = value * MS_PER_MINUTE; - } - 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 handlePause = async () => { - await pauseMonitor({ monitorId, triggerUpdate }); - }; - - const onSubmit = async (event) => { - event.preventDefault(); - await updateMonitor({ monitor, redirect: "/pagespeed" }); - }; - - const handleRemove = async (event) => { - event.preventDefault(); - await deleteMonitor({ monitor, redirect: "/pagespeed" }); - }; - - return ( - - {Object.keys(monitor).length === 0 ? ( - - ) : ( - <> - - - - - - {monitor.name} - - - - - - - - - {monitor.url?.replace(/^https?:\/\//, "") || "..."} - - - {t("editing")} - - - - - - - - - - - - {t("settingsGeneralSettings")} - - - {t("pageSpeedConfigureSettingsDescription")} - - - .Mui-disabled)": { - backgroundColor: theme.palette.tertiary.main, - }, - }} - > - - - - - - - {t("notificationConfig.title")} - - {t("notificationConfig.description")} - - - - - - - - {t("distributedUptimeCreateAdvancedSettings")} - - - - + {!isCreate && ( + setIsOpen(false)} + confirmationButtonLabel={t("delete")} + onConfirm={handleRemove} + /> + )} ); }; -export default CreatePageSpeed; + +export default PageSpeedSetup; diff --git a/client/src/Pages/PageSpeed/Configure/skeleton.jsx b/client/src/Pages/PageSpeed/Create/skeleton.jsx similarity index 100% rename from client/src/Pages/PageSpeed/Configure/skeleton.jsx rename to client/src/Pages/PageSpeed/Create/skeleton.jsx diff --git a/client/src/Routes/index.jsx b/client/src/Routes/index.jsx index 965ed2676..3db8b772d 100644 --- a/client/src/Routes/index.jsx +++ b/client/src/Routes/index.jsx @@ -18,9 +18,8 @@ import UptimeConfigure from "../Pages/Uptime/Configure"; // PageSpeed import PageSpeed from "../Pages/PageSpeed/Monitors"; -import PageSpeedCreate from "../Pages/PageSpeed/Create"; import PageSpeedDetails from "../Pages/PageSpeed/Details"; -import PageSpeedConfigure from "../Pages/PageSpeed/Configure"; +import PageSpeedCreate from "../Pages/PageSpeed/Create"; // Infrastructure import Infrastructure from "../Pages/Infrastructure/Monitors"; @@ -107,7 +106,7 @@ const Routes = () => { /> } + element={} />