@krak-stack/auth 0.1.48 → 0.1.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/admin-organizations.js +6 -2
- package/dist/components/admin-users.js +80 -73
- package/dist/components/auth-client-api.d.ts +132 -132
- package/dist/components/index.d.ts +2 -2
- package/dist/components/index.js +1 -1
- package/dist/components/invitation-expiration.d.ts +8 -0
- package/dist/components/invitation-expiration.js +24 -0
- package/dist/components/member-required.d.ts +45 -0
- package/dist/components/{admin-required.js → member-required.js} +56 -54
- package/dist/components/organization-switcher.d.ts +16 -6
- package/dist/components/organization-switcher.js +153 -59
- package/dist/components/user-button.js +10 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/components/admin-required.d.ts +0 -43
|
@@ -8,34 +8,37 @@ import { Button } from "@/components/ui/button";
|
|
|
8
8
|
import { CopyButton } from "@/components/ui/copy-button";
|
|
9
9
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card";
|
|
10
10
|
import { useKrakstackAuth } from "./auth-provider";
|
|
11
|
+
import { isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration";
|
|
11
12
|
const defaultMessages = {
|
|
12
13
|
en: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
member_required_title: "Organization access required",
|
|
15
|
+
member_required_description: "You need organization access to continue.",
|
|
16
|
+
member_required_org_description: "You need access to {organization} before opening the admin area.",
|
|
17
|
+
member_required_no_permission: "Your account is signed in, but it does not have access to this organization.",
|
|
18
|
+
member_required_invite_found: "You have a pending invitation to {organization}. Accept it to continue.",
|
|
19
|
+
member_required_invite_expired: "Your invitation to {organization} has expired. Contact the organization administrator for a new invitation.",
|
|
20
|
+
member_required_accept_invite: "Accept invitation",
|
|
21
|
+
member_required_accepting_invite: "Accepting...",
|
|
22
|
+
member_required_accept_error: "Could not accept the invitation.",
|
|
23
|
+
member_required_contact: "Contact organization",
|
|
24
|
+
member_required_contact_description: "If you expected access, contact the organization administrator.",
|
|
25
|
+
member_required_copy_email: "Copy email",
|
|
26
|
+
member_required_copied_email: "Copied email",
|
|
25
27
|
},
|
|
26
28
|
fr: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
29
|
+
member_required_title: "Accès à l'organisation requis",
|
|
30
|
+
member_required_description: "Vous devez disposer d'un accès à l'organisation pour continuer.",
|
|
31
|
+
member_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.",
|
|
32
|
+
member_required_no_permission: "Votre compte est connecté, mais il ne dispose pas d'un accès à cette organisation.",
|
|
33
|
+
member_required_invite_found: "Vous avez une invitation en attente pour {organization}. Acceptez-la pour continuer.",
|
|
34
|
+
member_required_invite_expired: "Votre invitation pour {organization} a expiré. Contactez l'administrateur de l'organisation pour obtenir une nouvelle invitation.",
|
|
35
|
+
member_required_accept_invite: "Accepter l'invitation",
|
|
36
|
+
member_required_accepting_invite: "Acceptation...",
|
|
37
|
+
member_required_accept_error: "Impossible d'accepter l'invitation.",
|
|
38
|
+
member_required_contact: "Contacter l'organisation",
|
|
39
|
+
member_required_contact_description: "Si vous pensiez avoir accès, contactez l'administrateur de l'organisation.",
|
|
40
|
+
member_required_copy_email: "Copier l'e-mail",
|
|
41
|
+
member_required_copied_email: "E-mail copié",
|
|
39
42
|
},
|
|
40
43
|
};
|
|
41
44
|
const isFullOrganization = (value) => {
|
|
@@ -57,7 +60,8 @@ const labels = (locale, overrides) => ({
|
|
|
57
60
|
...(locale === "fr" ? defaultMessages.fr : defaultMessages.en),
|
|
58
61
|
...overrides,
|
|
59
62
|
});
|
|
60
|
-
const invitationMatches = (invitation, organizationId) => invitation.status === "pending" &&
|
|
63
|
+
const invitationMatches = (invitation, organizationId) => invitation.status === "pending" &&
|
|
64
|
+
invitation.organizationId === organizationId;
|
|
61
65
|
const organizationContactEmail = (organization, fallback) => organization?.contactEmail ?? fallback ?? null;
|
|
62
66
|
const organizationDisplayName = (invitation, organization, fallback) => organization?.displayName ??
|
|
63
67
|
organization?.name ??
|
|
@@ -81,16 +85,14 @@ const getOrganizationPublicProfile = async (baseUrl, organizationId) => {
|
|
|
81
85
|
return isFullOrganization(body) ? body : null;
|
|
82
86
|
};
|
|
83
87
|
const accessAtom = Atom.family((authClient) => Atom.family((key) => {
|
|
84
|
-
const { baseUrl,
|
|
88
|
+
const { baseUrl, organizationId } = JSON.parse(key);
|
|
85
89
|
return Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
86
90
|
try: async () => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return { allowed: true };
|
|
93
|
-
}
|
|
91
|
+
const activeResult = await authClient.organization.setActive({
|
|
92
|
+
organizationId,
|
|
93
|
+
});
|
|
94
|
+
if (!activeResult.error)
|
|
95
|
+
return { allowed: true };
|
|
94
96
|
const [organization, invitationsResult] = await Promise.all([
|
|
95
97
|
getOrganizationPublicProfile(baseUrl, organizationId).catch(() => null),
|
|
96
98
|
authClient.organization.listUserInvitations({}),
|
|
@@ -104,11 +106,12 @@ const accessAtom = Atom.family((authClient) => Atom.family((key) => {
|
|
|
104
106
|
catch: (error) => error,
|
|
105
107
|
})));
|
|
106
108
|
}));
|
|
107
|
-
const accessAtomKey = ({
|
|
108
|
-
export function
|
|
109
|
+
const accessAtomKey = ({ authRefreshVersion, baseUrl, organizationId, userId, }) => JSON.stringify({ authRefreshVersion, baseUrl, organizationId, userId });
|
|
110
|
+
export function MemberRequired({ authClient: providedAuthClient, organizationId, contactEmail, children, messages, }) {
|
|
109
111
|
const auth = useKrakstackAuth();
|
|
110
112
|
const authClient = providedAuthClient ?? auth?.authClient;
|
|
111
113
|
const baseUrl = auth?.baseUrl;
|
|
114
|
+
const authRefreshVersion = auth?.authRefreshVersion ?? 0;
|
|
112
115
|
const locale = auth?.locale;
|
|
113
116
|
const refreshAuth = auth?.refreshAuth;
|
|
114
117
|
if (!authClient) {
|
|
@@ -116,21 +119,18 @@ export function AdminRequired({ authClient: providedAuthClient, organizationId,
|
|
|
116
119
|
}
|
|
117
120
|
const session = authClient.useSession();
|
|
118
121
|
const userId = session.data?.user.id;
|
|
119
|
-
const role = session.data?.user.role;
|
|
120
|
-
const isAdmin = typeof role === "string" &&
|
|
121
|
-
role.split(",").some((item) => item.trim() === "admin");
|
|
122
122
|
const currentAccessKey = accessAtomKey({
|
|
123
|
+
authRefreshVersion,
|
|
123
124
|
baseUrl,
|
|
124
|
-
isAdmin,
|
|
125
125
|
organizationId,
|
|
126
126
|
userId,
|
|
127
127
|
});
|
|
128
128
|
const [allowedAccessKey, setAllowedAccessKey] = useState(null);
|
|
129
129
|
if (allowedAccessKey === currentAccessKey)
|
|
130
130
|
return _jsx(_Fragment, { children: children });
|
|
131
|
-
return (_jsx(
|
|
131
|
+
return (_jsx(MemberRequiredGate, { accessKey: currentAccessKey, authClient: authClient, contactEmail: contactEmail, locale: locale, messages: messages, onAccessAllowed: () => setAllowedAccessKey(currentAccessKey), organizationId: organizationId, refreshAuth: refreshAuth, children: children }));
|
|
132
132
|
}
|
|
133
|
-
function
|
|
133
|
+
function MemberRequiredGate({ accessKey, authClient, contactEmail, children, locale, messages, onAccessAllowed, organizationId, refreshAuth, }) {
|
|
134
134
|
const m = labels(locale, messages);
|
|
135
135
|
const accessResult = useAtomSuspense(accessAtom(authClient)(accessKey), {
|
|
136
136
|
suspendOnWaiting: true,
|
|
@@ -138,6 +138,7 @@ function AdminRequiredGate({ accessKey, authClient, contactEmail, children, isAd
|
|
|
138
138
|
const [accepting, setAccepting] = useState(false);
|
|
139
139
|
const [error, setError] = useState(null);
|
|
140
140
|
const access = accessResult.value;
|
|
141
|
+
const invitationNow = useInvitationExpirationClock(access.allowed || !access.invitation ? [] : [access.invitation]);
|
|
141
142
|
useEffect(() => {
|
|
142
143
|
if (!access.allowed)
|
|
143
144
|
return;
|
|
@@ -146,10 +147,13 @@ function AdminRequiredGate({ accessKey, authClient, contactEmail, children, isAd
|
|
|
146
147
|
if (access.allowed)
|
|
147
148
|
return _jsx(_Fragment, { children: children });
|
|
148
149
|
const { invitation, organization } = access;
|
|
150
|
+
const invitationExpired = invitation
|
|
151
|
+
? isInvitationExpired(invitation, invitationNow)
|
|
152
|
+
: false;
|
|
149
153
|
const displayName = organizationDisplayName(invitation, organization, organizationId);
|
|
150
154
|
const resolvedContactEmail = organizationContactEmail(organization, contactEmail);
|
|
151
155
|
const acceptInvitation = async () => {
|
|
152
|
-
if (!invitation)
|
|
156
|
+
if (!invitation || isInvitationExpired(invitation))
|
|
153
157
|
return;
|
|
154
158
|
setAccepting(true);
|
|
155
159
|
setError(null);
|
|
@@ -158,7 +162,7 @@ function AdminRequiredGate({ accessKey, authClient, contactEmail, children, isAd
|
|
|
158
162
|
});
|
|
159
163
|
if (result.error) {
|
|
160
164
|
setAccepting(false);
|
|
161
|
-
setError(result.error.message ?? m.
|
|
165
|
+
setError(result.error.message ?? m.member_required_accept_error);
|
|
162
166
|
return;
|
|
163
167
|
}
|
|
164
168
|
await authClient.organization.setActive({
|
|
@@ -168,16 +172,14 @@ function AdminRequiredGate({ accessKey, authClient, contactEmail, children, isAd
|
|
|
168
172
|
onAccessAllowed();
|
|
169
173
|
setAccepting(false);
|
|
170
174
|
};
|
|
171
|
-
return (_jsx("main", { className: "relative grid min-h-screen place-items-center px-6 py-10", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx("div", { className: "bg-destructive/10 text-destructive mb-2 flex size-10 items-center justify-center rounded-md", children: _jsx(ShieldAlert, {}) }), _jsx(CardTitle, { children: m.
|
|
172
|
-
? interpolate(m.admin_required_org_description, {
|
|
173
|
-
organization: displayName,
|
|
174
|
-
})
|
|
175
|
-
: m.admin_required_no_permission })] }), _jsxs(CardContent, { className: "space-y-3", children: [invitation ? (_jsx("p", { className: "text-muted-foreground text-sm", children: interpolate(m.admin_required_invite_found, {
|
|
175
|
+
return (_jsx("main", { className: "relative grid min-h-screen place-items-center px-6 py-10", children: _jsxs(Card, { className: "w-full max-w-md", children: [_jsxs(CardHeader, { children: [_jsx("div", { className: "bg-destructive/10 text-destructive mb-2 flex size-10 items-center justify-center rounded-md", children: _jsx(ShieldAlert, {}) }), _jsx(CardTitle, { children: m.member_required_title }), _jsx(CardDescription, { children: interpolate(m.member_required_org_description, {
|
|
176
176
|
organization: displayName,
|
|
177
|
-
}) })
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
}) })] }), _jsxs(CardContent, { className: "space-y-3", children: [invitation ? (_jsx("p", { className: "text-muted-foreground text-sm", children: interpolate(invitationExpired
|
|
178
|
+
? m.member_required_invite_expired
|
|
179
|
+
: m.member_required_invite_found, { organization: displayName }) })) : (_jsx("p", { className: "text-muted-foreground text-sm", children: m.member_required_contact_description })), resolvedContactEmail ? (_jsxs("div", { className: "bg-muted/50 flex items-center justify-between gap-3 rounded-md border px-3 py-2 text-sm", children: [_jsxs("span", { className: "flex min-w-0 items-center gap-2 font-medium", children: [_jsx(Mail, { className: "text-muted-foreground size-4 shrink-0" }), _jsx("span", { className: "truncate", children: resolvedContactEmail })] }), _jsx(CopyButton, { value: resolvedContactEmail, valueDescription: resolvedContactEmail, variant: "ghost", className: "shrink-0", messages: {
|
|
180
|
+
copy: m.member_required_copy_email,
|
|
181
|
+
copied: m.member_required_copied_email,
|
|
182
|
+
} })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }), _jsx(CardFooter, { className: "flex flex-wrap gap-2", children: invitation && !invitationExpired ? (_jsxs(Button, { onClick: acceptInvitation, disabled: accepting, children: [accepting ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Check, { className: "size-4" })), accepting
|
|
183
|
+
? m.member_required_accepting_invite
|
|
184
|
+
: m.member_required_accept_invite] })) : null })] }) }));
|
|
183
185
|
}
|
|
@@ -22,9 +22,14 @@ declare const messages: {
|
|
|
22
22
|
readonly organization_invitation_reject_error: "Could not decline the invitation.";
|
|
23
23
|
readonly organization_invitation_rejected: "Invitation declined.";
|
|
24
24
|
readonly organization_invitation_status: "Status";
|
|
25
|
-
readonly
|
|
26
|
-
readonly
|
|
27
|
-
readonly
|
|
25
|
+
readonly organization_invitation_status_accepted: "Accepted";
|
|
26
|
+
readonly organization_invitation_status_canceled: "Canceled";
|
|
27
|
+
readonly organization_invitation_status_expired: "Expired";
|
|
28
|
+
readonly organization_invitation_status_pending: "Pending";
|
|
29
|
+
readonly organization_invitation_status_rejected: "Rejected";
|
|
30
|
+
readonly organization_invitations_description: "Track pending and expired invitations.";
|
|
31
|
+
readonly organization_invitations_empty: "No invitations.";
|
|
32
|
+
readonly organization_invitations_heading: "Invitations";
|
|
28
33
|
readonly organization_invitations_load_error: "Could not load organization invitations.";
|
|
29
34
|
readonly organization_user_invitations_description: "Review invitations sent to your email address and choose which organizations to join.";
|
|
30
35
|
readonly organization_user_invitations_empty: "You have no pending invitations.";
|
|
@@ -104,9 +109,14 @@ declare const messages: {
|
|
|
104
109
|
readonly organization_invitation_reject_error: "Impossible de refuser l'invitation.";
|
|
105
110
|
readonly organization_invitation_rejected: "Invitation refusée.";
|
|
106
111
|
readonly organization_invitation_status: "Statut";
|
|
107
|
-
readonly
|
|
108
|
-
readonly
|
|
109
|
-
readonly
|
|
112
|
+
readonly organization_invitation_status_accepted: "Acceptée";
|
|
113
|
+
readonly organization_invitation_status_canceled: "Annulée";
|
|
114
|
+
readonly organization_invitation_status_expired: "Expirée";
|
|
115
|
+
readonly organization_invitation_status_pending: "En attente";
|
|
116
|
+
readonly organization_invitation_status_rejected: "Refusée";
|
|
117
|
+
readonly organization_invitations_description: "Suivez les invitations en attente et expirées.";
|
|
118
|
+
readonly organization_invitations_empty: "Aucune invitation.";
|
|
119
|
+
readonly organization_invitations_heading: "Invitations";
|
|
110
120
|
readonly organization_invitations_load_error: "Impossible de charger les invitations de l'organisation.";
|
|
111
121
|
readonly organization_user_invitations_description: "Consultez les invitations envoyées à votre adresse courriel et choisissez les organisations à rejoindre.";
|
|
112
122
|
readonly organization_user_invitations_empty: "Vous n'avez aucune invitation en attente.";
|
|
@@ -16,11 +16,12 @@ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, }
|
|
|
16
16
|
import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu";
|
|
17
17
|
import { Separator } from "@/components/ui/separator";
|
|
18
18
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
19
|
-
import {
|
|
19
|
+
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, } from "../roles";
|
|
20
20
|
import { authClientApi } from "./auth-client-api";
|
|
21
21
|
import { useKrakstackAuth } from "./auth-provider";
|
|
22
22
|
import { createApiKey } from "./api-key";
|
|
23
23
|
import { useOpenedOnce } from "./hooks";
|
|
24
|
+
import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration";
|
|
24
25
|
import { ExtraUploadedAsset } from "../extra/schema";
|
|
25
26
|
import { assetPath, assetUrl, cn } from "./utils";
|
|
26
27
|
const messages = {
|
|
@@ -44,9 +45,14 @@ const messages = {
|
|
|
44
45
|
organization_invitation_reject_error: "Could not decline the invitation.",
|
|
45
46
|
organization_invitation_rejected: "Invitation declined.",
|
|
46
47
|
organization_invitation_status: "Status",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
organization_invitation_status_accepted: "Accepted",
|
|
49
|
+
organization_invitation_status_canceled: "Canceled",
|
|
50
|
+
organization_invitation_status_expired: "Expired",
|
|
51
|
+
organization_invitation_status_pending: "Pending",
|
|
52
|
+
organization_invitation_status_rejected: "Rejected",
|
|
53
|
+
organization_invitations_description: "Track pending and expired invitations.",
|
|
54
|
+
organization_invitations_empty: "No invitations.",
|
|
55
|
+
organization_invitations_heading: "Invitations",
|
|
50
56
|
organization_invitations_load_error: "Could not load organization invitations.",
|
|
51
57
|
organization_user_invitations_description: "Review invitations sent to your email address and choose which organizations to join.",
|
|
52
58
|
organization_user_invitations_empty: "You have no pending invitations.",
|
|
@@ -126,9 +132,14 @@ const messages = {
|
|
|
126
132
|
organization_invitation_reject_error: "Impossible de refuser l'invitation.",
|
|
127
133
|
organization_invitation_rejected: "Invitation refusée.",
|
|
128
134
|
organization_invitation_status: "Statut",
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
135
|
+
organization_invitation_status_accepted: "Acceptée",
|
|
136
|
+
organization_invitation_status_canceled: "Annulée",
|
|
137
|
+
organization_invitation_status_expired: "Expirée",
|
|
138
|
+
organization_invitation_status_pending: "En attente",
|
|
139
|
+
organization_invitation_status_rejected: "Refusée",
|
|
140
|
+
organization_invitations_description: "Suivez les invitations en attente et expirées.",
|
|
141
|
+
organization_invitations_empty: "Aucune invitation.",
|
|
142
|
+
organization_invitations_heading: "Invitations",
|
|
132
143
|
organization_invitations_load_error: "Impossible de charger les invitations de l'organisation.",
|
|
133
144
|
organization_user_invitations_description: "Consultez les invitations envoyées à votre adresse courriel et choisissez les organisations à rejoindre.",
|
|
134
145
|
organization_user_invitations_empty: "Vous n'avez aucune invitation en attente.",
|
|
@@ -223,6 +234,11 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
|
|
|
223
234
|
},
|
|
224
235
|
catch: (error) => error,
|
|
225
236
|
}))));
|
|
237
|
+
const invitationOrganizationProfileAtom = Atom.family(({ baseUrl, organizationId, }) => authClientApi(baseUrl).query("authExtra", "getOrganizationPublicProfile", {
|
|
238
|
+
query: { organizationId },
|
|
239
|
+
timeToLive: "5 minutes",
|
|
240
|
+
serializationKey: `invitation-organization:${organizationId}`,
|
|
241
|
+
}));
|
|
226
242
|
const emptyUserInvitationsAtom = Atom.make(Effect.try({
|
|
227
243
|
try: () => [],
|
|
228
244
|
catch: (error) => error,
|
|
@@ -361,6 +377,22 @@ const organizationRoleLabel = (role, m) => {
|
|
|
361
377
|
return m.organization_role_member();
|
|
362
378
|
}
|
|
363
379
|
};
|
|
380
|
+
const invitationStatusLabel = (status, m) => {
|
|
381
|
+
switch (status) {
|
|
382
|
+
case "accepted":
|
|
383
|
+
return m.organization_invitation_status_accepted();
|
|
384
|
+
case "canceled":
|
|
385
|
+
return m.organization_invitation_status_canceled();
|
|
386
|
+
case "expired":
|
|
387
|
+
return m.organization_invitation_status_expired();
|
|
388
|
+
case "pending":
|
|
389
|
+
return m.organization_invitation_status_pending();
|
|
390
|
+
case "rejected":
|
|
391
|
+
return m.organization_invitation_status_rejected();
|
|
392
|
+
default:
|
|
393
|
+
return status;
|
|
394
|
+
}
|
|
395
|
+
};
|
|
364
396
|
const formatOrganizationDate = (date) => new Intl.DateTimeFormat(getLocale(), { dateStyle: "medium" }).format(new Date(date));
|
|
365
397
|
const organizationMetadataFromForm = async (value, m, uploadImage) => {
|
|
366
398
|
const translations = [];
|
|
@@ -514,7 +546,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
514
546
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
515
547
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() })] }), _jsx(Separator, {}), activeOrganization.data && canUpdateOrganization ? (_jsx(EditOrganizationSection, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
516
548
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
517
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
|
|
549
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_members_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationMembersManager, { authClient: authClient, baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization.data, currentUserId: session.data.user.id, active: dialog === "members", onLeft: async () => {
|
|
518
550
|
setDialog(null);
|
|
519
551
|
auth?.refreshAuth();
|
|
520
552
|
await refresh();
|
|
@@ -523,15 +555,18 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
523
555
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
524
556
|
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-3xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.user_api_keys_title() }), _jsx(DialogDescription, { children: activeOrganization.data?.name })] }), _jsx(Separator, {}), activeOrganization.data ? (_jsx(OrganizationApiKeyManager, { authClient: authClient, organization: activeOrganization.data, active: dialog === "apiKeys" && canManageApiKeys })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations" && !locked, onOpenChange: (open) => {
|
|
525
557
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
526
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
558
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_user_invitations_title() }), _jsx(DialogDescription, { children: m.organization_user_invitations_description() })] }), _jsx(Separator, {}), _jsx(UserInvitationsManager, { authClient: authClient, baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization.data
|
|
527
559
|
? { activeOrganizationId: activeOrganization.data.id }
|
|
528
560
|
: {}), onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
529
561
|
}
|
|
530
|
-
function UserInvitationsManager({ authClient, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
562
|
+
function UserInvitationsManager({ authClient, baseUrl, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
531
563
|
const m = useOrganizationMessages();
|
|
532
564
|
const [actingInvitationId, setActingInvitationId] = useState(null);
|
|
533
565
|
const [actionError, setActionError] = useState(null);
|
|
566
|
+
const invitationNow = useInvitationExpirationClock(invitations);
|
|
534
567
|
const acceptInvitation = async (invitation) => {
|
|
568
|
+
if (isInvitationExpired(invitation))
|
|
569
|
+
return;
|
|
535
570
|
setActingInvitationId(invitation.id);
|
|
536
571
|
setActionError(null);
|
|
537
572
|
const result = await authClient.organization.acceptInvitation({
|
|
@@ -558,19 +593,33 @@ function UserInvitationsManager({ authClient, invitations, loading, error, activ
|
|
|
558
593
|
await onActionComplete(activeOrganizationId);
|
|
559
594
|
};
|
|
560
595
|
return (_jsxs("section", { className: "flex flex-col gap-4", children: [error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, actionError ? (_jsx("p", { className: "text-destructive text-sm", children: actionError })) : null, _jsx(DataTable, { columns: userInvitationColumns({
|
|
596
|
+
baseUrl,
|
|
561
597
|
m,
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
598
|
+
now: invitationNow,
|
|
599
|
+
}), data: invitations, features: {
|
|
600
|
+
export: { baseName: "organization-invitations" },
|
|
601
|
+
gallery: false,
|
|
602
|
+
rowActions: {
|
|
603
|
+
items: userInvitationRowActions({
|
|
604
|
+
m,
|
|
605
|
+
actingInvitationId,
|
|
606
|
+
now: invitationNow,
|
|
607
|
+
onAccept: acceptInvitation,
|
|
608
|
+
onReject: rejectInvitation,
|
|
609
|
+
}),
|
|
610
|
+
},
|
|
611
|
+
}, searchState: "local", state: {
|
|
612
|
+
empty: loading
|
|
613
|
+
? m.user_loading()
|
|
614
|
+
: m.organization_user_invitations_empty(),
|
|
615
|
+
loading,
|
|
616
|
+
} })] }));
|
|
568
617
|
}
|
|
569
|
-
const userInvitationColumns = ({ m, }) => [
|
|
618
|
+
const userInvitationColumns = ({ baseUrl, m, now, }) => [
|
|
570
619
|
{
|
|
571
620
|
accessorKey: "organizationName",
|
|
572
621
|
header: m.organization_invitation_organization(),
|
|
573
|
-
cell: ({ row }) => (
|
|
622
|
+
cell: ({ row }) => (_jsx(InvitationOrganizationBrand, { baseUrl: baseUrl, invitation: row.original })),
|
|
574
623
|
},
|
|
575
624
|
{
|
|
576
625
|
accessorKey: "role",
|
|
@@ -580,7 +629,7 @@ const userInvitationColumns = ({ m, }) => [
|
|
|
580
629
|
{
|
|
581
630
|
accessorKey: "status",
|
|
582
631
|
header: m.organization_invitation_status(),
|
|
583
|
-
cell: ({ row }) => _jsx(Badge, { children: row.original
|
|
632
|
+
cell: ({ row }) => (_jsx(Badge, { variant: isInvitationExpired(row.original, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(row.original, now), m) })),
|
|
584
633
|
},
|
|
585
634
|
{
|
|
586
635
|
accessorKey: "expiresAt",
|
|
@@ -588,11 +637,27 @@ const userInvitationColumns = ({ m, }) => [
|
|
|
588
637
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
|
|
589
638
|
},
|
|
590
639
|
];
|
|
591
|
-
|
|
640
|
+
function InvitationOrganizationBrand({ baseUrl, invitation, }) {
|
|
641
|
+
const profileResult = useAtomValue(invitationOrganizationProfileAtom({
|
|
642
|
+
baseUrl,
|
|
643
|
+
organizationId: invitation.organizationId,
|
|
644
|
+
}));
|
|
645
|
+
const profile = AsyncResult.match(profileResult, {
|
|
646
|
+
onInitial: () => null,
|
|
647
|
+
onFailure: () => null,
|
|
648
|
+
onSuccess: ({ value }) => value,
|
|
649
|
+
});
|
|
650
|
+
const image = assetUrl(profile?.icon ?? profile?.logo ?? null, baseUrl);
|
|
651
|
+
return (_jsx(AppBrand, { to: null, label: profile?.displayName ??
|
|
652
|
+
invitation.organizationName ??
|
|
653
|
+
invitation.organizationId, subtitle: invitation.organizationId, icon: Building2, className: "min-w-48", ...(image ? { imageSrc: image } : {}) }));
|
|
654
|
+
}
|
|
655
|
+
const userInvitationRowActions = ({ m, actingInvitationId, now, onAccept, onReject, }) => [
|
|
592
656
|
{
|
|
593
657
|
name: m.organization_invitation_accept(),
|
|
594
658
|
icon: _jsx(Check, {}),
|
|
595
|
-
visible: (invitation) => actingInvitationId !== invitation.id
|
|
659
|
+
visible: (invitation) => actingInvitationId !== invitation.id &&
|
|
660
|
+
!isInvitationExpired(invitation, now),
|
|
596
661
|
onClick: onAccept,
|
|
597
662
|
},
|
|
598
663
|
{
|
|
@@ -765,7 +830,7 @@ function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleC
|
|
|
765
830
|
: m.organization_translation_french();
|
|
766
831
|
return (_jsxs("div", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: title }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_translation_description() })] }), _jsx(EditingLocaleSwitcher, { value: editingLocale, onValueChange: onEditingLocaleChange })] }));
|
|
767
832
|
}
|
|
768
|
-
function OrganizationMembersManager({ authClient, baseUrl, organization, currentUserId, active, onLeft, }) {
|
|
833
|
+
function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, organization, currentUserId, active, onLeft, }) {
|
|
769
834
|
const m = useOrganizationMessages();
|
|
770
835
|
const hasOpened = useOpenedOnce(active);
|
|
771
836
|
const membersAtom = hasOpened
|
|
@@ -776,13 +841,20 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
776
841
|
const [error, setError] = useState(null);
|
|
777
842
|
const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
|
|
778
843
|
const [leavingOrganization, setLeavingOrganization] = useState(false);
|
|
779
|
-
const
|
|
780
|
-
|
|
781
|
-
|
|
844
|
+
const [lastMembersData, setLastMembersData] = useState(null);
|
|
845
|
+
const currentMembersData = AsyncResult.match(membersResult, {
|
|
846
|
+
onInitial: () => null,
|
|
847
|
+
onFailure: () => null,
|
|
782
848
|
onSuccess: ({ value }) => value,
|
|
783
849
|
});
|
|
850
|
+
const membersData = currentMembersData ??
|
|
851
|
+
lastMembersData ?? {
|
|
852
|
+
members: [],
|
|
853
|
+
invitations: [],
|
|
854
|
+
};
|
|
784
855
|
const members = membersData.members;
|
|
785
856
|
const invitations = membersData.invitations;
|
|
857
|
+
const invitationNow = useInvitationExpirationClock(invitations);
|
|
786
858
|
const [memberRoleOverrides, setMemberRoleOverrides] = useState({});
|
|
787
859
|
const displayedMembers = members.map((member) => ({
|
|
788
860
|
...member,
|
|
@@ -793,14 +865,14 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
793
865
|
onFailure: () => m.organization_members_load_error(),
|
|
794
866
|
onSuccess: () => null,
|
|
795
867
|
});
|
|
796
|
-
const loading = membersResult._tag === "Initial";
|
|
797
|
-
const
|
|
798
|
-
const
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
868
|
+
const loading = !lastMembersData && membersResult._tag === "Initial";
|
|
869
|
+
const canInviteMembers = canManageMembers;
|
|
870
|
+
const canRemoveMembers = canManageMembers;
|
|
871
|
+
useEffect(() => {
|
|
872
|
+
if (!currentMembersData)
|
|
873
|
+
return;
|
|
874
|
+
setLastMembersData(currentMembersData);
|
|
875
|
+
}, [currentMembersData]);
|
|
804
876
|
const inviteForm = useAppForm({
|
|
805
877
|
defaultValues: { email: "", role: "member" },
|
|
806
878
|
onSubmit: async ({ value, formApi }) => {
|
|
@@ -883,32 +955,45 @@ function OrganizationMembersManager({ authClient, baseUrl, organization, current
|
|
|
883
955
|
}
|
|
884
956
|
refreshMembers();
|
|
885
957
|
};
|
|
886
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
958
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx("div", { className: "min-h-40 rounded-lg border p-4", children: _jsx(inviteForm.AppForm, { children: _jsxs("form", { className: "grid gap-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
|
|
959
|
+
event.preventDefault();
|
|
960
|
+
event.stopPropagation();
|
|
961
|
+
inviteForm.handleSubmit();
|
|
962
|
+
}, children: [_jsxs("div", { className: "sm:col-span-3", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(UserPlus, { className: "size-4" }), m.organization_invite_member_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invite_member_description() })] }), _jsx(inviteForm.AppField, { name: "email", children: (field) => (_jsx(field.TextField, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true })) }), _jsx(inviteForm.AppField, { name: "role", children: (field) => (_jsx(field.SelectField, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
963
|
+
label: organizationRoleLabel(role, m),
|
|
964
|
+
value: role,
|
|
965
|
+
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }) })) : null, membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
|
|
894
966
|
m,
|
|
895
967
|
baseUrl,
|
|
896
|
-
canChangeRoles:
|
|
968
|
+
canChangeRoles: canManageMembers,
|
|
897
969
|
onRoleChange: updateRole,
|
|
898
|
-
}), data: displayedMembers,
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
970
|
+
}), data: displayedMembers, features: {
|
|
971
|
+
export: { baseName: `${organization.slug}-members` },
|
|
972
|
+
gallery: false,
|
|
973
|
+
rowActions: {
|
|
974
|
+
items: memberRowActions({
|
|
975
|
+
m,
|
|
976
|
+
canRemoveMembers,
|
|
977
|
+
currentUserId,
|
|
978
|
+
leavingOrganization,
|
|
979
|
+
onLeave: leaveOrganization,
|
|
980
|
+
onRemove: removeMember,
|
|
981
|
+
}),
|
|
982
|
+
},
|
|
983
|
+
}, searchState: "local", state: { empty: m.organization_members_empty(), loading } }) })] }), _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: invitationColumns({
|
|
908
984
|
m,
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
985
|
+
now: invitationNow,
|
|
986
|
+
}), data: invitations, features: {
|
|
987
|
+
export: { baseName: `${organization.slug}-invitations` },
|
|
988
|
+
gallery: false,
|
|
989
|
+
rowActions: {
|
|
990
|
+
items: invitationRowActions({
|
|
991
|
+
m,
|
|
992
|
+
cancellingInvitationId,
|
|
993
|
+
onCancel: cancelInvitation,
|
|
994
|
+
}),
|
|
995
|
+
},
|
|
996
|
+
}, searchState: "local", state: { empty: m.organization_invitations_empty(), loading } }) })] })] }));
|
|
912
997
|
}
|
|
913
998
|
const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
914
999
|
{
|
|
@@ -935,7 +1020,7 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
935
1020
|
return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
936
1021
|
label: organizationRoleLabel(role, m),
|
|
937
1022
|
value: role,
|
|
938
|
-
})), value: roleOptions,
|
|
1023
|
+
})), value: roleOptions, onAdd: (value) => {
|
|
939
1024
|
if (!isOrganizationRole(value))
|
|
940
1025
|
return;
|
|
941
1026
|
onRoleChange(member, Array.from(new Set([...roles, value])));
|
|
@@ -971,7 +1056,7 @@ const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganizat
|
|
|
971
1056
|
onClick: onRemove,
|
|
972
1057
|
},
|
|
973
1058
|
];
|
|
974
|
-
const invitationColumns = ({ m, }) => [
|
|
1059
|
+
const invitationColumns = ({ m, now, }) => [
|
|
975
1060
|
{
|
|
976
1061
|
accessorKey: "email",
|
|
977
1062
|
header: m.organization_member_email(),
|
|
@@ -985,7 +1070,7 @@ const invitationColumns = ({ m, }) => [
|
|
|
985
1070
|
{
|
|
986
1071
|
accessorKey: "status",
|
|
987
1072
|
header: m.organization_invitation_status(),
|
|
988
|
-
cell: ({ row }) => _jsx(Badge, { children: row.original
|
|
1073
|
+
cell: ({ row }) => (_jsx(Badge, { variant: isInvitationExpired(row.original, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(row.original, now), m) })),
|
|
989
1074
|
},
|
|
990
1075
|
{
|
|
991
1076
|
accessorKey: "expiresAt",
|
|
@@ -1065,7 +1150,16 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1065
1150
|
event.preventDefault();
|
|
1066
1151
|
event.stopPropagation();
|
|
1067
1152
|
createForm.handleSubmit();
|
|
1068
|
-
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsx("code", { className: "bg-muted overflow-x-auto rounded-md p-3 text-sm", children: createdKey })] })) : null, keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys,
|
|
1153
|
+
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.user_api_key_name(), required: true })) }), _jsx(createForm.FormError, {}), _jsx(createForm.SubmitButton, {})] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsx("code", { className: "bg-muted overflow-x-auto rounded-md p-3 text-sm", children: createdKey })] })) : null, keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, features: {
|
|
1154
|
+
export: { baseName: `${organization.slug}-api-keys` },
|
|
1155
|
+
gallery: false,
|
|
1156
|
+
rowActions: {
|
|
1157
|
+
items: apiKeyRowActions({ m, onDelete: deleteKey }),
|
|
1158
|
+
},
|
|
1159
|
+
}, searchState: "local", state: {
|
|
1160
|
+
empty: loading ? m.user_loading() : m.table_empty(),
|
|
1161
|
+
loading,
|
|
1162
|
+
} })] }));
|
|
1069
1163
|
}
|
|
1070
1164
|
const apiKeyColumns = ({ m, }) => [
|
|
1071
1165
|
{
|