From c19cde985e303153c90fad7d82d843a6cf3c3b7c Mon Sep 17 00:00:00 2001 From: Bill Nguyen Date: Fri, 24 May 2024 17:17:34 -0700 Subject: [PATCH] - DEVSU-2300 - Add shouldDirty flag to setValue of user copy feature to set the new added values as dirty fields in form state --- .../components/AddEditUserDialog/index.tsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/views/AdminView/components/Users/components/AddEditUserDialog/index.tsx b/app/views/AdminView/components/Users/components/AddEditUserDialog/index.tsx index 57491ed8..6c82d878 100644 --- a/app/views/AdminView/components/Users/components/AddEditUserDialog/index.tsx +++ b/app/views/AdminView/components/Users/components/AddEditUserDialog/index.tsx @@ -118,6 +118,19 @@ const AddEditUserDialog = ({ } }, [editData, groupOptions, projectOptions, setValue]); + const handleCopyUserPermissions = useCallback(async (user) => { + const userResp = await api.get(`/user/${user.ident}`, {}).request(); + const copiedProjectsAndGroups = (({ projects, groups }) => ({ projects, groups }))(userResp); + copiedProjectsAndGroups.groups = copiedProjectsAndGroups.groups.filter((group: { name: string; }) => (group.name !== 'admin')); // Remove possible admin from copied groups + Object.entries(copiedProjectsAndGroups).forEach(([key, val]) => { + let nextVal = val; + if (Array.isArray(val)) { + nextVal = val.map(({ ident }) => ident); + } + setValue(key as keyof UserForm, nextVal as string | string[], { shouldDirty: true }); + }); + }, [setValue]); + const handleClose = useCallback(async (formData: UserForm) => { setIsApiCalling(true); const { @@ -211,19 +224,6 @@ const AddEditUserDialog = ({ onClose(null); }, [dirtyFields, editData, onClose, projectOptions, groupOptions]); - const handleCopyUserPermissions = useCallback(async (user) => { - const userResp = await api.get(`/user/${user.ident}`, {}).request(); - const copiedProjectsAndGroups = (({ projects, groups }) => ({ projects, groups }))(userResp); - copiedProjectsAndGroups.groups = copiedProjectsAndGroups.groups.filter((group: { name: string; }) => (group.name !== 'admin')); // Remove possible admin from copied groups - Object.entries(copiedProjectsAndGroups).forEach(([key, val]) => { - let nextVal = val; - if (Array.isArray(val)) { - nextVal = val.map(({ ident }) => ident); - } - setValue(key as keyof UserForm, nextVal as string | string[]); - }); - }, [setValue]); - // Email error text let emailErrorText = ''; if (formErrors.email) {