Skip to content

Commit

Permalink
feat(web): remove multiple user-members from workspace (#1282)
Browse files Browse the repository at this point in the history
* feat: remove multiple user-members from workspace

* rename the mutation names
  • Loading branch information
nourbalaha authored Oct 24, 2024
1 parent 935ca4d commit 3cf2254
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 84 deletions.
41 changes: 22 additions & 19 deletions web/src/components/organisms/Settings/Members/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
useAddUsersToWorkspaceMutation,
useUpdateMemberOfWorkspaceMutation,
Role,
useRemoveMemberFromWorkspaceMutation,
useRemoveMultipleMembersFromWorkspaceMutation,
Workspace as GQLWorkspace,
useGetUserBySearchLazyQuery,
MemberInput as GQLMemberInput,
Expand Down Expand Up @@ -171,38 +171,34 @@ export default () => {
[workspaceId, updateMemberOfWorkspaceMutation, t, setWorkspace],
);

const [removeMemberFromWorkspaceMutation] = useRemoveMemberFromWorkspaceMutation();
const [RemoveMultipleMembersFromWorkspaceMutation] =
useRemoveMultipleMembersFromWorkspaceMutation();

const handleMemberRemoveFromWorkspace = useCallback(
async (userIds: string[]) => {
if (!workspaceId) return;
const results = await Promise.all(
userIds.map(async userId => {
const result = await removeMemberFromWorkspaceMutation({
variables: { workspaceId, userId },
});
if (result.errors) {
Notification.error({
message: t("Failed to remove member(s) from the workspace."),
});
}
}),
);
if (results) {
const result = await RemoveMultipleMembersFromWorkspaceMutation({
variables: { workspaceId, userIds },
});
if (result.errors) {
Notification.error({
message: t("Failed to remove member(s) from the workspace."),
});
} else {
Notification.success({
message: t("Successfully removed member(s) from the workspace!"),
});
setSelection({ selectedRowKeys: [] });
}
},
[workspaceId, removeMemberFromWorkspaceMutation, t],
[workspaceId, RemoveMultipleMembersFromWorkspaceMutation, t],
);

const handleLeave = useCallback(
async (userId: string) => {
if (!workspaceId) return;
const result = await removeMemberFromWorkspaceMutation({
variables: { workspaceId, userId },
const result = await RemoveMultipleMembersFromWorkspaceMutation({
variables: { workspaceId, userIds: [userId] },
});
if (result.errors) {
Notification.error({
Expand All @@ -216,7 +212,14 @@ export default () => {
navigate(`/workspace/${me.myWorkspace}`);
}
},
[workspaceId, removeMemberFromWorkspaceMutation, t, refetchMe, navigate, me.myWorkspace],
[
workspaceId,
RemoveMultipleMembersFromWorkspaceMutation,
t,
refetchMe,
navigate,
me.myWorkspace,
],
);

const handleRoleModalClose = useCallback(() => {
Expand Down
1 change: 1 addition & 0 deletions web/src/gql/fragmentMatcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"SchemaFieldGroup",
"SchemaFieldInteger",
"SchemaFieldMarkdown",
"SchemaFieldNumber",
"SchemaFieldReference",
"SchemaFieldRichText",
"SchemaFieldSelect",
Expand Down
Loading

0 comments on commit 3cf2254

Please sign in to comment.