Skip to content

Commit

Permalink
remove sync from RoleAssignmentHasMany
Browse files Browse the repository at this point in the history
  • Loading branch information
vd1992 committed Jun 25, 2024
1 parent 81dd930 commit 7e2d841
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
1 change: 0 additions & 1 deletion api/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,6 @@ input RolesInput
input RoleAssignmentHasMany {
attach: RolesInput
detach: RolesInput
sync: RolesInput
}

# This input only accepts Team-Based roles. It is assumed that a team id will be provided at a higher level of input.
Expand Down
1 change: 0 additions & 1 deletion api/storage/app/lighthouse-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,6 @@ input RolesInput {
input RoleAssignmentHasMany {
attach: RolesInput
detach: RolesInput
sync: RolesInput
}

input RolesForTeamInput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ const EditTeamRoleDialog = ({
const [isOpen, setIsOpen] = useState<boolean>(false);
const userDisplayName = getFullNameHtml(user.firstName, user.lastName, intl);
const teamDisplayName = getLocalizedName(team.displayName, intl);
const initialRolesIds = initialRoles.map((role) => role.id);

const methods = useForm<FormValues>({
defaultValues: {
roles: initialRoles.map((role) => role.id),
roles: initialRolesIds,
},
});

Expand All @@ -61,13 +62,28 @@ const EditTeamRoleDialog = ({
} = methods;

const handleEditRoles = async (formValues: FormValues) => {
const rolesToAttach = formValues.roles.filter(
(role) => !initialRolesIds.includes(role),
);
const rolesToDetach = initialRolesIds.filter(
(role) => !formValues.roles.includes(role),
);

return onEditRoles({
userId: user.id,
roleAssignmentsInput: {
sync: {
roles: formValues.roles,
team: team.id,
},
attach: rolesToAttach.length
? {
roles: rolesToAttach,
team: team.id,
}
: undefined,
detach: rolesToDetach.length
? {
roles: rolesToDetach,
team: team.id,
}
: undefined,
},
})
.then(() => {
Expand Down

0 comments on commit 7e2d841

Please sign in to comment.