Merge pull request #1018 from bluewave-labs/refactor/Dialog

Refactor/dialog
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-10-23 09:52:00 +08:00
commit 363c7bdde9
9 files changed
+299 -497

No files matched your search

@@ -0,0 +1,67 @@
import { useId } from "react";
import PropTypes from "prop-types";
import { Modal, Stack, Typography } from "@mui/material";
const GenericDialog = ({ title, description, open, onClose, theme, children }) => {
const titleId = useId();
const descriptionId = useId();
const ariaDescribedBy = description?.length > 0 ? descriptionId : "";
return (
<Modal
aria-labelledby={titleId}
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={titleId}
component="h2"
fontSize={16}
color={theme.palette.text.primary}
fontWeight={600}
>
{title}
</Typography>
{description && (
<Typography
id={descriptionId}
color={theme.palette.text.tertiary}
>
{description}
</Typography>
)}
{children}
</Stack>
</Modal>
);
};
GenericDialog.propTypes = {
title: PropTypes.string.isRequired,
description: PropTypes.string,
open: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
theme: PropTypes.object.isRequired,
children: PropTypes.element.isRequired,
};
export { GenericDialog };
+38 -79
View File
@@ -1,103 +1,62 @@
import LoadingButton from "@mui/lab/LoadingButton";
import { Button, Modal, Stack, Typography } from "@mui/material";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import LoadingButton from "@mui/lab/LoadingButton";
import { Button, Stack } from "@mui/material";
import { GenericDialog } from "./genericDialog";
const Dialog = ({ const Dialog = ({
modelTitle,
modelDescription,
open,
onClose,
title, title,
confirmationBtnLbl,
confirmationBtnOnClick,
cancelBtnLbl,
cancelBtnOnClick,
theme,
isLoading,
description, description,
open,
theme,
onCancel,
confirmationButtonLabel,
onConfirm,
isLoading,
}) => { }) => {
return ( return (
<Modal <GenericDialog
aria-labelledby={modelTitle} title={title}
aria-describedby={modelDescription} description={description}
open={open} open={open}
onClose={onClose} onClose={onCancel}
theme={theme}
> >
<Stack <Stack
gap={theme.spacing(2)} direction="row"
sx={{ gap={theme.spacing(4)}
position: "absolute", mt={theme.spacing(12)}
top: "50%", justifyContent="flex-end"
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 <Button
id={modelTitle} variant="text"
component="h2" color="info"
fontSize={16} onClick={onCancel}
color={theme.palette.text.primary}
fontWeight={600}
> >
{title} Cancel
</Typography> </Button>
{description && ( <LoadingButton
<Typography variant="contained"
id={modelDescription} color="error"
color={theme.palette.text.tertiary} loading={isLoading}
> onClick={onConfirm}
{description}
</Typography>
)}
<Stack
direction="row"
gap={theme.spacing(4)}
mt={theme.spacing(12)}
justifyContent="flex-end"
> >
<Button {confirmationButtonLabel}
variant="text" </LoadingButton>
color="info"
onClick={cancelBtnOnClick}
>
{cancelBtnLbl}
</Button>
<LoadingButton
variant="contained"
color="error"
loading={isLoading}
onClick={confirmationBtnOnClick}
>
{confirmationBtnLbl}
</LoadingButton>
</Stack>
</Stack> </Stack>
</Modal> </GenericDialog>
); );
}; };
Dialog.propTypes = { Dialog.propTypes = {
modelTitle: PropTypes.string.isRequired, title: PropTypes.string.isRequired,
modelDescription: PropTypes.string.isRequired, description: PropTypes.string,
open: PropTypes.bool.isRequired, open: PropTypes.bool.isRequired,
onClose: PropTypes.func.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, theme: PropTypes.object.isRequired,
onCancel: PropTypes.func.isRequired,
confirmationButtonLabel: PropTypes.string.isRequired,
onConfirm: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired,
description: PropTypes.string,
}; };
export default Dialog; export default Dialog;
@@ -1,7 +1,7 @@
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useRef, useState } from "react"; import { useRef, useState } from "react";
import TabPanel from "@mui/lab/TabPanel"; import TabPanel from "@mui/lab/TabPanel";
import { Box, Button, Divider, Modal, Stack, Typography } from "@mui/material"; import { Box, Button, Divider, Stack, Typography } from "@mui/material";
import Avatar from "../../Avatar"; import Avatar from "../../Avatar";
import Field from "../../Inputs/Field"; import Field from "../../Inputs/Field";
import ImageField from "../../Inputs/Image"; import ImageField from "../../Inputs/Image";
@@ -15,6 +15,8 @@ import { clearUptimeMonitorState } from "../../../Features/UptimeMonitors/uptime
import { createToast } from "../../../Utils/toastUtils"; import { createToast } from "../../../Utils/toastUtils";
import { logger } from "../../../Utils/Logger"; import { logger } from "../../../Utils/Logger";
import LoadingButton from "@mui/lab/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton";
import { GenericDialog } from "../../Dialog/genericDialog";
import Dialog from "../../Dialog";
/** /**
* ProfilePanel component displays a form for editing user profile information * ProfilePanel component displays a form for editing user profile information
@@ -369,158 +371,82 @@ const ProfilePanel = () => {
</Box> </Box>
)} )}
{/* TODO - Update ModalPopup Component with @mui for reusability */} {/* TODO - Update ModalPopup Component with @mui for reusability */}
<Modal
aria-labelledby="modal-delete-account" <Dialog
aria-describedby="delete-account-confirmation"
open={isModalOpen("delete")} open={isModalOpen("delete")}
onClose={() => setIsOpen("")} theme={theme}
disablePortal title={"Really delete this account?"}
> description={
<Stack "If you delete your account, you will no longer be able to sign in, and all of your data will be deleted. Deleting your account is permanent and non-recoverable action."
gap={theme.spacing(5)} }
sx={{ onCancel={() => setIsOpen("")}
position: "absolute", confirmationButtonLabel={"Delete account"}
top: "50%", onConfirm={handleDeleteAccount}
left: "50%", isLoading={isLoading}
transform: "translate(-50%, -50%)", />
width: 500,
bgcolor: theme.palette.background.main, <GenericDialog
border: 1, title={"Upload Image"}
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
boxShadow: 24,
p: theme.spacing(15),
"&:focus": {
outline: "none",
},
}}
>
<Typography
id="modal-delete-account"
component="h1"
>
Really delete this account?
</Typography>
<Typography
id="delete-account-confirmation"
component="p"
>
If you delete your account, you will no longer be able to sign in, and all of
your data will be deleted. Deleting your account is permanent and
non-recoverable action.
</Typography>
<Stack
direction="row"
gap={theme.spacing(5)}
mt={theme.spacing(5)}
justifyContent="flex-end"
>
<Button
variant="text"
color="info"
onClick={() => setIsOpen("")}
>
Cancel
</Button>
<LoadingButton
variant="contained"
color="error"
onClick={handleDeleteAccount}
loading={isLoading}
>
Delete account
</LoadingButton>
</Stack>
</Stack>
</Modal>
<Modal
aria-labelledby="modal-update-picture"
aria-describedby="update-profile-picture"
open={isModalOpen("picture")} open={isModalOpen("picture")}
onClose={closePictureModal} onClose={closePictureModal}
theme={theme}
> >
<Stack <ImageField
sx={{ id="update-profile-picture"
position: "absolute", src={
top: "50%", file?.delete
left: "50%", ? ""
transform: "translate(-50%, -50%)", : file?.src
width: 475, ? file.src
bgcolor: theme.palette.background.main, : localData?.file
border: 1, ? localData.file
borderColor: theme.palette.border.light, : user?.avatarImage
borderRadius: theme.shape.borderRadius, ? `data:image/png;base64,${user.avatarImage}`
boxShadow: theme.shape.boxShadow, : ""
p: theme.spacing(15), }
"&:focus": { loading={progress.isLoading && progress.value !== 100}
outline: "none", onChange={handlePicture}
}, />
}} {progress.isLoading || progress.value !== 0 || errors["picture"] ? (
> <ProgressUpload
<Typography icon={<ImageIcon />}
id="modal-update-picture" label={file?.name}
component="h1" size={file?.size}
color={theme.palette.text.secondary} progress={progress.value}
> onClick={removePicture}
Upload Image error={errors["picture"]}
</Typography>
<ImageField
id="update-profile-picture"
src={
file?.delete
? ""
: file?.src
? file.src
: localData?.file
? localData.file
: user?.avatarImage
? `data:image/png;base64,${user.avatarImage}`
: ""
}
loading={progress.isLoading && progress.value !== 100}
onChange={handlePicture}
/> />
{progress.isLoading || progress.value !== 0 || errors["picture"] ? ( ) : (
<ProgressUpload ""
icon={<ImageIcon />} )}
label={file?.name} <Stack
size={file?.size} direction="row"
progress={progress.value} mt={theme.spacing(10)}
onClick={removePicture} gap={theme.spacing(5)}
error={errors["picture"]} justifyContent="flex-end"
/> >
) : ( <Button
"" variant="text"
)} color="info"
<Stack onClick={removePicture}
direction="row"
mt={theme.spacing(10)}
gap={theme.spacing(5)}
justifyContent="flex-end"
> >
<Button Remove
variant="text" </Button>
color="info" <Button
onClick={removePicture} variant="contained"
> color="primary"
Remove onClick={handleUpdatePicture}
</Button> disabled={
<Button (Object.keys(errors).length !== 0 && errors?.picture) ||
variant="contained" progress.value !== 100
color="primary" ? true
onClick={handleUpdatePicture} : false
disabled={ }
(Object.keys(errors).length !== 0 && errors?.picture) || >
progress.value !== 100 Update
? true </Button>
: false
}
>
Update
</Button>
</Stack>
</Stack> </Stack>
</Modal> </GenericDialog>
</TabPanel> </TabPanel>
); );
}; };
@@ -1,6 +1,6 @@
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import TabPanel from "@mui/lab/TabPanel"; import TabPanel from "@mui/lab/TabPanel";
import { Box, Button, ButtonGroup, Modal, Stack, Typography } from "@mui/material"; import { Button, ButtonGroup, Stack, Typography } from "@mui/material";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Field from "../../Inputs/Field"; import Field from "../../Inputs/Field";
import { credentials } from "../../../Validation/validation"; import { credentials } from "../../../Validation/validation";
@@ -10,6 +10,7 @@ import { useSelector } from "react-redux";
import BasicTable from "../../BasicTable"; import BasicTable from "../../BasicTable";
import Select from "../../Inputs/Select"; import Select from "../../Inputs/Select";
import LoadingButton from "@mui/lab/LoadingButton"; import LoadingButton from "@mui/lab/LoadingButton";
import { GenericDialog } from "../../Dialog/genericDialog";
/** /**
* TeamPanel component manages the organization and team members, * TeamPanel component manages the organization and team members,
@@ -31,10 +32,10 @@ const TeamPanel = () => {
const { authToken, user } = useSelector((state) => state.auth); const { authToken, user } = useSelector((state) => state.auth);
//TODO //TODO
const [orgStates, setOrgStates] = useState({ // const [orgStates, setOrgStates] = useState({
name: "Bluewave Labs", // name: "Bluewave Labs",
isEdit: false, // isEdit: false,
}); // });
const [toInvite, setToInvite] = useState({ const [toInvite, setToInvite] = useState({
email: "", email: "",
role: ["0"], role: ["0"],
@@ -134,10 +135,10 @@ const TeamPanel = () => {
}, [errors, toInvite.email]); }, [errors, toInvite.email]);
// RENAME ORGANIZATION // RENAME ORGANIZATION
const toggleEdit = () => { // const toggleEdit = () => {
setOrgStates((prev) => ({ ...prev, isEdit: !prev.isEdit })); // setOrgStates((prev) => ({ ...prev, isEdit: !prev.isEdit }));
}; // };
const handleRename = () => {}; // const handleRename = () => {};
// INVITE MEMBER // INVITE MEMBER
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
@@ -327,100 +328,65 @@ const TeamPanel = () => {
table={"team"} table={"team"}
/> />
</Stack> </Stack>
<Modal
aria-labelledby="modal-invite-member" <GenericDialog
aria-describedby="invite-member-to-team" title={"Invite new team member"}
description={
"When you add a new team member, they will get access to all monitors."
}
open={isOpen} open={isOpen}
onClose={closeInviteModal} onClose={closeInviteModal}
theme={theme}
> >
<Field
type="email"
id="input-team-member"
placeholder="Email"
value={toInvite.email}
onChange={handleChange}
error={errors.email}
/>
<Select
id="team-member-role"
placeholder="Select role"
isHidden={true}
value={toInvite.role[0]}
onChange={(event) =>
setToInvite((prev) => ({
...prev,
role: [event.target.value],
}))
}
items={[
{ _id: "admin", name: "Admin" },
{ _id: "user", name: "User" },
]}
/>
<Stack <Stack
gap={theme.spacing(5)} direction="row"
sx={{ gap={theme.spacing(4)}
position: "absolute", mt={theme.spacing(8)}
top: "50%", justifyContent="flex-end"
left: "50%",
transform: "translate(-50%, -50%)",
width: 450,
bgcolor: theme.palette.background.main,
border: 1,
borderColor: theme.palette.border.light,
borderRadius: theme.shape.borderRadius,
boxShadow: theme.shape.boxShadow,
p: theme.spacing(15),
"&:focus": {
outline: "none",
},
}}
> >
<Box> <LoadingButton
<Typography loading={isSendingInvite}
id="modal-invite-member" variant="text"
component="h1" color="info"
fontWeight={600} onClick={closeInviteModal}
fontColor={theme.palette.text.secondary}
>
Invite new team member
</Typography>
<Typography
id="invite-member-to-team"
component="p"
fontSize={13}
color={theme.palette.text.accent}
sx={{ mt: theme.spacing(1), mb: theme.spacing(4) }}
>
When you add a new team member, they will get access to all monitors.
</Typography>
</Box>
<Field
type="email"
id="input-team-member"
placeholder="Email"
value={toInvite.email}
onChange={handleChange}
error={errors.email}
/>
<Select
id="team-member-role"
placeholder="Select role"
isHidden={true}
value={toInvite.role[0]}
onChange={(event) =>
setToInvite((prev) => ({
...prev,
role: [event.target.value],
}))
}
items={[
{ _id: "admin", name: "Admin" },
{ _id: "user", name: "User" },
]}
/>
<Stack
direction="row"
gap={theme.spacing(4)}
mt={theme.spacing(8)}
justifyContent="flex-end"
> >
<LoadingButton Cancel
loading={isSendingInvite} </LoadingButton>
variant="text" <LoadingButton
color="info" variant="contained"
onClick={closeInviteModal} color="primary"
> onClick={handleInviteMember}
Cancel loading={isSendingInvite}
</LoadingButton> disabled={isDisabled}
<LoadingButton >
variant="contained" Send invite
color="primary" </LoadingButton>
onClick={handleInviteMember}
loading={isSendingInvite}
disabled={isDisabled}
>
Send invite
</LoadingButton>
</Stack>
</Stack> </Stack>
</Modal> </GenericDialog>
</TabPanel> </TabPanel>
); );
}; };
@@ -2,23 +2,16 @@ import { useState } from "react";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { import { IconButton, Menu, MenuItem } from "@mui/material";
Button,
IconButton,
Menu,
MenuItem,
Modal,
Stack,
Typography,
} from "@mui/material";
import LoadingButton from "@mui/lab/LoadingButton";
import { logger } from "../../../../Utils/Logger"; import { logger } from "../../../../Utils/Logger";
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 { networkService } from "../../../../main"; import { networkService } from "../../../../main";
import { createToast } from "../../../../Utils/toastUtils"; import { createToast } from "../../../../Utils/toastUtils";
const ActionsMenu = ({ isAdmin, maintenanceWindow, updateCallback }) => { import Dialog from "../../../../Components/Dialog";
const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => {
maintenanceWindow; maintenanceWindow;
const { authToken } = useSelector((state) => state.auth); const { authToken } = useSelector((state) => state.auth);
const [anchorEl, setAnchorEl] = useState(null); const [anchorEl, setAnchorEl] = useState(null);
@@ -155,71 +148,21 @@ const ActionsMenu = ({ isAdmin, maintenanceWindow, updateCallback }) => {
Remove Remove
</MenuItem> </MenuItem>
</Menu> </Menu>
<Modal <Dialog
aria-labelledby="modal-delete-monitor"
aria-describedby="delete-monitor-confirmation"
open={isOpen} open={isOpen}
onClose={(e) => { theme={theme}
title={"Do you really want to remove this maintenance window?"}
onCancel={(e) => {
e.stopPropagation(); e.stopPropagation();
setIsOpen(false); setIsOpen(false);
}} }}
> confirmationButtonLabel={"Delete"}
<Stack onConfirm={(e) => {
gap={theme.spacing(2)} e.stopPropagation(e);
sx={{ handleRemove(e);
position: "absolute", }}
top: "50%", isLoading={isLoading}
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-maintenance"
component="h2"
variant="h2"
>
Do you really want to remove this maintenance window?
</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>
<LoadingButton
loading={isLoading}
variant="contained"
color="error"
onClick={(e) => {
e.stopPropagation(e);
handleRemove(e);
}}
>
Delete
</LoadingButton>
</Stack>
</Stack>
</Modal>
</> </>
); );
}; };
+7 -10
View File
@@ -453,20 +453,17 @@ const Configure = () => {
</Stack> </Stack>
</> </>
)} )}
<Dialog <Dialog
modelTitle="modal-delete-monitor"
modelDescription="delete-monitor-confirmation"
open={isOpen} open={isOpen}
onClose={() => setIsOpen(false)}
title="Do you really want to delete this monitor?"
confirmationBtnLbl="Delete"
confirmationBtnOnClick={handleRemove}
cancelBtnLbl="Cancel"
cancelBtnOnClick={() => setIsOpen(false)}
theme={theme} theme={theme}
isLoading={isLoading} title="Do you really want to delete this monitor?"
description="Once deleted, this monitor cannot be retrieved." description="Once deleted, this monitor cannot be retrieved."
></Dialog> onCancel={() => setIsOpen(false)}
confirmationButtonLabel="Delete"
onConfirm={handleRemove}
isLoading={isLoading}
/>
</Stack> </Stack>
); );
}; };
+13 -13
View File
@@ -188,25 +188,25 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
)} )}
</Menu> </Menu>
<Dialog <Dialog
modelTitle="modal-delete-monitor"
modelDescription="delete-monitor-confirmation"
open={isOpen} open={isOpen}
onClose={() => setIsOpen(false)} theme={theme}
title="Do you really want to delete this monitor?" title="Do you really want to delete this monitor?"
confirmationBtnLbl="Delete" description="Once deleted, this monitor cannot be retrieved."
confirmationBtnOnClick={(e) => { /* Do we need stop propagation? */
e.stopPropagation(); onCancel={(e) => {
handleRemove(e);
}}
cancelBtnLbl="Cancel"
cancelBtnOnClick={(e) => {
e.stopPropagation(); e.stopPropagation();
setIsOpen(false); setIsOpen(false);
}} }}
theme={theme} confirmationButtonLabel="Delete"
/* Do we need stop propagation? */
onConfirm={(e) => {
e.stopPropagation();
handleRemove(e);
}}
isLoading={isLoading} isLoading={isLoading}
description="Once deleted, this monitor cannot be retrieved." modelTitle="modal-delete-monitor"
></Dialog> modelDescription="delete-monitor-confirmation"
/>
</> </>
); );
}; };
+14 -63
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { Box, Button, Modal, Stack, Tooltip, Typography } from "@mui/material"; import { Box, Stack, Tooltip, Typography } from "@mui/material";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { useNavigate, useParams } from "react-router"; import { useNavigate, useParams } from "react-router";
import { import {
@@ -25,6 +25,7 @@ import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineR
import SkeletonLayout from "./skeleton"; import SkeletonLayout from "./skeleton";
import useUtils from "../../Monitors/utils"; import useUtils from "../../Monitors/utils";
import "./index.css"; import "./index.css";
import Dialog from "../../../Components/Dialog";
const PageSpeedConfigure = () => { const PageSpeedConfigure = () => {
const theme = useTheme(); const theme = useTheme();
@@ -37,6 +38,7 @@ const PageSpeedConfigure = () => {
const [monitor, setMonitor] = useState({}); const [monitor, setMonitor] = useState({});
const [errors, setErrors] = useState({}); const [errors, setErrors] = useState({});
const { statusColor, pagespeedStatusMsg, determineState } = useUtils(); const { statusColor, pagespeedStatusMsg, determineState } = useUtils();
const [buttonLoading, setButtonLoading] = useState(false);
const idMap = { const idMap = {
"monitor-url": "url", "monitor-url": "url",
"monitor-name": "name", "monitor-name": "name",
@@ -156,12 +158,14 @@ const PageSpeedConfigure = () => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const handleRemove = async (event) => { const handleRemove = async (event) => {
event.preventDefault(); event.preventDefault();
setButtonLoading(true);
const action = await dispatch(deletePageSpeed({ authToken, monitor })); const action = await dispatch(deletePageSpeed({ authToken, monitor }));
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
navigate("/pagespeed"); navigate("/pagespeed");
} else { } else {
createToast({ body: "Failed to delete monitor." }); createToast({ body: "Failed to delete monitor." });
} }
setButtonLoading(false);
}; };
return ( return (
@@ -428,69 +432,16 @@ const PageSpeedConfigure = () => {
</Stack> </Stack>
</> </>
)} )}
<Modal <Dialog
aria-labelledby="modal-delete-pagespeed-monitor"
aria-describedby="delete-pagespeed-monitor-confirmation"
open={isOpen} open={isOpen}
onClose={() => setIsOpen(false)} theme={theme}
disablePortal title={"Do you really want to delete this monitor?"}
> description={"Once deleted, this monitor cannot be retrieved."}
<Stack onCancel={() => setIsOpen(false)}
gap={theme.spacing(2)} confirmationButtonLabel={"Delete"}
sx={{ onConfirm={handleRemove}
position: "absolute", isLoading={buttonLoading}
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-pagespeed-monitor"
component="h2"
variant="h2"
fontWeight={500}
>
Do you really want to delete this monitor?
</Typography>
<Typography
id="delete-pagespeed-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={() => setIsOpen(false)}
>
Cancel
</Button>
<Button
variant="contained"
color="error"
onClick={handleRemove}
>
Delete
</Button>
</Stack>
</Stack>
</Modal>
</Stack> </Stack>
); );
}; };
+11 -18
View File
@@ -263,18 +263,15 @@ const Settings = ({ isAdmin }) => {
</Box> </Box>
</Stack> </Stack>
<Dialog <Dialog
modelTitle="model-clear-stats"
modelDescription="clear-stats-confirmation"
open={isOpen.deleteStats} open={isOpen.deleteStats}
onClose={() => setIsOpen(deleteStatsMonitorsInitState)}
title="Do you want to clear all stats?"
confirmationBtnLbl="Yes, clear all stats"
confirmationBtnOnClick={handleClearStats}
cancelBtnLbl="Cancel"
cancelBtnOnClick={() => setIsOpen(deleteStatsMonitorsInitState)}
theme={theme} theme={theme}
title="Do you want to clear all stats?"
description="Once deleted, this monitor cannot be retrieved."
onCancel={() => setIsOpen(deleteStatsMonitorsInitState)}
confirmationButtonLabel="Yes, clear all stats"
onConfirm={handleClearStats}
isLoading={isLoading || authIsLoading || checksIsLoading} isLoading={isLoading || authIsLoading || checksIsLoading}
></Dialog> />
</ConfigBox> </ConfigBox>
)} )}
{isAdmin && ( {isAdmin && (
@@ -314,18 +311,14 @@ const Settings = ({ isAdmin }) => {
</Box> </Box>
</Stack> </Stack>
<Dialog <Dialog
modelTitle="model-delete-all-monitors"
modelDescription="delete-all-monitors-confirmation"
open={isOpen.deleteMonitors} open={isOpen.deleteMonitors}
onClose={() => setIsOpen(deleteStatsMonitorsInitState)}
title="Do you want to remove all monitors?"
confirmationBtnLbl="Yes, clear all monitors"
confirmationBtnOnClick={handleDeleteAllMonitors}
cancelBtnLbl="Cancel"
cancelBtnOnClick={() => setIsOpen(deleteStatsMonitorsInitState)}
theme={theme} theme={theme}
title="Do you want to remove all monitors?"
onCancel={() => setIsOpen(deleteStatsMonitorsInitState)}
confirmationButtonLabel="Yes, clear all monitors"
onConfirm={handleDeleteAllMonitors}
isLoading={isLoading || authIsLoading || checksIsLoading} isLoading={isLoading || authIsLoading || checksIsLoading}
></Dialog> />
</ConfigBox> </ConfigBox>
)} )}
{isAdmin && ( {isAdmin && (