From a9584405503317c3d6b4b636a2277f5172bf74c0 Mon Sep 17 00:00:00 2001 From: Shemy Gan Date: Fri, 11 Oct 2024 14:28:09 -0400 Subject: [PATCH] - Add Dialog component - Create delete all monitors and clear all stats windows using dialog component --- Client/src/Components/Dialog/index.jsx | 80 ++++++++++++++++++++++++++ Client/src/Pages/Settings/index.jsx | 44 ++++++++++++-- 2 files changed, 118 insertions(+), 6 deletions(-) create mode 100644 Client/src/Components/Dialog/index.jsx diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx new file mode 100644 index 000000000..a4b3e282d --- /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 = ({ arialabelledby, ariadescribedby, + open, onClose, bdy1, yBtnLbl, yBtnOnClick, nBtnLbl, nBtnOnClick, theme, isLoading, bdy2 }) => { + return + + + {bdy1} + + {bdy2 && + {bdy2} + } + + + + {yBtnLbl} + + + + +} + +Dialog.prototypes = { + arialabelledby: PropTypes.string.isRequired, + ariadescribedby: 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, + theme: PropTypes.object.isRequired, + isLoading: PropTypes.bool.isRequired, + bdy2: PropTypes.string +} + +export default Dialog \ No newline at end of file diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index 9aba1c792..cb2e3e6d1 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; @@ -37,6 +38,7 @@ const Settings = ({ isAdmin }) => { ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0, }); const [errors, setErrors] = useState({}); + const [isOpen, setIsOpen] = useState({delMntrs: false, delSts: false}); const dispatch = useDispatch(); const navigate = useNavigate(); @@ -118,6 +120,8 @@ const Settings = ({ isAdmin }) => { } catch (error) { logger.error(error); createToast({ body: "Failed to clear stats" }); + } finally { + setIsOpen({delMntrs: false, delSts:false}) } }; @@ -146,6 +150,8 @@ const Settings = ({ isAdmin }) => { } catch (error) { logger.error(error); createToast({ Body: "Failed to delete all monitors" }); + } finally { + setIsOpen({ delMntrs: false, delSts: false }) } }; @@ -202,17 +208,30 @@ const Settings = ({ isAdmin }) => { /> Clear all stats. This is irreversible. - setIsOpen({delSts: true, delMntrs: false})} sx={{ mt: theme.spacing(4) }} > Clear all stats - + + 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 })} + theme={theme} + isLoading={isLoading || authIsLoading || checksIsLoading} + > + )} {isAdmin && ( @@ -242,13 +261,26 @@ const Settings = ({ isAdmin }) => { variant="contained" color="error" loading={isLoading || authIsLoading || checksIsLoading} - onClick={handleDeleteAllMonitors} + onClick={()=>setIsOpen({delMntrs: true, delSts: false})} sx={{ mt: theme.spacing(4) }} > Remove all monitors + 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})} + theme={theme} + > + )} {isAdmin && (