diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx
new file mode 100644
index 000000000..389d3a6e8
--- /dev/null
+++ b/Client/src/Components/Dialog/index.jsx
@@ -0,0 +1,80 @@
+import LoadingButton from "@mui/lab/LoadingButton";
+import { Button, Modal, Stack, Typography } from "@mui/material";
+import PropTypes from "prop-types";
+const Dialog = ({ modelTitle, modelDescription,
+ open, onClose, title, confirmationBtnLbl, confirmationBtnOnClick, cancelBtnLbl, cancelBtnOnClick, theme, isLoading, description }) => {
+ return
+
+
+ {title}
+
+ {description &&
+ {description}
+ }
+
+
+
+ {confirmationBtnLbl}
+
+
+
+
+}
+
+Dialog.propTypes = {
+ modelTitle: PropTypes.string.isRequired,
+ modelDescription: PropTypes.string.isRequired,
+ open: PropTypes.bool.isRequired,
+ onClose: PropTypes.func.isRequired,
+ title: PropTypes.string.isRequired,
+ confirmationBtnLbl: PropTypes.string.isRequired,
+ confirmationBtnOnClick: PropTypes.func.isRequired,
+ cancelBtnLbl: PropTypes.string.isRequired,
+ cancelBtnOnClick: PropTypes.func.isRequired,
+ theme: PropTypes.object.isRequired,
+ isLoading: PropTypes.bool.isRequired,
+ description: PropTypes.string
+}
+
+export default Dialog
\ No newline at end of file
diff --git a/Client/src/Pages/Monitors/Configure/index.jsx b/Client/src/Pages/Monitors/Configure/index.jsx
index cd55837a7..d10d6edc3 100644
--- a/Client/src/Pages/Monitors/Configure/index.jsx
+++ b/Client/src/Pages/Monitors/Configure/index.jsx
@@ -2,7 +2,7 @@ import { useNavigate, useParams } from "react-router";
import { useTheme } from "@emotion/react";
import { useDispatch, useSelector } from "react-redux";
import { useEffect, useState } from "react";
-import { Box, Button, Modal, Stack, Tooltip, Typography } from "@mui/material";
+import { Box, Stack, Tooltip, Typography } from "@mui/material";
import { monitorValidation } from "../../../Validation/validation";
import { createToast } from "../../../Utils/toastUtils";
import { logger } from "../../../Utils/Logger";
@@ -24,6 +24,7 @@ import PulseDot from "../../../Components/Animated/PulseDot";
import SkeletonLayout from "./skeleton";
import LoadingButton from "@mui/lab/LoadingButton";
import "./index.css";
+import Dialog from "../../../Components/Dialog";
/**
* Parses a URL string and returns a URL object.
@@ -447,71 +448,21 @@ const Configure = () => {
>
)}
- setIsOpen(false)}
- disablePortal
+ title="Do you really want to delete this monitor?"
+ confirmationBtnLbl="Delete"
+ confirmationBtnOnClick={handleRemove}
+ cancelBtnLbl="Cancel"
+ cancelBtnOnClick={() => setIsOpen(false)}
+ theme={theme}
+ isLoading={isLoading}
+ description="Once deleted, this monitor cannot be retrieved."
>
-
-
- Do you really want to delete this monitor?
-
-
- Once deleted, this monitor cannot be retrieved.
-
-
-
-
- Delete
-
-
-
-
+
);
};
diff --git a/Client/src/Pages/Monitors/Home/actionsMenu.jsx b/Client/src/Pages/Monitors/Home/actionsMenu.jsx
index d2ccc0b88..fabb74a1b 100644
--- a/Client/src/Pages/Monitors/Home/actionsMenu.jsx
+++ b/Client/src/Pages/Monitors/Home/actionsMenu.jsx
@@ -5,13 +5,9 @@ import { useNavigate } from "react-router-dom";
import { createToast } from "../../../Utils/toastUtils";
import { logger } from "../../../Utils/Logger";
import {
- Button,
IconButton,
Menu,
- MenuItem,
- Modal,
- Stack,
- Typography,
+ MenuItem
} from "@mui/material";
import {
deleteUptimeMonitor,
@@ -20,6 +16,7 @@ import {
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
import Settings from "../../../assets/icons/settings-bold.svg?react";
import PropTypes from "prop-types";
+import Dialog from "../../../Components/Dialog"
const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
const [anchorEl, setAnchorEl] = useState(null);
@@ -29,7 +26,7 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
const theme = useTheme();
const authState = useSelector((state) => state.auth);
const authToken = authState.authToken;
-
+ const { isLoading } = useSelector((state) => state.uptimeMonitors);
const handleRemove = async (event) => {
event.preventDefault();
@@ -199,69 +196,21 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
)}
- {
- e.stopPropagation();
- setIsOpen(false);
- }}
+ onClose={() => setIsOpen(false)}
+ title="Do you really want to delete this monitor?"
+ confirmationBtnLbl="Delete"
+ confirmationBtnOnClick={e => { e.stopPropagation(); handleRemove(e) }}
+ cancelBtnLbl="Cancel"
+ cancelBtnOnClick={e => { e.stopPropagation(); setIsOpen(false) }}
+ theme={theme}
+ isLoading={isLoading}
+ description="Once deleted, this monitor cannot be retrieved."
>
-
-
- Do you really want to delete this monitor?
-
-
- Once deleted, this monitor cannot be retrieved.
-
-
-
-
-
-
-
+
>
);
};
diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx
index 5ba4d676a..10f34fa23 100644
--- a/Client/src/Pages/Settings/index.jsx
+++ b/Client/src/Pages/Settings/index.jsx
@@ -22,6 +22,7 @@ import { ConfigBox } from "./styled";
import { networkService } from "../../main";
import { settingsValidation } from "../../Validation/validation";
import { useNavigate } from "react-router";
+import Dialog from "../../Components/Dialog"
const SECONDS_PER_DAY = 86400;
@@ -39,6 +40,8 @@ const Settings = ({ isAdmin }) => {
});
const [version,setVersion]=useState("unknown");
const [errors, setErrors] = useState({});
+ const deleteStatsMonitorsInitState = { deleteMonitors: false, deleteStats: false };
+ const [isOpen, setIsOpen] = useState(deleteStatsMonitorsInitState);
const dispatch = useDispatch();
const navigate = useNavigate();
@@ -139,6 +142,8 @@ const Settings = ({ isAdmin }) => {
} catch (error) {
logger.error(error);
createToast({ body: "Failed to clear stats" });
+ } finally {
+ setIsOpen(deleteStatsMonitorsInitState)
}
};
@@ -167,9 +172,11 @@ const Settings = ({ isAdmin }) => {
} catch (error) {
logger.error(error);
createToast({ Body: "Failed to delete all monitors" });
+ } finally {
+ setIsOpen(deleteStatsMonitorsInitState)
}
};
-
+
return (
{
/>
Clear all stats. This is irreversible.
- setIsOpen({...deleteStatsMonitorsInitState, deleteStats: true})}
sx={{ mt: theme.spacing(4) }}
>
Clear all stats
-
+
+
)}
{isAdmin && (
@@ -283,13 +303,27 @@ const Settings = ({ isAdmin }) => {
variant="contained"
color="error"
loading={isLoading || authIsLoading || checksIsLoading}
- onClick={handleDeleteAllMonitors}
+ onClick={()=>setIsOpen({...deleteStatsMonitorsInitState, deleteMonitors: true})}
sx={{ mt: theme.spacing(4) }}
>
Remove all monitors
+
)}
{isAdmin && (