diff --git a/client/src/Hooks/useMonitorUtils.js b/client/src/Hooks/useMonitorUtils.js index fc1966b69..f187f7250 100644 --- a/client/src/Hooks/useMonitorUtils.js +++ b/client/src/Hooks/useMonitorUtils.js @@ -1,6 +1,8 @@ import { useCallback } from "react"; +import { useTheme } from "@mui/material"; const useMonitorUtils = () => { + const getMonitorWithPercentage = useCallback((monitor, theme) => { let uptimePercentage = ""; let percentageColor = ""; @@ -36,7 +38,16 @@ const useMonitorUtils = () => { return monitor?.status == true ? "up" : "down"; }, []); - return { getMonitorWithPercentage, determineState }; + const theme = useTheme(); + + const statusColor = { + up: theme.palette.success.lowContrast, + down: theme.palette.error.lowContrast, + paused: theme.palette.warning.lowContrast, + pending: theme.palette.warning.lowContrast, + }; + + return { getMonitorWithPercentage, determineState, statusColor }; }; export { useMonitorUtils }; diff --git a/client/src/Pages/Uptime/Configure/index.jsx b/client/src/Pages/Uptime/Configure/index.jsx index c430d78df..745cd6fe8 100644 --- a/client/src/Pages/Uptime/Configure/index.jsx +++ b/client/src/Pages/Uptime/Configure/index.jsx @@ -34,6 +34,10 @@ import SkeletonLayout from "./skeleton"; import "./index.css"; import Dialog from "../../../Components/Dialog"; import NotificationIntegrationModal from "../../../Components/NotificationIntegrationModal/Components/NotificationIntegrationModal"; +import { usePauseMonitor } from "../../../Hooks/useMonitorControls"; +import PauseOutlinedIcon from "@mui/icons-material/PauseOutlined"; +import PlayArrowOutlinedIcon from "@mui/icons-material/PlayArrowOutlined"; +import { useMonitorUtils } from "../../../Hooks/useMonitorUtils"; /** * Parses a URL string and returns a URL object. @@ -83,11 +87,19 @@ const Configure = () => { include: "ok", }; + const [trigger, setTrigger] = useState(false); + const triggerUpdate = () => { + setTrigger(!trigger); + }; + const [pauseMonitor, isPausing, error] = usePauseMonitor({ + 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); @@ -100,7 +112,7 @@ const Configure = () => { } }; fetchMonitor(); - }, [monitorId, navigate]); + }, [monitorId, navigate, trigger]); const handleChange = (event, name) => { let { checked, value, id } = event.target; @@ -202,17 +214,7 @@ const Configure = () => { setIsNotificationModalOpen(false); }; - const statusColor = { - true: theme.palette.success.main, - false: theme.palette.error.main, - undefined: theme.palette.warning.main, - }; - - const statusMsg = { - true: "Your site is up.", - false: "Your site is down.", - undefined: "Pending...", - }; + const { determineState, statusColor } = useMonitorUtils(); const { t } = useTranslation(); @@ -257,7 +259,7 @@ const Configure = () => { gap={theme.spacing(2)} > { }} > - + { +