-
Notifications
You must be signed in to change notification settings - Fork 330
/
Copy pathOrganizationMembers.tsx
169 lines (163 loc) · 5.71 KB
/
OrganizationMembers.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import { useOrganization } from '@clerk/shared/react';
import { NotificationCountBadge, useProtect } from '../../common';
import { useEnvironment, useOrganizationProfileContext } from '../../contexts';
import { Button, Col, descriptors, Flex, localizationKeys } from '../../customizables';
import {
Animated,
Card,
Header,
Tab,
TabPanel,
TabPanels,
Tabs,
TabsList,
useCardState,
withCardStateProvider,
} from '../../elements';
import { Action } from '../../elements/Action';
import { mqu, type ThemableCssProp } from '../../styledSystem';
import { ActiveMembersList } from './ActiveMembersList';
import { InviteMembersScreen } from './InviteMembersScreen';
import { MembershipWidget } from './MembershipWidget';
import { OrganizationMembersTabInvitations } from './OrganizationMembersTabInvitations';
import { OrganizationMembersTabRequests } from './OrganizationMembersTabRequests';
export const InviteMembersButton = (props: { sx?: ThemableCssProp }) => {
return (
<Button
{...props}
elementDescriptor={descriptors.membersPageInviteButton}
aria-label='Invite'
textVariant='buttonSmall'
localizationKey={localizationKeys('organizationProfile.membersPage.action__invite')}
/>
);
};
export const OrganizationMembers = withCardStateProvider(() => {
const { organizationSettings } = useEnvironment();
const card = useCardState();
const canManageMemberships = useProtect({ permission: 'org:sys_memberships:manage' });
const canReadMemberships = useProtect({ permission: 'org:sys_memberships:read' });
const isDomainsEnabled = organizationSettings?.domains?.enabled;
const { membershipRequests } = useOrganization({
membershipRequests: isDomainsEnabled || undefined,
});
// @ts-expect-error This property is not typed. It is used by our dashboard in order to render a billing widget.
const { __unstable_manageBillingUrl } = useOrganizationProfileContext();
if (canManageMemberships === null) {
return null;
}
return (
<Col
elementDescriptor={descriptors.page}
gap={2}
>
<Card.Alert>{card.error}</Card.Alert>
<Col
elementDescriptor={descriptors.profilePage}
elementId={descriptors.profilePage.setId('organizationMembers')}
gap={4}
>
<Action.Root animate={false}>
<Animated asChild>
<Header.Root
contentSx={{
[mqu.md]: {
flexDirection: 'row',
width: '100%',
justifyContent: 'space-between',
},
}}
>
<Header.Title
localizationKey={localizationKeys('organizationProfile.start.headerTitle__members')}
textVariant='h2'
/>
{canManageMemberships && (
<Action.Trigger value='invite'>
<InviteMembersButton
sx={{
display: 'none',
[mqu.md]: {
display: 'inline-flex',
},
}}
/>
</Action.Trigger>
)}
</Header.Root>
</Animated>
{canReadMemberships && (
<Animated>
<Action.Open value='invite'>
<Action.Card>
<InviteMembersScreen />
</Action.Card>
</Action.Open>
</Animated>
)}
<Tabs>
<TabsList>
{canReadMemberships && (
<Tab localizationKey={localizationKeys('organizationProfile.membersPage.start.headerTitle__members')} />
)}
{canManageMemberships && (
<Tab
localizationKey={localizationKeys('organizationProfile.membersPage.start.headerTitle__invitations')}
/>
)}
{canManageMemberships && isDomainsEnabled && (
<Tab localizationKey={localizationKeys('organizationProfile.membersPage.start.headerTitle__requests')}>
<NotificationCountBadge notificationCount={membershipRequests?.count || 0} />
</Tab>
)}
</TabsList>
{canManageMemberships && (
<Animated asChild>
<Flex
justify='end'
sx={{
width: '100%',
marginLeft: 'auto',
[mqu.md]: {
display: 'none',
},
}}
>
<Action.Trigger value='invite'>
<InviteMembersButton />
</Action.Trigger>
</Flex>
</Animated>
)}
<TabPanels>
{canReadMemberships && (
<TabPanel sx={{ width: '100%' }}>
<Flex
gap={4}
direction='col'
sx={{
width: '100%',
}}
>
{canManageMemberships && __unstable_manageBillingUrl && <MembershipWidget />}
<ActiveMembersList />
</Flex>
</TabPanel>
)}
{canManageMemberships && (
<TabPanel sx={{ width: '100%' }}>
<OrganizationMembersTabInvitations />
</TabPanel>
)}
{canManageMemberships && isDomainsEnabled && (
<TabPanel sx={{ width: '100%' }}>
<OrganizationMembersTabRequests />
</TabPanel>
)}
</TabPanels>
</Tabs>
</Action.Root>
</Col>
</Col>
);
});