Merge branch 'develop' of https://github.com/bluewave-labs/bluewave-uptime into develop
This commit is contained in:
commit
a7a4542a11
1 file changed
+35
-1
@@ -3,6 +3,7 @@ import { useSelector, useDispatch } from "react-redux";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
|
import { logger } from "../../../Utils/Logger";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
IconButton,
|
IconButton,
|
||||||
@@ -14,6 +15,7 @@ import {
|
|||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {
|
import {
|
||||||
deleteUptimeMonitor,
|
deleteUptimeMonitor,
|
||||||
|
pauseUptimeMonitor,
|
||||||
getUptimeMonitorsByTeamId,
|
getUptimeMonitorsByTeamId,
|
||||||
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import Settings from "../../../assets/icons/settings-bold.svg?react";
|
import Settings from "../../../assets/icons/settings-bold.svg?react";
|
||||||
@@ -26,6 +28,8 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
|
const authToken = authState.authToken;
|
||||||
|
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -44,6 +48,24 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handlePause = async () => {
|
||||||
|
try {
|
||||||
|
const action = await dispatch(
|
||||||
|
pauseUptimeMonitor({ authToken, monitorId: monitor._id })
|
||||||
|
);
|
||||||
|
if (pauseUptimeMonitor.fulfilled.match(action)) {
|
||||||
|
updateCallback();
|
||||||
|
const state = action?.payload?.data.isActive === false ? "paused" : "resumed";
|
||||||
|
createToast({ body: `Monitor ${state} successfully.` });
|
||||||
|
} else {
|
||||||
|
throw new Error(action?.error?.message ?? "Failed to pause monitor.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error pausing monitor:", monitor._id, error);
|
||||||
|
createToast({ body: "Failed to pause monitor." });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const openMenu = (event, id, url) => {
|
const openMenu = (event, id, url) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -155,6 +177,17 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
Clone
|
Clone
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
|
{isAdmin && (
|
||||||
|
<MenuItem
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
handlePause(e);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{monitor?.isActive === true ? "Pause" : "Resume"}
|
||||||
|
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
{isAdmin && (
|
{isAdmin && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
@@ -164,7 +197,7 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
>
|
>
|
||||||
Remove
|
Remove
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
<Modal
|
<Modal
|
||||||
aria-labelledby="modal-delete-monitor"
|
aria-labelledby="modal-delete-monitor"
|
||||||
@@ -238,6 +271,7 @@ ActionsMenu.propTypes = {
|
|||||||
_id: PropTypes.string,
|
_id: PropTypes.string,
|
||||||
url: PropTypes.string,
|
url: PropTypes.string,
|
||||||
type: PropTypes.string,
|
type: PropTypes.string,
|
||||||
|
isActive: PropTypes.bool,
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
isAdmin: PropTypes.bool,
|
isAdmin: PropTypes.bool,
|
||||||
updateCallback: PropTypes.func,
|
updateCallback: PropTypes.func,
|
||||||
|
|||||||
Reference in new issue
Block a user