Added pause button in configuration page.
This commit is contained in:
1 parent
0be0c5bf3f
commit
dab2bb466f
1 file changed
+32
-4
@@ -34,6 +34,9 @@ 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 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";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a URL string and returns a URL object.
|
* Parses a URL string and returns a URL object.
|
||||||
@@ -83,13 +86,22 @@ const Configure = () => {
|
|||||||
include: "ok",
|
include: "ok",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [trigger, setTrigger] = useState(false);
|
||||||
|
const triggerUpdate = () => {
|
||||||
|
setTrigger(!trigger);
|
||||||
|
};
|
||||||
|
const [pauseMonitor, isPausing, error] = usePauseMonitor({
|
||||||
|
monitorId: monitor?._id,
|
||||||
|
triggerUpdate,
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
try {
|
try {
|
||||||
const action = await dispatch(getUptimeMonitorById({ monitorId }));
|
const action = await dispatch(getUptimeMonitorById({ monitorId }));
|
||||||
|
|
||||||
if (getUptimeMonitorById.fulfilled.match(action)) {
|
if (getUptimeMonitorById.fulfilled.match(action)) {
|
||||||
const monitor = action.payload.data;
|
const monitor = action.payload.data;
|
||||||
|
console.log("Monitor fetched: ", monitor);
|
||||||
setMonitor(monitor);
|
setMonitor(monitor);
|
||||||
} else if (getUptimeMonitorById.rejected.match(action)) {
|
} else if (getUptimeMonitorById.rejected.match(action)) {
|
||||||
throw new Error(action.error.message);
|
throw new Error(action.error.message);
|
||||||
@@ -100,7 +112,7 @@ const Configure = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
}, [monitorId, navigate]);
|
}, [monitorId, navigate, trigger]);
|
||||||
|
|
||||||
const handleChange = (event, name) => {
|
const handleChange = (event, name) => {
|
||||||
let { checked, value, id } = event.target;
|
let { checked, value, id } = event.target;
|
||||||
@@ -257,7 +269,7 @@ const Configure = () => {
|
|||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
title={statusMsg[monitor?.status ?? undefined]}
|
title={statusMsg[monitor?.isActive ?? undefined]}
|
||||||
disableInteractive
|
disableInteractive
|
||||||
slotProps={{
|
slotProps={{
|
||||||
popper: {
|
popper: {
|
||||||
@@ -273,7 +285,7 @@ const Configure = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
<PulseDot color={statusColor[monitor?.status ?? undefined]} />
|
<PulseDot color={statusColor[monitor?.isActive ?? undefined]} />
|
||||||
</Box>
|
</Box>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Typography
|
<Typography
|
||||||
@@ -307,11 +319,27 @@ const Configure = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
|
justifyContent="space-between"
|
||||||
sx={{
|
sx={{
|
||||||
alignSelf: "flex-end",
|
alignSelf: "flex-end",
|
||||||
ml: "auto",
|
ml: "auto",
|
||||||
|
display: "flex",
|
||||||
|
gap: theme.spacing(2),
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
loading={isPausing}
|
||||||
|
startIcon={
|
||||||
|
monitor?.isActive ? <PauseOutlinedIcon /> : <PlayArrowOutlinedIcon />
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
pauseMonitor();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{monitor?.isActive ? "Pause" : "Resume"}
|
||||||
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
Reference in new issue
Block a user