From 47c5618fb6279f8d1fe7ab874b73878668620a97 Mon Sep 17 00:00:00 2001 From: SteveGT96 Date: Fri, 29 Nov 2024 11:04:29 +0100 Subject: [PATCH] update(OH2-443): Refactor user / group reset/cancel operations --- .../admin/users/editGroup/EditGroup.tsx | 78 +++++++++++++++---- .../admin/users/editGroup/styles.scss | 33 +++++++- .../admin/users/editUser/EditUserForm.tsx | 65 +++++++++++++--- .../admin/users/editUser/styles.scss | 27 +++++++ .../admin/users/newGroup/NewGroup.tsx | 65 +++++++++++++--- .../admin/users/newGroup/styles.scss | 27 +++++++ .../admin/users/newUser/NewUser.tsx | 65 +++++++++++++--- .../admin/users/newUser/styles.scss | 27 +++++++ src/resources/i18n/en.json | 4 +- 9 files changed, 344 insertions(+), 47 deletions(-) diff --git a/src/components/accessories/admin/users/editGroup/EditGroup.tsx b/src/components/accessories/admin/users/editGroup/EditGroup.tsx index 8563e118e..e71f18c8f 100644 --- a/src/components/accessories/admin/users/editGroup/EditGroup.tsx +++ b/src/components/accessories/admin/users/editGroup/EditGroup.tsx @@ -15,6 +15,7 @@ import TextField from "../../../textField/TextField"; import { PATHS } from "../../../../../consts"; import { usePermission } from "../../../../../libraries/permissionUtils/usePermission"; +import { Cancel } from "@mui/icons-material"; import { CircularProgress } from "@mui/material"; import CheckboxField from "components/accessories/checkboxField/CheckboxField"; import { PermissionDTO } from "generated/models/PermissionDTO"; @@ -45,6 +46,8 @@ export const EditGroup = () => { const [openResetConfirmation, setOpenResetConfirmation] = useState(false); + const [openCancelConfirmation, setOpenCancelConfirmation] = useState(false); + const update = useAppSelector((state) => state.usergroups.update); const permissions = useAppSelector((state) => state.permissions.getAll); const group = useAppSelector((state) => state.usergroups.currentGroup); @@ -133,10 +136,29 @@ export const EditGroup = () => { }; }, []); - const handleResetConfirmation = () => { + const handleResetConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenResetConfirmation(value); + }, + [setOpenResetConfirmation] + ); + + const handleCancelConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenCancelConfirmation(value); + }, + [setOpenCancelConfirmation] + ); + + const handleResetConfirmation = useCallback(() => { setOpenResetConfirmation(false); + resetForm(); + }, [navigate, resetForm, setOpenResetConfirmation]); + + const handleCancelConfirmation = useCallback(() => { + setOpenCancelConfirmation(false); navigate(-1); - }; + }, [navigate, setOpenCancelConfirmation]); const handleCheckboxChange = useCallback( (fieldName: string) => (value: boolean) => { @@ -168,10 +190,24 @@ export const EditGroup = () => { permissions.isLoading ? ( ) : ( -
-
+
+
+
+ +
+
+
-
+
{ disabled />
-
+
{ />
-
+
{ /> )} -
+
{isPermissionEditorAvailable && updatedPermissionsStack.length > 0 && (

@@ -249,7 +285,7 @@ export const EditGroup = () => { )}

-
+
+ setOpenResetConfirmation(false)} + handleSecondaryButtonClick={handleResetConfirmationDialog(false)} /> { const { passwd2, ...userDTO } = values; if (userDTO.passwd === undefined) { @@ -65,6 +68,7 @@ export const EditUserForm = ({ errors, touched, values, + resetForm, setFieldTouched, setFieldValue, } = useFormik({ @@ -73,10 +77,29 @@ export const EditUserForm = ({ onSubmit: handleFormSubmit, }); - const handleResetConfirmation = () => { + const handleResetConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenResetConfirmation(value); + }, + [setOpenResetConfirmation] + ); + + const handleCancelConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenCancelConfirmation(value); + }, + [setOpenCancelConfirmation] + ); + + const handleResetConfirmation = useCallback(() => { setOpenResetConfirmation(false); + resetForm(); + }, [navigate, resetForm, setOpenResetConfirmation]); + + const handleCancelConfirmation = useCallback(() => { + setOpenCancelConfirmation(false); navigate(-1); - }; + }, [navigate, setOpenCancelConfirmation]); const handleCheckboxChange = useCallback( (fieldName: string) => (value: boolean) => { @@ -87,6 +110,20 @@ export const EditUserForm = ({ return (
+
+
+ +
+
@@ -199,26 +236,36 @@ export const EditUserForm = ({
+ setOpenResetConfirmation(false)} + handleSecondaryButtonClick={handleResetConfirmationDialog(false)} /> { const [openResetConfirmation, setOpenResetConfirmation] = useState(false); + const [openCancelConfirmation, setOpenCancelConfirmation] = useState(false); + const create = useAppSelector((state) => state.usergroups.create); const { @@ -46,6 +49,7 @@ export const NewGroup = () => { errors, touched, values, + resetForm, setFieldValue, } = useFormik({ initialValues, @@ -61,10 +65,29 @@ export const NewGroup = () => { }; }, [dispatch]); - const handleResetConfirmation = () => { + const handleResetConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenResetConfirmation(value); + }, + [setOpenResetConfirmation] + ); + + const handleCancelConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenCancelConfirmation(value); + }, + [setOpenCancelConfirmation] + ); + + const handleResetConfirmation = useCallback(() => { setOpenResetConfirmation(false); + resetForm(); + }, [navigate, resetForm, setOpenResetConfirmation]); + + const handleCancelConfirmation = useCallback(() => { + setOpenCancelConfirmation(false); navigate(-1); - }; + }, [navigate, setOpenCancelConfirmation]); const handleCheckboxChange = useCallback( (fieldName: string) => (value: boolean) => { @@ -75,6 +98,20 @@ export const NewGroup = () => { return (
+
+
+ +
+
@@ -130,26 +167,36 @@ export const NewGroup = () => {
+ setOpenResetConfirmation(false)} + handleSecondaryButtonClick={handleResetConfirmationDialog(false)} /> { const [openResetConfirmation, setOpenResetConfirmation] = useState(false); + const [openCancelConfirmation, setOpenCancelConfirmation] = useState(false); + const create = useAppSelector((state) => state.users.create); const userGroupsTypeState = useAppSelector( @@ -60,6 +63,7 @@ export const NewUser = () => { errors, touched, values, + resetForm, } = useFormik({ initialValues, validationSchema: userSchema(t), @@ -80,10 +84,29 @@ export const NewUser = () => { }; }, [create.hasSucceeded, dispatch, navigate]); - const handleResetConfirmation = () => { + const handleResetConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenResetConfirmation(value); + }, + [setOpenResetConfirmation] + ); + + const handleCancelConfirmationDialog = useCallback( + (value: boolean) => () => { + setOpenCancelConfirmation(value); + }, + [setOpenCancelConfirmation] + ); + + const handleResetConfirmation = useCallback(() => { setOpenResetConfirmation(false); + resetForm(); + }, [navigate, resetForm, setOpenResetConfirmation]); + + const handleCancelConfirmation = useCallback(() => { + setOpenCancelConfirmation(false); navigate(-1); - }; + }, [navigate, setOpenCancelConfirmation]); const handleCheckboxChange = useCallback( (fieldName: string) => (value: boolean) => { @@ -94,6 +117,20 @@ export const NewUser = () => { return (
+
+
+ +
+
@@ -207,13 +244,13 @@ export const NewUser = () => {
@@ -229,14 +266,24 @@ export const NewUser = () => { handleSecondaryButtonClick={() => ({})} /> + setOpenResetConfirmation(false)} + handleSecondaryButtonClick={handleResetConfirmationDialog(false)} />