- Update based on review feedbacks
This commit is contained in:
1 parent
fef74266c8
commit
21caca1ffb
4 files changed
+71
-170
No files matched your search
@@ -1,11 +1,11 @@
|
|||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import { Button, Modal, Stack, Typography } from "@mui/material";
|
import { Button, Modal, Stack, Typography } from "@mui/material";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
const Dialog = ({ arialabelledby, ariadescribedby,
|
const Dialog = ({ modelTitle, modelDescription,
|
||||||
open, onClose, bdy1, yBtnLbl, yBtnOnClick, nBtnLbl, nBtnOnClick, theme, isLoading, bdy2 }) => {
|
open, onClose, title, confirmationBtnLbl, confirmationBtnOnClick, cancelBtnLbl, cancelBtnOnClick, theme, isLoading, description }) => {
|
||||||
return <Modal
|
return <Modal
|
||||||
aria-labelledby={arialabelledby}
|
aria-labelledby={modelTitle}
|
||||||
aria-describedby={ariadescribedby}
|
aria-describedby={modelDescription}
|
||||||
open={open}
|
open={open}
|
||||||
onClose={onClose} >
|
onClose={onClose} >
|
||||||
<Stack
|
<Stack
|
||||||
@@ -27,14 +27,14 @@ const Dialog = ({ arialabelledby, ariadescribedby,
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography id={arialabelledby} component="h2"
|
<Typography id={modelTitle} component="h2"
|
||||||
fontSize={16}
|
fontSize={16}
|
||||||
color={theme.palette.text.primary}
|
color={theme.palette.text.primary}
|
||||||
fontWeight={600}>
|
fontWeight={600}>
|
||||||
{bdy1}
|
{title}
|
||||||
</Typography>
|
</Typography>
|
||||||
{bdy2 && <Typography id={ariadescribedby} color={theme.palette.text.tertiary}>
|
{description && <Typography id={modelDescription} color={theme.palette.text.tertiary}>
|
||||||
{bdy2}
|
{description}
|
||||||
</Typography>}
|
</Typography>}
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -45,36 +45,36 @@ const Dialog = ({ arialabelledby, ariadescribedby,
|
|||||||
<Button
|
<Button
|
||||||
variant="text"
|
variant="text"
|
||||||
color="info"
|
color="info"
|
||||||
onClick={nBtnOnClick}
|
onClick={cancelBtnOnClick}
|
||||||
>
|
>
|
||||||
{nBtnLbl}
|
{cancelBtnLbl}
|
||||||
</Button>
|
</Button>
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="error"
|
color="error"
|
||||||
loading= {isLoading}
|
loading= {isLoading}
|
||||||
onClick={yBtnOnClick}
|
onClick={confirmationBtnOnClick}
|
||||||
>
|
>
|
||||||
{yBtnLbl}
|
{confirmationBtnLbl}
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Modal>
|
</Modal>
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog.prototypes = {
|
Dialog.PropTypes = {
|
||||||
arialabelledby: PropTypes.string.isRequired,
|
modelTitle: PropTypes.string.isRequired,
|
||||||
ariadescribedby: PropTypes.string.isRequired,
|
modelDescription: PropTypes.string.isRequired,
|
||||||
open: PropTypes.bool.isRequired,
|
open: PropTypes.bool.isRequired,
|
||||||
onClose: PropTypes.func.isRequired,
|
onClose: PropTypes.func.isRequired,
|
||||||
bdy1: PropTypes.string.isRequired,
|
title: PropTypes.string.isRequired,
|
||||||
nBtnLbl: PropTypes.string.isRequired,
|
confirmationBtnLbl: PropTypes.string.isRequired,
|
||||||
nBtnOnClick: PropTypes.func.isRequired,
|
confirmationBtnOnClick: PropTypes.func.isRequired,
|
||||||
yBtnLbl: PropTypes.string.isRequired,
|
cancelBtnLbl: PropTypes.string.isRequired,
|
||||||
yBtnOnClick: PropTypes.func.isRequired,
|
cancelBtnOnClick: PropTypes.func.isRequired,
|
||||||
theme: PropTypes.object.isRequired,
|
theme: PropTypes.object.isRequired,
|
||||||
isLoading: PropTypes.bool.isRequired,
|
isLoading: PropTypes.bool.isRequired,
|
||||||
bdy2: PropTypes.string
|
description: PropTypes.string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Dialog
|
export default Dialog
|
||||||
@@ -2,7 +2,7 @@ import { useNavigate, useParams } from "react-router";
|
|||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { useEffect, useState } from "react";
|
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 { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
@@ -24,6 +24,7 @@ import PulseDot from "../../../Components/Animated/PulseDot";
|
|||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import LoadingButton from "@mui/lab/LoadingButton";
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
import Dialog from "../../../Components/Dialog";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a URL string and returns a URL object.
|
* Parses a URL string and returns a URL object.
|
||||||
@@ -447,71 +448,21 @@ const Configure = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<Modal
|
<Dialog
|
||||||
aria-labelledby="modal-delete-monitor"
|
modelTitle="modal-delete-monitor"
|
||||||
aria-describedby="delete-monitor-confirmation"
|
modelDescription="delete-monitor-confirmation"
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onClose={() => setIsOpen(false)}
|
onClose={() => 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."
|
||||||
>
|
>
|
||||||
<Stack
|
</Dialog>
|
||||||
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="modal-delete-monitor"
|
|
||||||
component="h2"
|
|
||||||
fontSize={16}
|
|
||||||
color={theme.palette.text.primary}
|
|
||||||
fontWeight={600}
|
|
||||||
>
|
|
||||||
Do you really want to delete this monitor?
|
|
||||||
</Typography>
|
|
||||||
<Typography
|
|
||||||
id="delete-monitor-confirmation"
|
|
||||||
color={theme.palette.text.tertiary}
|
|
||||||
>
|
|
||||||
Once deleted, this monitor cannot be retrieved.
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
mt={theme.spacing(12)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={() => setIsOpen(false)}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<LoadingButton
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
loading={isLoading}
|
|
||||||
onClick={handleRemove}
|
|
||||||
>
|
|
||||||
Delete
|
|
||||||
</LoadingButton>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</Modal>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,13 +5,9 @@ import { useNavigate } from "react-router-dom";
|
|||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
import {
|
import {
|
||||||
Button,
|
|
||||||
IconButton,
|
IconButton,
|
||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem
|
||||||
Modal,
|
|
||||||
Stack,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import {
|
import {
|
||||||
deleteUptimeMonitor,
|
deleteUptimeMonitor,
|
||||||
@@ -20,6 +16,7 @@ import {
|
|||||||
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
} from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import Settings from "../../../assets/icons/settings-bold.svg?react";
|
import Settings from "../../../assets/icons/settings-bold.svg?react";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
|
import Dialog from "../../../Components/Dialog"
|
||||||
|
|
||||||
const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
||||||
const [anchorEl, setAnchorEl] = useState(null);
|
const [anchorEl, setAnchorEl] = useState(null);
|
||||||
@@ -29,7 +26,7 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const authState = useSelector((state) => state.auth);
|
const authState = useSelector((state) => state.auth);
|
||||||
const authToken = authState.authToken;
|
const authToken = authState.authToken;
|
||||||
|
const { isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
|
|
||||||
const handleRemove = async (event) => {
|
const handleRemove = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -199,69 +196,21 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
)}
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
<Modal
|
<Dialog
|
||||||
aria-labelledby="modal-delete-monitor"
|
modelTitle="modal-delete-monitor"
|
||||||
aria-describedby="delete-monitor-confirmation"
|
modelDescription="delete-monitor-confirmation"
|
||||||
open={isOpen}
|
open={isOpen}
|
||||||
onClose={(e) => {
|
onClose={() => setIsOpen(false)}
|
||||||
e.stopPropagation();
|
title="Do you really want to delete this monitor?"
|
||||||
setIsOpen(false);
|
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."
|
||||||
>
|
>
|
||||||
<Stack
|
</Dialog>
|
||||||
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="modal-delete-monitor" component="h2" variant="h2">
|
|
||||||
Do you really want to delete this monitor?
|
|
||||||
</Typography>
|
|
||||||
<Typography id="delete-monitor-confirmation" variant="body1">
|
|
||||||
Once deleted, this monitor cannot be retrieved.
|
|
||||||
</Typography>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
gap={theme.spacing(4)}
|
|
||||||
mt={theme.spacing(12)}
|
|
||||||
justifyContent="flex-end"
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
variant="text"
|
|
||||||
color="info"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setIsOpen(false);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="error"
|
|
||||||
onClick={(e) => {
|
|
||||||
e.stopPropagation(e);
|
|
||||||
handleRemove(e);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Delete
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Stack>
|
|
||||||
</Modal>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ const Settings = ({ isAdmin }) => {
|
|||||||
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
|
ttl: checkTTL ? (checkTTL / SECONDS_PER_DAY).toString() : 0,
|
||||||
});
|
});
|
||||||
const [errors, setErrors] = useState({});
|
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 dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ const Settings = ({ isAdmin }) => {
|
|||||||
logger.error(error);
|
logger.error(error);
|
||||||
createToast({ body: "Failed to clear stats" });
|
createToast({ body: "Failed to clear stats" });
|
||||||
} finally {
|
} finally {
|
||||||
setIsOpen({delMntrs: false, delSts:false})
|
setIsOpen(delStatMntrInitState)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ const Settings = ({ isAdmin }) => {
|
|||||||
logger.error(error);
|
logger.error(error);
|
||||||
createToast({ Body: "Failed to delete all monitors" });
|
createToast({ Body: "Failed to delete all monitors" });
|
||||||
} finally {
|
} finally {
|
||||||
setIsOpen({ delMntrs: false, delSts: false })
|
setIsOpen(delStatMntrInitState)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -240,15 +241,15 @@ const Settings = ({ isAdmin }) => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Dialog
|
<Dialog
|
||||||
arialabelledby="model-clear-stats"
|
modelTitle="model-clear-stats"
|
||||||
ariadescribedby="clear-stats-confirmation"
|
modelDescription="clear-stats-confirmation"
|
||||||
open={isOpen.delSts}
|
open={isOpen.delSts}
|
||||||
onClose={() => setIsOpen({ delSts: false, delMntrs: false })}
|
onClose={() => setIsOpen(delStatMntrInitState)}
|
||||||
bdy1="Do you want to clear all stats?"
|
title="Do you want to clear all stats?"
|
||||||
yBtnLbl="Yes, clear all stats"
|
confirmationBtnLbl="Yes, clear all stats"
|
||||||
yBtnOnClick={handleClearStats}
|
confirmationBtnOnClick={handleClearStats}
|
||||||
nBtnLbl="Cancel"
|
cancelBtnLbl="Cancel"
|
||||||
nBtnOnClick={() => setIsOpen({ delSts: false, delMntrs: false })}
|
cancelBtnOnClick={() => setIsOpen(delStatMntrInitState)}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
isLoading={isLoading || authIsLoading || checksIsLoading}
|
isLoading={isLoading || authIsLoading || checksIsLoading}
|
||||||
>
|
>
|
||||||
@@ -290,15 +291,15 @@ const Settings = ({ isAdmin }) => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Dialog
|
<Dialog
|
||||||
arialabelledby="model-delete-all-monitors"
|
modelTitle="model-delete-all-monitors"
|
||||||
ariadescribedby="delete-all-monitors-confirmation"
|
modelDescription="delete-all-monitors-confirmation"
|
||||||
open={isOpen.delMntrs}
|
open={isOpen.delMntrs}
|
||||||
onClose={() => setIsOpen({delMntrs:false, delSts: false})}
|
onClose={() => setIsOpen(delStatMntrInitState)}
|
||||||
bdy1="Do you want to remove all monitors?"
|
title="Do you want to remove all monitors?"
|
||||||
yBtnLbl="Yes, clear all monitors"
|
confirmationBtnLbl="Yes, clear all monitors"
|
||||||
yBtnOnClick={handleDeleteAllMonitors}
|
confirmationBtnOnClick={handleDeleteAllMonitors}
|
||||||
nBtnLbl="Cancel"
|
cancelBtnLbl="Cancel"
|
||||||
nBtnOnClick={() => setIsOpen({delMntrs:false, delSts: false})}
|
cancelBtnOnClick={() => setIsOpen(delStatMntrInitState)}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
isLoading={isLoading || authIsLoading || checksIsLoading}
|
isLoading={isLoading || authIsLoading || checksIsLoading}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in new issue
Block a user