- Add Dialog component
- Create delete all monitors and clear all stats windows using dialog component
This commit is contained in:
1 parent
307856707a
commit
a958440550
2 files changed
+118
-6
No files matched your search
@@ -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 <Modal
|
||||
aria-labelledby={arialabelledby}
|
||||
aria-describedby={ariadescribedby}
|
||||
open={open}
|
||||
onClose={onClose} >
|
||||
<Stack
|
||||
gap={theme.spacing(2)}
|
||||
sx={{
|
||||
position: "absolute",
|
||||
top: "50%",
|
||||
left: "50%",
|
||||
transform: "translate(-50%, -50%)",
|
||||
width: 400,
|
||||
bgcolor: theme.palette.background.main,
|
||||
border: 1,
|
||||
borderColor: theme.palette.border.light,
|
||||
borderRadius: theme.shape.borderRadius,
|
||||
boxShadow: 24,
|
||||
p: theme.spacing(15),
|
||||
"&:focus": {
|
||||
outline: "none",
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Typography id={arialabelledby} component="h2"
|
||||
fontSize={16}
|
||||
color={theme.palette.text.primary}
|
||||
fontWeight={600}>
|
||||
{bdy1}
|
||||
</Typography>
|
||||
{bdy2 && <Typography id={ariadescribedby} color={theme.palette.text.tertiary}>
|
||||
{bdy2}
|
||||
</Typography>}
|
||||
<Stack
|
||||
direction="row"
|
||||
gap={theme.spacing(4)}
|
||||
mt={theme.spacing(12)}
|
||||
justifyContent="flex-end"
|
||||
>
|
||||
<Button
|
||||
variant="text"
|
||||
color="info"
|
||||
onClick={nBtnOnClick}
|
||||
>
|
||||
{nBtnLbl}
|
||||
</Button>
|
||||
<LoadingButton
|
||||
variant="contained"
|
||||
color="error"
|
||||
loading= {isLoading}
|
||||
onClick={yBtnOnClick}
|
||||
>
|
||||
{yBtnLbl}
|
||||
</LoadingButton>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Modal>
|
||||
}
|
||||
|
||||
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
|
||||
@@ -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 }) => {
|
||||
/>
|
||||
<Box>
|
||||
<Typography>Clear all stats. This is irreversible.</Typography>
|
||||
<LoadingButton
|
||||
<Button
|
||||
variant="contained"
|
||||
color="error"
|
||||
loading={isLoading || authIsLoading || checksIsLoading}
|
||||
onClick={handleClearStats}
|
||||
color="error"
|
||||
onClick={()=>setIsOpen({delSts: true, delMntrs: false})}
|
||||
sx={{ mt: theme.spacing(4) }}
|
||||
>
|
||||
Clear all stats
|
||||
</LoadingButton>
|
||||
</Button>
|
||||
</Box>
|
||||
</Stack>
|
||||
<Dialog
|
||||
arialabelledby="model-clear-stats"
|
||||
ariadescribedby="clear-stats-confirmation"
|
||||
open={isOpen.delSts}
|
||||
onClose={() => 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}
|
||||
>
|
||||
</Dialog>
|
||||
</ConfigBox>
|
||||
)}
|
||||
{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
|
||||
</LoadingButton>
|
||||
</Box>
|
||||
</Stack>
|
||||
<Dialog
|
||||
arialabelledby="model-delete-all-monitors"
|
||||
ariadescribedby="delete-all-monitors-confirmation"
|
||||
open={isOpen.delMntrs}
|
||||
onClose={() => 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}
|
||||
>
|
||||
</Dialog>
|
||||
</ConfigBox>
|
||||
)}
|
||||
{isAdmin && (
|
||||
|
||||
Reference in new issue
Block a user