diff --git a/Client/src/Pages/Monitors/index.jsx b/Client/src/Pages/Monitors/index.jsx
index b80e88f5a..1b541c72b 100644
--- a/Client/src/Pages/Monitors/index.jsx
+++ b/Client/src/Pages/Monitors/index.jsx
@@ -11,7 +11,6 @@ import ServerStatus from "../../Components/Charts/Servers/ServerStatus";
import { useTheme } from "@emotion/react";
import ArrowDownwardRoundedIcon from "@mui/icons-material/ArrowDownwardRounded";
import OpenInNewPage from "../../assets/icons/open-in-new-page.svg?react";
-import Settings from "../../assets/icons/settings-bold.svg?react";
import BasicTable from "../../Components/BasicTable";
import { StatusLabel } from "../../Components/Label";
import { createToast } from "../../Utils/toastUtils";
@@ -27,6 +26,181 @@ import {
Typography,
} from "@mui/material";
+import Settings from "../../assets/icons/settings-bold.svg?react";
+import PropTypes from "prop-types";
+
+const ActionsMenu = ({ monitor }) => {
+ const [anchorEl, setAnchorEl] = useState(null);
+ const [actions, setActions] = useState({});
+ const [isOpen, setIsOpen] = useState(false);
+ const dispatch = useDispatch();
+ const theme = useTheme();
+ const authState = useSelector((state) => state.auth);
+
+ const handleRemove = async (event) => {
+ event.preventDefault();
+ event.stopPropagation();
+ let monitor = { _id: actions.id };
+ const action = await dispatch(
+ deleteUptimeMonitor({ authToken: authState.authToken, monitor })
+ );
+ if (action.meta.requestStatus === "fulfilled") {
+ setIsOpen(false); // close modal
+ dispatch(getUptimeMonitorsByUserId(authState.authToken));
+ createToast({ body: "Monitor deleted successfully." });
+ } else {
+ createToast({ body: "Failed to delete monitor." });
+ }
+ };
+
+ const openMenu = (event, id, url) => {
+ event.preventDefault();
+ event.stopPropagation();
+ setAnchorEl(event.currentTarget);
+ setActions({ id: id, url: url });
+ };
+
+ const openRemove = (e) => {
+ closeMenu(e);
+ setIsOpen(true);
+ };
+
+ const closeMenu = (e) => {
+ e.stopPropagation();
+ setAnchorEl(null);
+ };
+
+ const navigate = useNavigate();
+ return (
+ <>
+ {
+ event.stopPropagation();
+ openMenu(
+ event,
+ monitor._id,
+ monitor.type === "ping" ? null : monitor.url
+ );
+ }}
+ sx={{
+ "&:focus": {
+ outline: "none",
+ },
+ }}
+ >
+
+
+
+
+ setIsOpen(false)}
+ disablePortal
+ >
+
+
+ Do you really want to delete this monitor?
+
+
+ Once deleted, this monitor cannot be retrieved.
+
+
+
+
+
+ >
+ );
+};
+
+ActionsMenu.propTypes = {
+ monitor: PropTypes.shape({
+ _id: PropTypes.string,
+ url: PropTypes.string,
+ type: PropTypes.string,
+ }).isRequired,
+};
+
/**
* Host component.
* This subcomponent receives a params object and displays the host details.
@@ -72,6 +246,15 @@ const Host = ({ params }) => {
);
};
+Host.propTypes = {
+ params: PropTypes.shape({
+ url: PropTypes.string,
+ title: PropTypes.string,
+ percentageColor: PropTypes.string,
+ percentage: PropTypes.number,
+ }).isRequired,
+};
+
/**
* Renders a skeleton layout.
*
@@ -111,37 +294,6 @@ const Monitors = () => {
const authState = useSelector((state) => state.auth);
const dispatch = useDispatch({});
- const [anchorEl, setAnchorEl] = useState(null);
- const [actions, setActions] = useState({});
- const openMenu = (event, id, url) => {
- event.preventDefault();
- setAnchorEl(event.currentTarget);
- setActions({ id: id, url: url });
- };
- const closeMenu = () => {
- setAnchorEl(null);
- };
-
- const [isOpen, setIsOpen] = useState(false);
- const openRemove = () => {
- closeMenu();
- setIsOpen(true);
- };
- const handleRemove = async (event) => {
- event.preventDefault();
- let monitor = { _id: actions.id };
- const action = await dispatch(
- deleteUptimeMonitor({ authToken: authState.authToken, monitor })
- );
- if (action.meta.requestStatus === "fulfilled") {
- setIsOpen(false); // close modal
- dispatch(getUptimeMonitorsByUserId(authState.authToken));
- createToast({ body: "Monitor deleted successfully." });
- } else {
- createToast({ body: "Failed to delete monitor." });
- }
- };
-
useEffect(() => {
dispatch(getUptimeMonitorsByUserId(authState.authToken));
}, [authState.authToken, dispatch]);
@@ -191,7 +343,9 @@ const Monitors = () => {
return {
id: monitor._id,
// disabled for now
- handleClick: () => navigate(`/monitors/${monitor._id}`),
+ handleClick: () => {
+ navigate(`/monitors/${monitor._id}`);
+ },
data: [
{ id: idx, data: },
{
@@ -213,28 +367,7 @@ const Monitors = () => {
},
{
id: idx + 4,
- data: (
- <>
- {
- event.stopPropagation();
- openMenu(
- event,
- monitor._id,
- monitor.type === "ping" ? null : monitor.url
- );
- }}
- sx={{
- "&:focus": {
- outline: "none",
- },
- }}
- >
-
-
- >
- ),
+ data: ,
},
],
};
@@ -327,79 +460,6 @@ const Monitors = () => {
)}
>
)}
-
- setIsOpen(false)}
- disablePortal
- >
-
-
- Do you really want to delete this monitor?
-
-
- Once deleted, this monitor cannot be retrieved.
-
-
- setIsOpen(false)}
- />
-
-
-
-
);
};