From 83c15d8bf54d793deac76ede7b89ca9463f3e561 Mon Sep 17 00:00:00 2001 From: daniele-mng Date: Mon, 11 Nov 2024 16:45:08 +0100 Subject: [PATCH] fix: delete button dialogs --- .../components/dialog/confirmationdialog.jsx | 10 +- src/web/components/dialog/twobuttonfooter.jsx | 8 +- src/web/entities/footer.jsx | 2 + src/web/pages/extras/trashcanpage.jsx | 2 + src/web/pages/users/dialog.jsx | 341 +++++++++--------- 5 files changed, 191 insertions(+), 172 deletions(-) diff --git a/src/web/components/dialog/confirmationdialog.jsx b/src/web/components/dialog/confirmationdialog.jsx index 72df7b0424..de6705427b 100644 --- a/src/web/components/dialog/confirmationdialog.jsx +++ b/src/web/components/dialog/confirmationdialog.jsx @@ -9,7 +9,9 @@ import PropTypes from 'web/utils/proptypes'; import Dialog from 'web/components/dialog/dialog'; import DialogContent from 'web/components/dialog/content'; -import DialogTwoButtonFooter from 'web/components/dialog/twobuttonfooter'; +import DialogTwoButtonFooter, { + DELETE_ACTION, +} from 'web/components/dialog/twobuttonfooter'; import useTranslation from 'web/hooks/useTranslation'; @@ -21,6 +23,7 @@ const ConfirmationDialogContent = ({ rightButtonTitle, onResumeClick, loading, + rightButtonAction, }) => { const handleResume = useCallback(() => { if (onResumeClick) { @@ -36,6 +39,7 @@ const ConfirmationDialogContent = ({ onLeftButtonClick={close} onRightButtonClick={handleResume} loading={loading} + rightButtonAction={rightButtonAction} /> ); @@ -47,6 +51,7 @@ ConfirmationDialogContent.propTypes = { rightButtonTitle: PropTypes.string, onResumeClick: PropTypes.func.isRequired, loading: PropTypes.bool, + rightButtonAction: PropTypes.oneOf([undefined, DELETE_ACTION]), }; const ConfirmationDialog = ({ @@ -54,6 +59,7 @@ const ConfirmationDialog = ({ content, title, rightButtonTitle, + rightButtonAction, onClose, onResumeClick, loading, @@ -70,6 +76,7 @@ const ConfirmationDialog = ({ rightButtonTitle={rightButtonTitle} onResumeClick={onResumeClick} loading={loading} + rightButtonAction={rightButtonAction} /> )} @@ -84,6 +91,7 @@ ConfirmationDialog.propTypes = { onClose: PropTypes.func.isRequired, onResumeClick: PropTypes.func.isRequired, loading: PropTypes.bool, + rightButtonAction: PropTypes.oneOf([undefined, DELETE_ACTION]), }; export default ConfirmationDialog; diff --git a/src/web/components/dialog/twobuttonfooter.jsx b/src/web/components/dialog/twobuttonfooter.jsx index 1c2228c23a..29669fd15a 100644 --- a/src/web/components/dialog/twobuttonfooter.jsx +++ b/src/web/components/dialog/twobuttonfooter.jsx @@ -13,6 +13,8 @@ import Button from 'web/components/form/button'; import useTranslation from 'web/hooks/useTranslation'; +export const DELETE_ACTION = 'delete'; + const DialogTwoButtonFooter = ({ leftButtonTitle, rightButtonTitle, @@ -20,15 +22,17 @@ const DialogTwoButtonFooter = ({ onRightButtonClick, loading = false, isLoading = loading, + rightButtonAction, }) => { const [_] = useTranslation(); leftButtonTitle = leftButtonTitle || _('Cancel'); + const isRightButtonAction = DELETE_ACTION === rightButtonAction; return ( @@ -51,6 +56,7 @@ DialogTwoButtonFooter.propTypes = { rightButtonTitle: PropTypes.string.isRequired, onLeftButtonClick: PropTypes.func, onRightButtonClick: PropTypes.func, + rightButtonAction: PropTypes.oneOf([undefined, DELETE_ACTION]), }; export default DialogTwoButtonFooter; diff --git a/src/web/entities/footer.jsx b/src/web/entities/footer.jsx index b9dea16f85..5098f25901 100644 --- a/src/web/entities/footer.jsx +++ b/src/web/entities/footer.jsx @@ -24,6 +24,7 @@ import TableFooter from 'web/components/table/footer'; import TableRow from 'web/components/table/row'; import useTranslation from 'web/hooks/useTranslation'; +import {DELETE_ACTION} from 'web/components/dialog/twobuttonfooter'; const DIALOG_TYPES = { TRASH: 'trash', @@ -162,6 +163,7 @@ export const EntitiesFooter = ({ content={configDialog.dialogText} title={configDialog.dialogTitle} rightButtonTitle={configDialog.dialogButtonTitle} + rightButtonAction={DELETE_ACTION} width="500px" /> )} diff --git a/src/web/pages/extras/trashcanpage.jsx b/src/web/pages/extras/trashcanpage.jsx index 1bdc141409..073a00b520 100644 --- a/src/web/pages/extras/trashcanpage.jsx +++ b/src/web/pages/extras/trashcanpage.jsx @@ -62,6 +62,7 @@ import useUserSessionTimeout from 'web/hooks/useUserSessionTimeout'; import useDialogNotification from 'web/components/notification/useDialogNotification'; import DialogNotification from 'web/components/notification/dialognotification'; import ConfirmationDialog from 'web/components/dialog/confirmationdialog'; +import {DELETE_ACTION} from 'web/components/dialog/twobuttonfooter'; const Col = styled.col` width: 50%; @@ -441,6 +442,7 @@ const TrashCan = () => { rightButtonTitle={_('Confirm')} loading={isEmptyingTrash || isLoading} width="500px" + rightButtonAction={DELETE_ACTION} /> )} diff --git a/src/web/pages/users/dialog.jsx b/src/web/pages/users/dialog.jsx index e36b33333d..e25c1443d1 100644 --- a/src/web/pages/users/dialog.jsx +++ b/src/web/pages/users/dialog.jsx @@ -33,6 +33,7 @@ import Row from 'web/components/layout/row'; import useTranslation from 'web/hooks/useTranslation'; import useUserName from 'web/hooks/useUserName'; import useCapabilities from 'web/hooks/useCapabilities'; +import {DELETE_ACTION} from 'web/components/dialog/twobuttonfooter'; const Dialog = ({ roleIds: initialRoleIds = [], @@ -158,197 +159,197 @@ const Dialog = ({ const hasRadiusEnabled = settings.get('method:radius_connect').enabled; return ( - - - {({values: state, onValueChange}) => ( - - - - - - - - - - {!isEdit && ( - - - - - - {hasLdapEnabled && ( - - )} - {hasRadiusEnabled && ( - - )} - - )} - - {isEdit && ( - + + {({values: state, onValueChange}) => ( + <> + + + + + + + + + {!isEdit && ( + + - - - - - {hasLdapEnabled && ( - - )} - {hasRadiusEnabled && ( - - )} - - )} - {capabilities.mayAccess('roles') && ( - - - - )} - - {capabilities.mayAccess('groups') && ( - - + {hasLdapEnabled && ( + - - )} - - - + )} + {hasRadiusEnabled && ( + )} + + )} + + {isEdit && ( + + + + - + )} + {hasRadiusEnabled && ( + + )} + + )} + {capabilities.mayAccess('roles') && ( + + + + )} + + {capabilities.mayAccess('groups') && ( + + - {confirmationDialogVisibleSuperAdmin && ( - + + - )} - {confirmationDialogVisible && ( - - )} - - )} - - + + + + {confirmationDialogVisibleSuperAdmin && ( + + )} + {confirmationDialogVisible && ( + + )} + + )} + ); };