-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathremove-member.tsx
More file actions
95 lines (91 loc) · 2.82 KB
/
remove-member.tsx
File metadata and controls
95 lines (91 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import type { SearchOrganizationUsersResponse_OrganizationUser } from "@raystack/proton/frontier";
import {
FrontierServiceQueries,
RemoveOrganizationUserRequestSchema,
} from "@raystack/proton/frontier";
import { create } from "@bufbuild/protobuf";
import { useMutation } from "@connectrpc/connect-query";
import { Button, Dialog, Flex, Text, toast } from "@raystack/apsara";
import { ConnectError } from "@connectrpc/connect";
interface RemoveMemberProps {
organizationId: string;
user?: SearchOrganizationUsersResponse_OrganizationUser;
onRemove: (user: SearchOrganizationUsersResponse_OrganizationUser) => void;
onClose: () => void;
}
export const RemoveMember = ({
organizationId,
user,
onRemove,
onClose,
}: RemoveMemberProps) => {
const { mutateAsync: removeOrganizationUser, isPending } = useMutation(
FrontierServiceQueries.removeOrganizationUser,
);
async function onSubmit() {
try {
if (!user) return;
await removeOrganizationUser(
create(RemoveOrganizationUserRequestSchema, {
id: organizationId,
userId: user?.id || "",
}),
);
if (onRemove) {
onRemove(user);
}
toast.success("Member removed successfully");
} catch (error) {
const message =
error instanceof ConnectError
? error.message
: "Unknown error";
toast.error(`Failed to remove member: ${message}`);
console.error(error);
}
}
return (
<Dialog open onOpenChange={onClose}>
<Dialog.Content width={400}>
<Dialog.Header>
<Dialog.Title>Remove Member</Dialog.Title>
<Dialog.CloseButton data-test-id="remove-member-close-button" />
</Dialog.Header>
<Dialog.Body>
<Flex direction="column" gap={7}>
<Text variant="secondary">
Removing this member will revoke all their access to the
organization. This action cannot be undone. The member will lose
all assigned roles and permissions immediately.
</Text>
<Text variant="secondary">
Are you sure you want to remove this member?
</Text>
</Flex>
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close asChild>
<Button
type="button"
variant="outline"
color="neutral"
data-test-id="remove-member-cancel-button"
>
Cancel
</Button>
</Dialog.Close>
<Button
type="submit"
data-test-id="remove-member-submit-button"
color="danger"
loading={isPending}
loaderText="Removing..."
onClick={onSubmit}
>
Remove
</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog>
);
};