Skip to content

Commit

Permalink
deprecate/replace updateUserTeamRoles
Browse files Browse the repository at this point in the history
  • Loading branch information
vd1992 committed Jun 25, 2024
1 parent 7e2d841 commit 7c660bb
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 22 deletions.
5 changes: 4 additions & 1 deletion api/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,10 @@ type Mutation {
@canFind(ability: "delete", find: "id")
updateUserTeamRoles(
teamRoleAssignments: UpdateUserTeamRolesInput! @spread
): Team @guard @canFind(ability: "assignTeamMembers", find: "teamId")
): Team
@guard
@canFind(ability: "assignTeamMembers", find: "teamId")
@deprecated(reason: "use updateUserRoles")

# Notifications
markNotificationAsRead(id: UUID!): Notification @guard # can only affect notifications belonging to the logged-in user
Expand Down
2 changes: 1 addition & 1 deletion api/storage/app/lighthouse-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ type Mutation {
createTeam(team: CreateTeamInput!): Team
updateTeam(id: UUID!, team: UpdateTeamInput!): Team
deleteTeam(id: UUID!): Team
updateUserTeamRoles(teamRoleAssignments: UpdateUserTeamRolesInput!): Team
updateUserTeamRoles(teamRoleAssignments: UpdateUserTeamRolesInput!): Team @deprecated(reason: "use updateUserRoles")
markNotificationAsRead(id: UUID!): Notification
markNotificationAsUnread(id: UUID!): Notification
deleteNotification(id: UUID!): Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ AddTeamMemberDialogProps) => {

const handleSave = async (formValues: TeamMemberFormValues) => {
await executeMutation({
teamRoleAssignments: {
updateUserRolesInput: {
userId: formValues.userId,
teamId: formValues.teamId,
roleAssignments: {
roleAssignmentsInput: {
attach: {
roles: formValues.roles,
team: formValues.teamId,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ const EditTeamMemberDialog = ({ user, team }: EditTeamMemberDialogProps) => {
const { roles, fetching } = useAvailableRoles();
const [, executeMutation] = useMutation(UpdateUserTeamRoles_Mutation);
const [isOpen, setIsOpen] = useState<boolean>(false);
const initialRolesIds = user.roles.map((role) => role.id);

const methods = useForm<TeamMemberFormValues>({
defaultValues: {
userId: user.id,
userDisplay: user.id,
teamId: team.id,
teamDisplay: team.id,
roles: user.roles.map((role) => role.id),
roles: initialRolesIds,
},
});

Expand All @@ -52,14 +53,29 @@ const EditTeamMemberDialog = ({ user, team }: EditTeamMemberDialogProps) => {
} = methods;

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

await executeMutation({
teamRoleAssignments: {
updateUserRolesInput: {
userId: formValues.userId,
teamId: formValues.teamId,
roleAssignments: {
attach: {
roles: formValues.roles,
},
roleAssignmentsInput: {
attach: rolesToAttach.length
? {
roles: rolesToAttach,
team: team.id,
}
: undefined,
detach: rolesToDetach.length
? {
roles: rolesToDetach,
team: team.id,
}
: undefined,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ const RemoveTeamMemberDialog = ({

const handleRemove = async () => {
await executeMutation({
teamRoleAssignments: {
updateUserRolesInput: {
userId: user.id,
teamId: team.id,
roleAssignments: {
roleAssignmentsInput: {
detach: {
roles: user.roles.map((role) => role.id),
team: team.id,
},
},
},
Expand Down
23 changes: 16 additions & 7 deletions apps/web/src/pages/Teams/TeamMembersPage/components/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@ import { graphql } from "@gc-digital-talent/graphql";

// eslint-disable-next-line import/prefer-default-export
export const UpdateUserTeamRoles_Mutation = graphql(/* GraphQL */ `
mutation UpdateUserTeamRoles(
$teamRoleAssignments: UpdateUserTeamRolesInput!
) {
updateUserTeamRoles(teamRoleAssignments: $teamRoleAssignments) {
mutation UpdateUserRoles($updateUserRolesInput: UpdateUserRolesInput!) {
updateUserRoles(updateUserRolesInput: $updateUserRolesInput) {
id
roleAssignments {
id
role {
id
name
isTeamBased
displayName {
en
fr
}
}
user {
team {
id
firstName
lastName
name
displayName {
en
fr
}
}
}
}
Expand Down

0 comments on commit 7c660bb

Please sign in to comment.