From effc6dac3af95bec088b0326161c7ae82d344649 Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 05:58:21 -0400 Subject: [PATCH 1/9] feat: create generic dialog component --- .../src/Components/Dialog/genericDialog.jsx | 45 ++++++++ Client/src/Components/Dialog/index.jsx | 100 +++++++----------- 2 files changed, 86 insertions(+), 59 deletions(-) create mode 100644 Client/src/Components/Dialog/genericDialog.jsx diff --git a/Client/src/Components/Dialog/genericDialog.jsx b/Client/src/Components/Dialog/genericDialog.jsx new file mode 100644 index 000000000..2807b2e8c --- /dev/null +++ b/Client/src/Components/Dialog/genericDialog.jsx @@ -0,0 +1,45 @@ +import { Modal, Stack } from "@mui/material"; +import PropTypes from "prop-types"; +const GenericDialog = ({ title, description, open, onClose, theme, children }) => { + return ( + + + {children} + + + ); +}; + +GenericDialog.propTypes = { + title: PropTypes.string.isRequired, + description: PropTypes.string.isRequired, + open: PropTypes.bool.isRequired, + onClose: PropTypes.func.isRequired, + theme: PropTypes.object.isRequired, + children: PropTypes.element.isRequired, +}; + +export { GenericDialog }; diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx index 55ec801d7..d87baa42a 100644 --- a/Client/src/Components/Dialog/index.jsx +++ b/Client/src/Components/Dialog/index.jsx @@ -1,6 +1,7 @@ import LoadingButton from "@mui/lab/LoadingButton"; -import { Button, Modal, Stack, Typography } from "@mui/material"; +import { Button, Stack, Typography } from "@mui/material"; import PropTypes from "prop-types"; +import { GenericDialog } from "./genericDialog"; const Dialog = ({ modelTitle, modelDescription, @@ -16,72 +17,53 @@ const Dialog = ({ description, }) => { return ( - - + {title} + + {description && ( - {title} + {description} - {description && ( - - {description} - - )} - + - - {confirmationBtnLbl} - - + {cancelBtnLbl} + + + {confirmationBtnLbl} + - + ); }; From 7752e52fcdefbd7ab625b362e23f5a69cf069bab Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 08:54:12 -0400 Subject: [PATCH 2/9] refactor team panel to get rid of error of unused code, and add generic modals --- .../TabPanels/Account/ProfilePanel.jsx | 242 ++++++++---------- .../TabPanels/Account/TeamPanel.jsx | 181 ++++++------- 2 files changed, 185 insertions(+), 238 deletions(-) diff --git a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx index 999e026c7..f5ac95bc8 100644 --- a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx +++ b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx @@ -1,7 +1,7 @@ import { useTheme } from "@emotion/react"; import { useRef, useState } from "react"; 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 Field from "../../Inputs/Field"; import ImageField from "../../Inputs/Image"; @@ -15,6 +15,7 @@ import { clearUptimeMonitorState } from "../../../Features/UptimeMonitors/uptime import { createToast } from "../../../Utils/toastUtils"; import { logger } from "../../../Utils/Logger"; import LoadingButton from "@mui/lab/LoadingButton"; +import { GenericDialog } from "../../Dialog/genericDialog"; /** * ProfilePanel component displays a form for editing user profile information @@ -369,158 +370,121 @@ const ProfilePanel = () => { )} {/* TODO - Update ModalPopup Component with @mui for reusability */} - setIsOpen("")} - disablePortal + close={() => setIsOpen("")} + theme={theme} + /* disablePortal ? */ > + + Really delete this account? + + + 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. + - setIsOpen("")} > - Really delete this account? - - + - 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. - - - - - Delete account - - + Delete account + - - + - - - Upload Image - - + + {progress.isLoading || progress.value !== 0 || errors["picture"] ? ( + } + label={file?.name} + size={file?.size} + progress={progress.value} + onClick={removePicture} + error={errors["picture"]} /> - {progress.isLoading || progress.value !== 0 || errors["picture"] ? ( - } - label={file?.name} - size={file?.size} - progress={progress.value} - onClick={removePicture} - error={errors["picture"]} - /> - ) : ( - "" - )} - + - - + Remove + + - + ); }; diff --git a/Client/src/Components/TabPanels/Account/TeamPanel.jsx b/Client/src/Components/TabPanels/Account/TeamPanel.jsx index 33218bcbb..d1d67d253 100644 --- a/Client/src/Components/TabPanels/Account/TeamPanel.jsx +++ b/Client/src/Components/TabPanels/Account/TeamPanel.jsx @@ -1,6 +1,6 @@ import { useTheme } from "@emotion/react"; import TabPanel from "@mui/lab/TabPanel"; -import { Box, Button, ButtonGroup, Modal, Stack, Typography } from "@mui/material"; +import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material"; import { useEffect, useState } from "react"; import Field from "../../Inputs/Field"; import { credentials } from "../../../Validation/validation"; @@ -10,6 +10,7 @@ import { useSelector } from "react-redux"; import BasicTable from "../../BasicTable"; import Select from "../../Inputs/Select"; import LoadingButton from "@mui/lab/LoadingButton"; +import { GenericDialog } from "../../Dialog/genericDialog"; /** * TeamPanel component manages the organization and team members, @@ -31,10 +32,10 @@ const TeamPanel = () => { const { authToken, user } = useSelector((state) => state.auth); //TODO - const [orgStates, setOrgStates] = useState({ - name: "Bluewave Labs", - isEdit: false, - }); + // const [orgStates, setOrgStates] = useState({ + // name: "Bluewave Labs", + // isEdit: false, + // }); const [toInvite, setToInvite] = useState({ email: "", role: ["0"], @@ -134,10 +135,10 @@ const TeamPanel = () => { }, [errors, toInvite.email]); // RENAME ORGANIZATION - const toggleEdit = () => { - setOrgStates((prev) => ({ ...prev, isEdit: !prev.isEdit })); - }; - const handleRename = () => {}; + // const toggleEdit = () => { + // setOrgStates((prev) => ({ ...prev, isEdit: !prev.isEdit })); + // }; + // const handleRename = () => {}; // INVITE MEMBER const [isOpen, setIsOpen] = useState(false); @@ -327,100 +328,82 @@ const TeamPanel = () => { table={"team"} /> - - - - - Invite new team member - - - When you add a new team member, they will get access to all monitors. - - - - + setToInvite((prev) => ({ + ...prev, + role: [event.target.value], + })) + } + items={[ + { _id: "admin", name: "Admin" }, + { _id: "user", name: "User" }, + ]} + /> + + + Cancel + + + Send invite + - + ); }; From 220fc080e615113fdb5f722ef3301b3ca969a8a9 Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 08:56:35 -0400 Subject: [PATCH 3/9] refactor actions menu --- .../MaintenanceTable/ActionsMenu/index.jsx | 106 +++++++----------- 1 file changed, 40 insertions(+), 66 deletions(-) diff --git a/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx b/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx index 088dae988..a4ed0edae 100644 --- a/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx +++ b/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx @@ -2,23 +2,16 @@ import { useState } from "react"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { useSelector } from "react-redux"; -import { - Button, - IconButton, - Menu, - MenuItem, - Modal, - Stack, - Typography, -} from "@mui/material"; +import { Button, IconButton, Menu, MenuItem, Stack, Typography } from "@mui/material"; import LoadingButton from "@mui/lab/LoadingButton"; import { logger } from "../../../../Utils/Logger"; import Settings from "../../../../assets/icons/settings-bold.svg?react"; import PropTypes from "prop-types"; import { networkService } from "../../../../main"; import { createToast } from "../../../../Utils/toastUtils"; +import { GenericDialog } from "../../../../Components/Dialog/genericDialog"; -const ActionsMenu = ({ isAdmin, maintenanceWindow, updateCallback }) => { +const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => { maintenanceWindow; const { authToken } = useSelector((state) => state.auth); const [anchorEl, setAnchorEl] = useState(null); @@ -155,71 +148,52 @@ const ActionsMenu = ({ isAdmin, maintenanceWindow, updateCallback }) => { Remove - { + close={(e) => { e.stopPropagation(); setIsOpen(false); }} + theme={theme} > - - + + - { - e.stopPropagation(e); - handleRemove(e); - }} - > - Delete - - + Delete + - + ); }; From 3a76fa77dd5b6ba110a8ac747b966cf427543cdf Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 08:58:40 -0400 Subject: [PATCH 4/9] refactor page speed --- .../src/Pages/PageSpeed/Configure/index.jsx | 97 ++++++++----------- 1 file changed, 39 insertions(+), 58 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index 71f3ff083..49d18e4c8 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { useTheme } from "@emotion/react"; -import { Box, Button, Modal, Stack, Tooltip, Typography } from "@mui/material"; +import { Box, Button, Stack, Tooltip, Typography } from "@mui/material"; import { useDispatch, useSelector } from "react-redux"; import { useNavigate, useParams } from "react-router"; import { @@ -25,6 +25,7 @@ import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineR import SkeletonLayout from "./skeleton"; import useUtils from "../../Monitors/utils"; import "./index.css"; +import { GenericDialog } from "../../../Components/Dialog/genericDialog"; const PageSpeedConfigure = () => { const theme = useTheme(); @@ -428,69 +429,49 @@ const PageSpeedConfigure = () => { )} - setIsOpen(false)} - disablePortal + close={() => setIsOpen(false)} + theme={theme} > - - + + Once deleted, this monitor cannot be retrieved. + + + - - + Delete + - + ); }; From 4fd11fbd1c99d2e28da19aee61e39c9d26a6ac9f Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 10:09:03 -0400 Subject: [PATCH 5/9] refactor: changing all dialogs to use Dialog or generic dialog --- Client/src/Components/Dialog/index.jsx | 47 +++++++------- .../TabPanels/Account/ProfilePanel.jsx | 59 +++++------------- .../TabPanels/Account/TeamPanel.jsx | 2 +- .../MaintenanceTable/ActionsMenu/index.jsx | 61 ++++++------------- Client/src/Pages/Monitors/Configure/index.jsx | 16 +++-- .../src/Pages/Monitors/Home/actionsMenu.jsx | 25 ++++---- .../src/Pages/PageSpeed/Configure/index.jsx | 17 +++++- Client/src/Pages/Settings/index.jsx | 27 ++++---- 8 files changed, 102 insertions(+), 152 deletions(-) diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx index d87baa42a..2053304ee 100644 --- a/Client/src/Components/Dialog/index.jsx +++ b/Client/src/Components/Dialog/index.jsx @@ -2,30 +2,30 @@ import LoadingButton from "@mui/lab/LoadingButton"; import { Button, Stack, Typography } from "@mui/material"; import PropTypes from "prop-types"; import { GenericDialog } from "./genericDialog"; +import { useId } from "react"; const Dialog = ({ - modelTitle, - modelDescription, open, onClose, - title, - confirmationBtnLbl, - confirmationBtnOnClick, - cancelBtnLbl, - cancelBtnOnClick, theme, - isLoading, + title, description, + onCancel, + confirmationButtonLabel, + onConfirm, + isLoading, }) => { + const titleId = useId(); + const descriptionId = useId(); return ( {description && ( {description} @@ -50,17 +50,17 @@ const Dialog = ({ - {confirmationBtnLbl} + {confirmationButtonLabel} @@ -68,18 +68,15 @@ const Dialog = ({ }; Dialog.propTypes = { - modelTitle: PropTypes.string.isRequired, - modelDescription: PropTypes.string.isRequired, open: PropTypes.bool.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, - isLoading: PropTypes.bool.isRequired, + title: PropTypes.string.isRequired, description: PropTypes.string, + onCancel: PropTypes.func.isRequired, + confirmationButtonLabel: PropTypes.string.isRequired, + onConfirm: PropTypes.func.isRequired, + isLoading: PropTypes.bool.isRequired, }; export default Dialog; diff --git a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx index f5ac95bc8..988c4d1d5 100644 --- a/Client/src/Components/TabPanels/Account/ProfilePanel.jsx +++ b/Client/src/Components/TabPanels/Account/ProfilePanel.jsx @@ -16,6 +16,7 @@ import { createToast } from "../../../Utils/toastUtils"; import { logger } from "../../../Utils/Logger"; 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 @@ -370,56 +371,26 @@ const ProfilePanel = () => { )} {/* TODO - Update ModalPopup Component with @mui for reusability */} - setIsOpen("")} + onClose={() => setIsOpen("")} theme={theme} - /* disablePortal ? */ - > - - Really delete this account? - - - 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. - - - - - Delete account - - - + title={"Really delete this account?"} + description={ + "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." + } + onCancel={() => setIsOpen("")} + confirmationButtonLabel={"Delete account"} + onConfirm={handleDeleteAccount} + isLoading={isLoading} + /> + { title={"modal-invite-member"} description={"invite-member-to-team"} open={isOpen} - close={closeInviteModal} + onClose={closeInviteModal} theme={theme} > diff --git a/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx b/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx index a4ed0edae..b0e571fd6 100644 --- a/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx +++ b/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx @@ -2,14 +2,14 @@ import { useState } from "react"; import { useTheme } from "@emotion/react"; import { useNavigate } from "react-router-dom"; import { useSelector } from "react-redux"; -import { Button, IconButton, Menu, MenuItem, Stack, Typography } from "@mui/material"; -import LoadingButton from "@mui/lab/LoadingButton"; +import { IconButton, Menu, MenuItem } from "@mui/material"; import { logger } from "../../../../Utils/Logger"; import Settings from "../../../../assets/icons/settings-bold.svg?react"; import PropTypes from "prop-types"; import { networkService } from "../../../../main"; import { createToast } from "../../../../Utils/toastUtils"; -import { GenericDialog } from "../../../../Components/Dialog/genericDialog"; + +import Dialog from "../../../../Components/Dialog"; const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => { maintenanceWindow; @@ -148,52 +148,25 @@ const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => { Remove - { + onClose={(e) => { e.stopPropagation(); setIsOpen(false); }} theme={theme} - > - - Do you really want to remove this maintenance window? - - - - { - e.stopPropagation(e); - handleRemove(e); - }} - > - Delete - - - + title={"Do you really want to remove this maintenance window?"} + onCancel={(e) => { + e.stopPropagation(); + setIsOpen(false); + }} + confirmationButtonLabel={"Delete"} + onConfirm={(e) => { + e.stopPropagation(e); + handleRemove(e); + }} + isLoading={isLoading} + /> ); }; diff --git a/Client/src/Pages/Monitors/Configure/index.jsx b/Client/src/Pages/Monitors/Configure/index.jsx index 9eb27c478..8ef557f5e 100644 --- a/Client/src/Pages/Monitors/Configure/index.jsx +++ b/Client/src/Pages/Monitors/Configure/index.jsx @@ -453,20 +453,18 @@ const Configure = () => { )} + setIsOpen(false)} - title="Do you really want to delete this monitor?" - confirmationBtnLbl="Delete" - confirmationBtnOnClick={handleRemove} - cancelBtnLbl="Cancel" - cancelBtnOnClick={() => setIsOpen(false)} theme={theme} - isLoading={isLoading} + 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={isLoading} + /> ); }; diff --git a/Client/src/Pages/Monitors/Home/actionsMenu.jsx b/Client/src/Pages/Monitors/Home/actionsMenu.jsx index fb3bd4b49..e72bb545f 100644 --- a/Client/src/Pages/Monitors/Home/actionsMenu.jsx +++ b/Client/src/Pages/Monitors/Home/actionsMenu.jsx @@ -188,25 +188,26 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => { )} setIsOpen(false)} + theme={theme} title="Do you really want to delete this monitor?" - confirmationBtnLbl="Delete" - confirmationBtnOnClick={(e) => { - e.stopPropagation(); - handleRemove(e); - }} - cancelBtnLbl="Cancel" - cancelBtnOnClick={(e) => { + description="Once deleted, this monitor cannot be retrieved." + /* Do we need stop propagation? */ + onCancel={(e) => { e.stopPropagation(); setIsOpen(false); }} - theme={theme} + confirmationButtonLabel="Delete" + /* Do we need stop propagation? */ + onConfirm={(e) => { + e.stopPropagation(); + handleRemove(e); + }} isLoading={isLoading} - description="Once deleted, this monitor cannot be retrieved." - > + modelTitle="modal-delete-monitor" + modelDescription="delete-monitor-confirmation" + /> ); }; diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index 49d18e4c8..e0ad1516b 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -26,6 +26,7 @@ import SkeletonLayout from "./skeleton"; import useUtils from "../../Monitors/utils"; import "./index.css"; import { GenericDialog } from "../../../Components/Dialog/genericDialog"; +import Dialog from "../../../Components/Dialog"; const PageSpeedConfigure = () => { const theme = useTheme(); @@ -38,6 +39,7 @@ const PageSpeedConfigure = () => { const [monitor, setMonitor] = useState({}); const [errors, setErrors] = useState({}); const { statusColor, pagespeedStatusMsg, determineState } = useUtils(); + const [buttonLoading, setButtonLoading] = useState(false); const idMap = { "monitor-url": "url", "monitor-name": "name", @@ -157,12 +159,14 @@ const PageSpeedConfigure = () => { const [isOpen, setIsOpen] = useState(false); const handleRemove = async (event) => { event.preventDefault(); + setButtonLoading(true); const action = await dispatch(deletePageSpeed({ authToken, monitor })); if (action.meta.requestStatus === "fulfilled") { navigate("/pagespeed"); } else { createToast({ body: "Failed to delete monitor." }); } + setButtonLoading(false); }; return ( @@ -429,11 +433,22 @@ const PageSpeedConfigure = () => { )} + 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} + /> setIsOpen(false)} + onClose={() => setIsOpen(false)} theme={theme} > { setIsOpen(deleteStatsMonitorsInitState)} - title="Do you want to clear all stats?" - confirmationBtnLbl="Yes, clear all stats" - confirmationBtnOnClick={handleClearStats} - cancelBtnLbl="Cancel" - cancelBtnOnClick={() => setIsOpen(deleteStatsMonitorsInitState)} 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} - > + /> )} {isAdmin && ( @@ -314,18 +312,15 @@ const Settings = ({ isAdmin }) => { setIsOpen(deleteStatsMonitorsInitState)} - title="Do you want to remove all monitors?" - confirmationBtnLbl="Yes, clear all monitors" - confirmationBtnOnClick={handleDeleteAllMonitors} - cancelBtnLbl="Cancel" - cancelBtnOnClick={() => setIsOpen(deleteStatsMonitorsInitState)} theme={theme} + title="Do you want to remove all monitors?" + onCancel={() => setIsOpen(deleteStatsMonitorsInitState)} + confirmationButtonLabel="Yes, clear all monitors" + onConfirm={handleDeleteAllMonitors} isLoading={isLoading || authIsLoading || checksIsLoading} - > + /> )} {isAdmin && ( From f1d331cdf83f7256d5de849081333feb997d6ac5 Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 11:38:54 -0400 Subject: [PATCH 6/9] refactor: update generic dialog to have title and maybe description --- .../src/Components/Dialog/genericDialog.jsx | 30 +++++++++++++-- Client/src/Components/Dialog/index.jsx | 37 +++++-------------- .../TabPanels/Account/ProfilePanel.jsx | 10 +---- .../TabPanels/Account/TeamPanel.jsx | 27 +++----------- .../src/Pages/PageSpeed/Configure/index.jsx | 19 ++-------- 5 files changed, 44 insertions(+), 79 deletions(-) diff --git a/Client/src/Components/Dialog/genericDialog.jsx b/Client/src/Components/Dialog/genericDialog.jsx index 2807b2e8c..eb1c287d3 100644 --- a/Client/src/Components/Dialog/genericDialog.jsx +++ b/Client/src/Components/Dialog/genericDialog.jsx @@ -1,10 +1,15 @@ -import { Modal, Stack } from "@mui/material"; +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 ( @@ -27,6 +32,23 @@ const GenericDialog = ({ title, description, open, onClose, theme, children }) = }, }} > + + {title} + + {description && ( + + {description} + + )} {children} @@ -35,7 +57,7 @@ const GenericDialog = ({ title, description, open, onClose, theme, children }) = GenericDialog.propTypes = { title: PropTypes.string.isRequired, - description: PropTypes.string.isRequired, + description: PropTypes.string, open: PropTypes.bool.isRequired, onClose: PropTypes.func.isRequired, theme: PropTypes.object.isRequired, diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx index 2053304ee..d138ab983 100644 --- a/Client/src/Components/Dialog/index.jsx +++ b/Client/src/Components/Dialog/index.jsx @@ -1,46 +1,27 @@ -import LoadingButton from "@mui/lab/LoadingButton"; -import { Button, Stack, Typography } from "@mui/material"; import PropTypes from "prop-types"; +import LoadingButton from "@mui/lab/LoadingButton"; +import { Button, Stack } from "@mui/material"; import { GenericDialog } from "./genericDialog"; -import { useId } from "react"; + const Dialog = ({ + title, + description, open, onClose, theme, - title, - description, onCancel, confirmationButtonLabel, onConfirm, isLoading, }) => { - const titleId = useId(); - const descriptionId = useId(); return ( - - {title} - - {description && ( - - {description} - - )} { /> - - Upload Image - { - - - Invite new team member - - - When you add a new team member, they will get access to all monitors. - - { isLoading={buttonLoading} /> setIsOpen(false)} theme={theme} > - - Do you really want to delete this monitor? - - - Once deleted, this monitor cannot be retrieved. - + {/* Make it dialog? */} Date: Tue, 22 Oct 2024 11:41:55 -0400 Subject: [PATCH 7/9] chore: removing duplicated code --- .../src/Pages/PageSpeed/Configure/index.jsx | 34 ++----------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index e4b6363fd..275321694 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "react"; import { useTheme } from "@emotion/react"; -import { Box, Button, Stack, Tooltip, Typography } from "@mui/material"; +import { Box, Stack, Tooltip, Typography } from "@mui/material"; import { useDispatch, useSelector } from "react-redux"; import { useNavigate, useParams } from "react-router"; import { @@ -25,7 +25,6 @@ import PlayCircleOutlineRoundedIcon from "@mui/icons-material/PlayCircleOutlineR import SkeletonLayout from "./skeleton"; import useUtils from "../../Monitors/utils"; import "./index.css"; -import { GenericDialog } from "../../../Components/Dialog/genericDialog"; import Dialog from "../../../Components/Dialog"; const PageSpeedConfigure = () => { @@ -444,36 +443,7 @@ const PageSpeedConfigure = () => { onConfirm={handleRemove} isLoading={buttonLoading} /> - setIsOpen(false)} - theme={theme} - > - {/* Make it dialog? */} - - - - - + ); }; From 02d65bd0bcc5d670e44b64ba231786cdd3761cf9 Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 11:49:12 -0400 Subject: [PATCH 8/9] chore, removing closing tag for dialog --- Client/src/Pages/PageSpeed/Configure/index.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index 275321694..50488548a 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -443,7 +443,6 @@ const PageSpeedConfigure = () => { onConfirm={handleRemove} isLoading={buttonLoading} /> - ); }; From f0c1d30de08ea980a61bdb3d20be57e71b26724c Mon Sep 17 00:00:00 2001 From: Caio Cabral Date: Tue, 22 Oct 2024 11:56:12 -0400 Subject: [PATCH 9/9] refactor: removing dupicity of onCancel and onClose --- Client/src/Components/Dialog/index.jsx | 3 +-- Client/src/Components/TabPanels/Account/ProfilePanel.jsx | 1 - .../Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx | 4 ---- Client/src/Pages/Monitors/Configure/index.jsx | 1 - Client/src/Pages/Monitors/Home/actionsMenu.jsx | 1 - Client/src/Pages/PageSpeed/Configure/index.jsx | 1 - Client/src/Pages/Settings/index.jsx | 2 -- 7 files changed, 1 insertion(+), 12 deletions(-) diff --git a/Client/src/Components/Dialog/index.jsx b/Client/src/Components/Dialog/index.jsx index d138ab983..fdc34c0c1 100644 --- a/Client/src/Components/Dialog/index.jsx +++ b/Client/src/Components/Dialog/index.jsx @@ -7,7 +7,6 @@ const Dialog = ({ title, description, open, - onClose, theme, onCancel, confirmationButtonLabel, @@ -19,7 +18,7 @@ const Dialog = ({ title={title} description={description} open={open} - onClose={onClose} + onClose={onCancel} theme={theme} > { setIsOpen("")} theme={theme} title={"Really delete this account?"} description={ diff --git a/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx b/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx index b0e571fd6..8928b1e05 100644 --- a/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx +++ b/Client/src/Pages/Maintenance/MaintenanceTable/ActionsMenu/index.jsx @@ -150,10 +150,6 @@ const ActionsMenu = ({ /* isAdmin, */ maintenanceWindow, updateCallback }) => { { - e.stopPropagation(); - setIsOpen(false); - }} theme={theme} title={"Do you really want to remove this maintenance window?"} onCancel={(e) => { diff --git a/Client/src/Pages/Monitors/Configure/index.jsx b/Client/src/Pages/Monitors/Configure/index.jsx index 8ef557f5e..22cc8618e 100644 --- a/Client/src/Pages/Monitors/Configure/index.jsx +++ b/Client/src/Pages/Monitors/Configure/index.jsx @@ -456,7 +456,6 @@ const Configure = () => { setIsOpen(false)} theme={theme} title="Do you really want to delete this monitor?" description="Once deleted, this monitor cannot be retrieved." diff --git a/Client/src/Pages/Monitors/Home/actionsMenu.jsx b/Client/src/Pages/Monitors/Home/actionsMenu.jsx index e72bb545f..7efffa93c 100644 --- a/Client/src/Pages/Monitors/Home/actionsMenu.jsx +++ b/Client/src/Pages/Monitors/Home/actionsMenu.jsx @@ -189,7 +189,6 @@ const ActionsMenu = ({ monitor, isAdmin, updateCallback }) => { setIsOpen(false)} theme={theme} title="Do you really want to delete this monitor?" description="Once deleted, this monitor cannot be retrieved." diff --git a/Client/src/Pages/PageSpeed/Configure/index.jsx b/Client/src/Pages/PageSpeed/Configure/index.jsx index 50488548a..222fa733f 100644 --- a/Client/src/Pages/PageSpeed/Configure/index.jsx +++ b/Client/src/Pages/PageSpeed/Configure/index.jsx @@ -434,7 +434,6 @@ const PageSpeedConfigure = () => { )} setIsOpen(false)} theme={theme} title={"Do you really want to delete this monitor?"} description={"Once deleted, this monitor cannot be retrieved."} diff --git a/Client/src/Pages/Settings/index.jsx b/Client/src/Pages/Settings/index.jsx index b88650400..9a8913c39 100644 --- a/Client/src/Pages/Settings/index.jsx +++ b/Client/src/Pages/Settings/index.jsx @@ -264,7 +264,6 @@ const Settings = ({ isAdmin }) => { setIsOpen(deleteStatsMonitorsInitState)} theme={theme} title="Do you want to clear all stats?" description="Once deleted, this monitor cannot be retrieved." @@ -313,7 +312,6 @@ const Settings = ({ isAdmin }) => { setIsOpen(deleteStatsMonitorsInitState)} theme={theme} title="Do you want to remove all monitors?" onCancel={() => setIsOpen(deleteStatsMonitorsInitState)}