-
Notifications
You must be signed in to change notification settings - Fork 5
/
TeamMembersTable.tsx
105 lines (100 loc) · 3.29 KB
/
TeamMembersTable.tsx
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
96
97
98
99
100
101
102
103
104
105
import { Avatar, Flex, Group, Select, Text } from "@mantine/core"
import { DataTable } from "~/components/DataTable"
import Identicon from "~/components/Identicon"
import { Account, RoleName, User } from "~/models/portal/sdk"
import TeamMemberAction from "~/routes/account.$accountId.settings.members/components/TeamMemberAction"
import useTeamModals from "~/routes/account.$accountId.settings.members/hooks/useTeamModals"
import { capitalizeFirstLetter } from "~/utils/utils"
type TeamMembersTableProps = {
account: Account
userRole: RoleName | null
user?: User
}
const TeamMembersTable = ({ account, userRole, user }: TeamMembersTableProps) => {
const { openChangeRoleModal } = useTeamModals({ account })
const teamData = account.users.sort(
(a, b) => Number(b.roleName === "OWNER") - Number(a.roleName === "OWNER"),
)
return (
<DataTable
columns={["Member", "Roles", "Status", ""]}
data={teamData.map(({ email, roleName, accepted, id }, index) => {
return {
member: {
element: (
<Group>
<Avatar radius="xl">
<Identicon
alt={`${id} profile picture`}
seed={id}
size="md"
type="user"
/>
</Avatar>
<Text> {email} </Text>
</Group>
),
},
role: {
element:
roleName === RoleName.Owner ? (
<Text> Owner </Text>
) : userRole !== RoleName.Member ? (
<Flex>
<Select
data={[
{
value: RoleName.Member,
label: "Member",
},
{
value: RoleName.Admin,
label: "Admin",
},
]}
disabled={!accepted}
value={roleName}
onChange={(value) => {
if (value !== roleName) {
openChangeRoleModal({ email, id, roleName: value as RoleName })
}
}}
/>
</Flex>
) : (
<Text> {capitalizeFirstLetter(roleName)} </Text>
),
},
status: {
element: (
<Text
c={
roleName === RoleName.Owner
? "var(--text-color)"
: accepted
? "var(--mantine-color-green-6)"
: "var(--mantine-color-yellow-7)"
}
>
{roleName === RoleName.Owner ? "-" : accepted ? "Accepted" : "Pending"}
</Text>
),
},
action: {
element: roleName !== RoleName.Owner && (
<TeamMemberAction
account={account}
status={accepted}
teamMember={teamData[index]}
user={user}
userRole={userRole}
/>
),
},
}
})}
paginate={teamData.length > 10 ? { perPage: 10 } : false}
/>
)
}
export default TeamMembersTable