Skip to content

Commit

Permalink
feat: Add thunk to delete user from project
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Oct 18, 2023
1 parent fe41d24 commit 67a5d10
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/project/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type {
ProjectArchiveMutationInput,
ProjectDataFragment,
ProjectDeleteMutationInput,
ProjectDeleteUserMutationInput,
ProjectMembershipFieldsFragment,
ProjectUpdateMutationInput,
ProjectUpdateUserRoleMutationInput,
Expand Down Expand Up @@ -237,3 +238,32 @@ export const updateUserRole = (input: ProjectUpdateUserRoleMutationInput) => {
}),
);
};

export const deleteUserFromProject = (
input: ProjectDeleteUserMutationInput,
) => {
const command = graphql(`
mutation removeUser($input: ProjectDeleteUserMutationInput!) {
deleteUserFromProject(input: $input) {
membership {
id
}
project {
id
}
}
}
`);

return terrasoApi.requestGraphQL(command, { input }).then(
({
deleteUserFromProject: {
project: { id: projectId },
membership: { id: membershipId },
},
}) => ({
projectId,
membershipId,
}),
);
};
12 changes: 12 additions & 0 deletions src/project/projectSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ const projectSlice = createSlice({
state.projects[projectId].memberships[membershipId].userRole = userRole;
},
);

builder.addCase(
deleteUserFromProject.fulfilled,
(state, { payload: { projectId, membershipId } }) => {
delete state.projects[projectId].memberships[membershipId];
},
);
},
});

Expand Down Expand Up @@ -221,4 +228,9 @@ export const updateUserRole = createAsyncThunk(
projectService.updateUserRole,
);

export const deleteUserFromProject = createAsyncThunk(
'project/deleteUserFromProject',
projectService.deleteUserFromProject,
);

export default projectSlice.reducer;

0 comments on commit 67a5d10

Please sign in to comment.