refactor: changing all dialogs to use Dialog or generic dialog

This commit is contained in:
Caio Cabral committed 2024-10-22 10:09:03 -04:00
1 parent 3a76fa77dd
commit 4fd11fbd1c
8 files changed
+102 -152

No files matched your search

+22 -25
View File
@@ -2,30 +2,30 @@ import LoadingButton from "@mui/lab/LoadingButton";
import { Button, Stack, Typography } from "@mui/material"; import { Button, Stack, Typography } from "@mui/material";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { GenericDialog } from "./genericDialog"; import { GenericDialog } from "./genericDialog";
import { useId } from "react";
const Dialog = ({ const Dialog = ({
modelTitle,
modelDescription,
open, open,
onClose, onClose,
title,
confirmationBtnLbl,
confirmationBtnOnClick,
cancelBtnLbl,
cancelBtnOnClick,
theme, theme,
isLoading, title,
description, description,
onCancel,
confirmationButtonLabel,
onConfirm,
isLoading,
}) => { }) => {
const titleId = useId();
const descriptionId = useId();
return ( return (
<GenericDialog <GenericDialog
title={modelTitle} title={titleId}
description={modelDescription} description={descriptionId}
open={open} open={open}
close={onClose} onClose={onClose}
theme={theme} theme={theme}
> >
<Typography <Typography
id={modelTitle} id={titleId}
component="h2" component="h2"
fontSize={16} fontSize={16}
color={theme.palette.text.primary} color={theme.palette.text.primary}
@@ -35,7 +35,7 @@ const Dialog = ({
</Typography> </Typography>
{description && ( {description && (
<Typography <Typography
id={modelDescription} id={descriptionId}
color={theme.palette.text.tertiary} color={theme.palette.text.tertiary}
> >
{description} {description}
@@ -50,17 +50,17 @@ const Dialog = ({
<Button <Button
variant="text" variant="text"
color="info" color="info"
onClick={cancelBtnOnClick} onClick={onCancel}
> >
{cancelBtnLbl} Cancel
</Button> </Button>
<LoadingButton <LoadingButton
variant="contained" variant="contained"
color="error" color="error"
loading={isLoading} loading={isLoading}
onClick={confirmationBtnOnClick} onClick={onConfirm}
> >
{confirmationBtnLbl} {confirmationButtonLabel}
</LoadingButton> </LoadingButton>
</Stack> </Stack>
</GenericDialog> </GenericDialog>
@@ -68,18 +68,15 @@ const Dialog = ({
}; };
Dialog.propTypes = { Dialog.propTypes = {
modelTitle: PropTypes.string.isRequired,
modelDescription: PropTypes.string.isRequired,
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,
isLoading: PropTypes.bool.isRequired, title: PropTypes.string.isRequired,
description: PropTypes.string, description: PropTypes.string,
onCancel: PropTypes.func.isRequired,
confirmationButtonLabel: PropTypes.string.isRequired,
onConfirm: PropTypes.func.isRequired,
isLoading: PropTypes.bool.isRequired,
}; };
export default Dialog; export default Dialog;
@@ -16,6 +16,7 @@ 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 { 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
@@ -370,56 +371,26 @@ const ProfilePanel = () => {
</Box> </Box>
)} )}
{/* TODO - Update ModalPopup Component with @mui for reusability */} {/* TODO - Update ModalPopup Component with @mui for reusability */}
<GenericDialog
title={"modal-delete-account"} <Dialog
description={"delete-account-confirmation"}
open={isModalOpen("delete")} open={isModalOpen("delete")}
close={() => setIsOpen("")} onClose={() => setIsOpen("")}
theme={theme} theme={theme}
/* disablePortal ? */ title={"Really delete this account?"}
> description={
<Typography "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."
id="modal-delete-account" }
component="h1" onCancel={() => setIsOpen("")}
> confirmationButtonLabel={"Delete account"}
Really delete this account? onConfirm={handleDeleteAccount}
</Typography> isLoading={isLoading}
<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>
</GenericDialog>
<GenericDialog <GenericDialog
title={"modal-update-picture"} title={"modal-update-picture"}
description={"update-profile-picture"} description={"update-profile-picture"}
open={isModalOpen("picture")} open={isModalOpen("picture")}
close={closePictureModal} onClose={closePictureModal}
theme={theme} theme={theme}
> >
<Typography <Typography
@@ -333,7 +333,7 @@ const TeamPanel = () => {
title={"modal-invite-member"} title={"modal-invite-member"}
description={"invite-member-to-team"} description={"invite-member-to-team"}
open={isOpen} open={isOpen}
close={closeInviteModal} onClose={closeInviteModal}
theme={theme} theme={theme}
> >
<Box> <Box>
@@ -2,14 +2,14 @@ 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 { Button, IconButton, Menu, MenuItem, Stack, Typography } from "@mui/material"; import { IconButton, Menu, MenuItem } 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";
import { GenericDialog } from "../../../../Components/Dialog/genericDialog";
import Dialog from "../../../../Components/Dialog";
const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => { const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => {
maintenanceWindow; maintenanceWindow;
@@ -148,52 +148,25 @@ const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => {
Remove Remove
</MenuItem> </MenuItem>
</Menu> </Menu>
<GenericDialog <Dialog
title={"modal-delete-monitor"}
description={"delete-monitor-confirmation"}
open={isOpen} open={isOpen}
close={(e) => { onClose={(e) => {
e.stopPropagation(); e.stopPropagation();
setIsOpen(false); setIsOpen(false);
}} }}
theme={theme} theme={theme}
> title={"Do you really want to remove this maintenance window?"}
<Typography onCancel={(e) => {
id="modal-delete-maintenance" e.stopPropagation();
component="h2" setIsOpen(false);
variant="h2" }}
> confirmationButtonLabel={"Delete"}
Do you really want to remove this maintenance window? onConfirm={(e) => {
</Typography> e.stopPropagation(e);
<Stack handleRemove(e);
direction="row" }}
gap={theme.spacing(4)} isLoading={isLoading}
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>
</GenericDialog>
</> </>
); );
}; };
@@ -453,20 +453,18 @@ const Configure = () => {
</Stack> </Stack>
</> </>
)} )}
<Dialog <Dialog
modelTitle="modal-delete-monitor"
modelDescription="delete-monitor-confirmation"
open={isOpen} open={isOpen}
onClose={() => setIsOpen(false)} 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 -12
View File
@@ -188,25 +188,26 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => {
)} )}
</Menu> </Menu>
<Dialog <Dialog
modelTitle="modal-delete-monitor"
modelDescription="delete-monitor-confirmation"
open={isOpen} open={isOpen}
onClose={() => setIsOpen(false)} 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"
/>
</> </>
); );
}; };
+16 -1
View File
@@ -26,6 +26,7 @@ import SkeletonLayout from "./skeleton";
import useUtils from "../../Monitors/utils"; import useUtils from "../../Monitors/utils";
import "./index.css"; import "./index.css";
import { GenericDialog } from "../../../Components/Dialog/genericDialog"; import { GenericDialog } from "../../../Components/Dialog/genericDialog";
import Dialog from "../../../Components/Dialog";
const PageSpeedConfigure = () => { const PageSpeedConfigure = () => {
const theme = useTheme(); const theme = useTheme();
@@ -38,6 +39,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",
@@ -157,12 +159,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 (
@@ -429,11 +433,22 @@ const PageSpeedConfigure = () => {
</Stack> </Stack>
</> </>
)} )}
<Dialog
open={isOpen}
onClose={() => setIsOpen(false)}
theme={theme}
title={"Do you really want to delete this monitor?"}
description={"Once deleted, this monitor cannot be retrieved."}
onCancel={() => setIsOpen(false)}
confirmationButtonLabel={"Delete"}
onConfirm={handleRemove}
isLoading={buttonLoading}
/>
<GenericDialog <GenericDialog
title={"modal-delete-pagespeed-monitor"} title={"modal-delete-pagespeed-monitor"}
description={"delete-pagespeed-monitor-confirmation"} description={"delete-pagespeed-monitor-confirmation"}
open={isOpen} open={isOpen}
close={() => setIsOpen(false)} onClose={() => setIsOpen(false)}
theme={theme} theme={theme}
> >
<Typography <Typography
+11 -16
View File
@@ -263,18 +263,16 @@ 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)} 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 +312,15 @@ 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)} 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 && (