Skip to content

Commit

Permalink
- DEVSU-2300
Browse files Browse the repository at this point in the history
- Add shouldDirty flag to setValue of user copy feature to set the new added values as dirty fields in form state
  • Loading branch information
bnguyen-bcgsc committed May 25, 2024
1 parent f51ac60 commit c19cde9
Showing 1 changed file with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c19cde9

Please sign in to comment.