diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx index a4b3e282d..0e3bdad54 100644 --- a/Client/src/Components/Dialog/index.jsx +++ b/Client/src/Components/Dialog/index.jsx @@ -1,11 +1,11 @@ import LoadingButton from "@mui/lab/LoadingButton"; import { Button, Modal, Stack, Typography } from "@mui/material"; import PropTypes from "prop-types"; -const Dialog = ({ arialabelledby, ariadescribedby, - open, onClose, bdy1, yBtnLbl, yBtnOnClick, nBtnLbl, nBtnOnClick, theme, isLoading, bdy2 }) => { +const Dialog = ({ modelTitle, modelDescription, + open, onClose, title, confirmationBtnLbl, confirmationBtnOnClick, cancelBtnLbl, cancelBtnOnClick, theme, isLoading, description }) => { return - - {bdy1} + {title} - {bdy2 && - {bdy2} + {description && + {description} } - {nBtnLbl} + {cancelBtnLbl} - {yBtnLbl} + {confirmationBtnLbl} } -Dialog.prototypes = { - arialabelledby: PropTypes.string.isRequired, - ariadescribedby: PropTypes.string.isRequired, +Dialog.PropTypes = { + modelTitle: PropTypes.string.isRequired, + modelDescription: PropTypes.string.isRequired, open: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, - bdy1: PropTypes.string.isRequired, - nBtnLbl: PropTypes.string.isRequired, - nBtnOnClick: PropTypes.func.isRequired, - yBtnLbl: PropTypes.string.isRequired, - yBtnOnClick: 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, - bdy2: PropTypes.string + 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 bf7465349..67bca8db0 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -39,7 +39,8 @@ const Settings = ({ isAdmin }) => { ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0, }); const [errors, setErrors] = useState({}); - const [isOpen, setIsOpen] = useState({delMntrs: false, delSts: false}); + const delStatMntrInitState = { delMntrs: false, delSts: false }; + const [isOpen, setIsOpen] = useState(delStatMntrInitState); const dispatch = useDispatch(); const navigate = useNavigate(); @@ -122,7 +123,7 @@ const Settings = ({ isAdmin }) => { logger.error(error); createToast({ body: "Failed to clear stats" }); } finally { - setIsOpen({delMntrs: false, delSts:false}) + setIsOpen(delStatMntrInitState) } }; @@ -152,10 +153,10 @@ const Settings = ({ isAdmin }) => { logger.error(error); createToast({ Body: "Failed to delete all monitors" }); } finally { - setIsOpen({ delMntrs: false, delSts: false }) + setIsOpen(delStatMntrInitState) } }; - + return ( { setIsOpen({ delSts: false, delMntrs: false })} - bdy1="Do you want to clear all stats?" - yBtnLbl="Yes, clear all stats" - yBtnOnClick={handleClearStats} - nBtnLbl="Cancel" - nBtnOnClick={() => setIsOpen({ delSts: false, delMntrs: false })} + onClose={() => setIsOpen(delStatMntrInitState)} + title="Do you want to clear all stats?" + confirmationBtnLbl="Yes, clear all stats" + confirmationBtnOnClick={handleClearStats} + cancelBtnLbl="Cancel" + cancelBtnOnClick={() => setIsOpen(delStatMntrInitState)} theme={theme} isLoading={isLoading || authIsLoading || checksIsLoading} > @@ -290,15 +291,15 @@ const Settings = ({ isAdmin }) => { setIsOpen({delMntrs:false, delSts: false})} - bdy1="Do you want to remove all monitors?" - yBtnLbl="Yes, clear all monitors" - yBtnOnClick={handleDeleteAllMonitors} - nBtnLbl="Cancel" - nBtnOnClick={() => setIsOpen({delMntrs:false, delSts: false})} + onClose={() => setIsOpen(delStatMntrInitState)} + title="Do you want to remove all monitors?" + confirmationBtnLbl="Yes, clear all monitors" + confirmationBtnOnClick={handleDeleteAllMonitors} + cancelBtnLbl="Cancel" + cancelBtnOnClick={() => setIsOpen(delStatMntrInitState)} theme={theme} isLoading={isLoading || authIsLoading || checksIsLoading} >