@krak-stack/auth 0.1.49 → 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/invitation-expiration.d.ts +8 -0
- package/dist/components/invitation-expiration.js +24 -0
- package/dist/components/member-required.d.ts +2 -0
- package/dist/components/member-required.js +14 -6
- package/dist/components/organization-switcher.d.ts +8 -6
- package/dist/components/organization-switcher.js +104 -37
- package/dist/components/user-button.js +10 -1
- package/package.json +1 -1
|
@@ -96,13 +96,17 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
96
96
|
onFailure: () => false,
|
|
97
97
|
onSuccess: () => false,
|
|
98
98
|
});
|
|
99
|
-
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations,
|
|
99
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, features: {
|
|
100
|
+
export: { baseName: "organizations" },
|
|
101
|
+
gallery: false,
|
|
102
|
+
pagination: { mode: "server", rowCount: total },
|
|
103
|
+
}, ...(from ? { routeFrom: from } : {}), ...(!search
|
|
100
104
|
? {
|
|
101
105
|
search: tableSearch,
|
|
102
106
|
onSearchChange: setLocalSearch,
|
|
103
107
|
searchState: "local",
|
|
104
108
|
}
|
|
105
|
-
: {}),
|
|
109
|
+
: {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { loading: isLoading } })] }));
|
|
106
110
|
}
|
|
107
111
|
const organizationColumns = (m, locale, baseUrl) => [
|
|
108
112
|
{
|
|
@@ -171,84 +171,91 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
171
171
|
await navigate({ to: "/" });
|
|
172
172
|
await router.invalidate();
|
|
173
173
|
};
|
|
174
|
-
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users,
|
|
174
|
+
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users, features: {
|
|
175
|
+
export: { baseName: "users" },
|
|
176
|
+
gallery: false,
|
|
177
|
+
pagination: { mode: "server", rowCount: total },
|
|
178
|
+
rowActions: {
|
|
179
|
+
items: [
|
|
180
|
+
{
|
|
181
|
+
name: m.admin_action_impersonate,
|
|
182
|
+
icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(UserCog, { className: "size-4" })),
|
|
183
|
+
onClick: async (user) => {
|
|
184
|
+
setImpersonateError("");
|
|
185
|
+
setImpersonatingUserId(user.id);
|
|
186
|
+
try {
|
|
187
|
+
if (!authClient)
|
|
188
|
+
throw new Error(m.admin_error_access_required);
|
|
189
|
+
await impersonateUser(authClient, user.id, m);
|
|
190
|
+
await refreshSessionAndNavigate();
|
|
191
|
+
}
|
|
192
|
+
catch (cause) {
|
|
193
|
+
setImpersonateError(cause instanceof Error
|
|
194
|
+
? cause.message
|
|
195
|
+
: m.admin_error_impersonate);
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
setImpersonatingUserId(null);
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
visible: (user) => !user.banned,
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: m.admin_action_impersonate_organization,
|
|
205
|
+
icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Building2, { className: "size-4" })),
|
|
206
|
+
onClick: async (user) => {
|
|
207
|
+
setImpersonateError("");
|
|
208
|
+
setImpersonatingUserId(user.id);
|
|
209
|
+
try {
|
|
210
|
+
if (!session?.user?.id) {
|
|
211
|
+
throw new Error(m.admin_error_access_required);
|
|
212
|
+
}
|
|
213
|
+
const organizationId = activeOrganizationId(session);
|
|
214
|
+
if (!organizationId) {
|
|
215
|
+
throw new Error(m.admin_error_organization_required);
|
|
216
|
+
}
|
|
217
|
+
await impersonateOrganizationUser({
|
|
218
|
+
payload: {
|
|
219
|
+
organizationId,
|
|
220
|
+
actorUserId: session.user.id,
|
|
221
|
+
targetUserId: user.id,
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
await refreshSessionAndNavigate();
|
|
225
|
+
}
|
|
226
|
+
catch (cause) {
|
|
227
|
+
setImpersonateError(cause instanceof Error
|
|
228
|
+
? cause.message
|
|
229
|
+
: m.admin_error_impersonate_organization);
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
setImpersonatingUserId(null);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
visible: (user) => !user.banned,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: m.admin_action_ban,
|
|
239
|
+
icon: _jsx(Ban, { className: "size-4" }),
|
|
240
|
+
variant: "destructive",
|
|
241
|
+
onClick: (user) => setBanningUser(user),
|
|
242
|
+
visible: (user) => !user.banned,
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: m.admin_action_unban,
|
|
246
|
+
icon: _jsx(ShieldOff, { className: "size-4" }),
|
|
247
|
+
onClick: (user) => setUnbanningUser(user),
|
|
248
|
+
visible: (user) => !!user.banned,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
},
|
|
252
|
+
}, ...(from ? { routeFrom: from } : {}), ...(!search
|
|
175
253
|
? {
|
|
176
254
|
search: tableSearch,
|
|
177
255
|
onSearchChange: setLocalSearch,
|
|
178
256
|
searchState: "local",
|
|
179
257
|
}
|
|
180
|
-
: {}),
|
|
181
|
-
{
|
|
182
|
-
name: m.admin_action_impersonate,
|
|
183
|
-
icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(UserCog, { className: "size-4" })),
|
|
184
|
-
onClick: async (user) => {
|
|
185
|
-
setImpersonateError("");
|
|
186
|
-
setImpersonatingUserId(user.id);
|
|
187
|
-
try {
|
|
188
|
-
if (!authClient)
|
|
189
|
-
throw new Error(m.admin_error_access_required);
|
|
190
|
-
await impersonateUser(authClient, user.id, m);
|
|
191
|
-
await refreshSessionAndNavigate();
|
|
192
|
-
}
|
|
193
|
-
catch (cause) {
|
|
194
|
-
setImpersonateError(cause instanceof Error
|
|
195
|
-
? cause.message
|
|
196
|
-
: m.admin_error_impersonate);
|
|
197
|
-
}
|
|
198
|
-
finally {
|
|
199
|
-
setImpersonatingUserId(null);
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
visible: (user) => !user.banned,
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
name: m.admin_action_impersonate_organization,
|
|
206
|
-
icon: impersonatingUserId ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Building2, { className: "size-4" })),
|
|
207
|
-
onClick: async (user) => {
|
|
208
|
-
setImpersonateError("");
|
|
209
|
-
setImpersonatingUserId(user.id);
|
|
210
|
-
try {
|
|
211
|
-
if (!session?.user?.id) {
|
|
212
|
-
throw new Error(m.admin_error_access_required);
|
|
213
|
-
}
|
|
214
|
-
const organizationId = activeOrganizationId(session);
|
|
215
|
-
if (!organizationId) {
|
|
216
|
-
throw new Error(m.admin_error_organization_required);
|
|
217
|
-
}
|
|
218
|
-
await impersonateOrganizationUser({
|
|
219
|
-
payload: {
|
|
220
|
-
organizationId,
|
|
221
|
-
actorUserId: session.user.id,
|
|
222
|
-
targetUserId: user.id,
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
await refreshSessionAndNavigate();
|
|
226
|
-
}
|
|
227
|
-
catch (cause) {
|
|
228
|
-
setImpersonateError(cause instanceof Error
|
|
229
|
-
? cause.message
|
|
230
|
-
: m.admin_error_impersonate_organization);
|
|
231
|
-
}
|
|
232
|
-
finally {
|
|
233
|
-
setImpersonatingUserId(null);
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
visible: (user) => !user.banned,
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
name: m.admin_action_ban,
|
|
240
|
-
icon: _jsx(Ban, { className: "size-4" }),
|
|
241
|
-
variant: "destructive",
|
|
242
|
-
onClick: (user) => setBanningUser(user),
|
|
243
|
-
visible: (user) => !user.banned,
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
name: m.admin_action_unban,
|
|
247
|
-
icon: _jsx(ShieldOff, { className: "size-4" }),
|
|
248
|
-
onClick: (user) => setUnbanningUser(user),
|
|
249
|
-
visible: (user) => !!user.banned,
|
|
250
|
-
},
|
|
251
|
-
] }), banningUser ? (_jsx(BanUserDialog, { labels: m, authClient: authClient, user: banningUser, onBanned: () => setRefreshKey((current) => current + 1), onClose: () => setBanningUser(null) })) : null, unbanningUser ? (_jsx(UnbanUserDialog, { labels: m, authClient: authClient, user: unbanningUser, onUnbanned: () => setRefreshKey((current) => current + 1), onClose: () => setUnbanningUser(null) })) : null] }));
|
|
258
|
+
: {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { loading: isLoading } }), banningUser ? (_jsx(BanUserDialog, { labels: m, authClient: authClient, user: banningUser, onBanned: () => setRefreshKey((current) => current + 1), onClose: () => setBanningUser(null) })) : null, unbanningUser ? (_jsx(UnbanUserDialog, { labels: m, authClient: authClient, user: unbanningUser, onUnbanned: () => setRefreshKey((current) => current + 1), onClose: () => setUnbanningUser(null) })) : null] }));
|
|
252
259
|
}
|
|
253
260
|
export function useAdminUsersTotal(search) {
|
|
254
261
|
const auth = useKrakstackAuth();
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type ExpiringInvitation = {
|
|
2
|
+
status: string;
|
|
3
|
+
expiresAt: Date | string;
|
|
4
|
+
};
|
|
5
|
+
export declare const isInvitationExpired: (invitation: ExpiringInvitation, now?: number) => boolean;
|
|
6
|
+
export declare const invitationDisplayStatus: (invitation: ExpiringInvitation, now?: number) => string;
|
|
7
|
+
export declare const useInvitationExpirationClock: (invitations: readonly ExpiringInvitation[]) => number;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
const expirationTime = (invitation) => new Date(invitation.expiresAt).getTime();
|
|
3
|
+
export const isInvitationExpired = (invitation, now = Date.now()) => invitation.status === "pending" && expirationTime(invitation) <= now;
|
|
4
|
+
export const invitationDisplayStatus = (invitation, now = Date.now()) => (isInvitationExpired(invitation, now) ? "expired" : invitation.status);
|
|
5
|
+
export const useInvitationExpirationClock = (invitations) => {
|
|
6
|
+
const [now, setNow] = useState(Date.now);
|
|
7
|
+
const nextExpiration = invitations.reduce((next, invitation) => {
|
|
8
|
+
const expiresAt = expirationTime(invitation);
|
|
9
|
+
if (invitation.status !== "pending" ||
|
|
10
|
+
!Number.isFinite(expiresAt) ||
|
|
11
|
+
expiresAt <= now) {
|
|
12
|
+
return next;
|
|
13
|
+
}
|
|
14
|
+
return next === undefined ? expiresAt : Math.min(next, expiresAt);
|
|
15
|
+
}, undefined);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (nextExpiration === undefined)
|
|
18
|
+
return;
|
|
19
|
+
const delay = Math.min(Math.max(nextExpiration - Date.now() + 1, 0), 2_147_483_647);
|
|
20
|
+
const timeout = globalThis.setTimeout(() => setNow(Date.now()), delay);
|
|
21
|
+
return () => globalThis.clearTimeout(timeout);
|
|
22
|
+
}, [nextExpiration]);
|
|
23
|
+
return now;
|
|
24
|
+
};
|
|
@@ -7,6 +7,7 @@ declare const defaultMessages: {
|
|
|
7
7
|
readonly member_required_org_description: "You need access to {organization} before opening the admin area.";
|
|
8
8
|
readonly member_required_no_permission: "Your account is signed in, but it does not have access to this organization.";
|
|
9
9
|
readonly member_required_invite_found: "You have a pending invitation to {organization}. Accept it to continue.";
|
|
10
|
+
readonly member_required_invite_expired: "Your invitation to {organization} has expired. Contact the organization administrator for a new invitation.";
|
|
10
11
|
readonly member_required_accept_invite: "Accept invitation";
|
|
11
12
|
readonly member_required_accepting_invite: "Accepting...";
|
|
12
13
|
readonly member_required_accept_error: "Could not accept the invitation.";
|
|
@@ -21,6 +22,7 @@ declare const defaultMessages: {
|
|
|
21
22
|
readonly member_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.";
|
|
22
23
|
readonly member_required_no_permission: "Votre compte est connecté, mais il ne dispose pas d'un accès à cette organisation.";
|
|
23
24
|
readonly member_required_invite_found: "Vous avez une invitation en attente pour {organization}. Acceptez-la pour continuer.";
|
|
25
|
+
readonly member_required_invite_expired: "Votre invitation pour {organization} a expiré. Contactez l'administrateur de l'organisation pour obtenir une nouvelle invitation.";
|
|
24
26
|
readonly member_required_accept_invite: "Accepter l'invitation";
|
|
25
27
|
readonly member_required_accepting_invite: "Acceptation...";
|
|
26
28
|
readonly member_required_accept_error: "Impossible d'accepter l'invitation.";
|
|
@@ -8,6 +8,7 @@ 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
|
member_required_title: "Organization access required",
|
|
@@ -15,6 +16,7 @@ const defaultMessages = {
|
|
|
15
16
|
member_required_org_description: "You need access to {organization} before opening the admin area.",
|
|
16
17
|
member_required_no_permission: "Your account is signed in, but it does not have access to this organization.",
|
|
17
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.",
|
|
18
20
|
member_required_accept_invite: "Accept invitation",
|
|
19
21
|
member_required_accepting_invite: "Accepting...",
|
|
20
22
|
member_required_accept_error: "Could not accept the invitation.",
|
|
@@ -29,6 +31,7 @@ const defaultMessages = {
|
|
|
29
31
|
member_required_org_description: "Vous devez avoir accès à {organization} avant d'ouvrir l'administration.",
|
|
30
32
|
member_required_no_permission: "Votre compte est connecté, mais il ne dispose pas d'un accès à cette organisation.",
|
|
31
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.",
|
|
32
35
|
member_required_accept_invite: "Accepter l'invitation",
|
|
33
36
|
member_required_accepting_invite: "Acceptation...",
|
|
34
37
|
member_required_accept_error: "Impossible d'accepter l'invitation.",
|
|
@@ -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 ??
|
|
@@ -134,6 +138,7 @@ function MemberRequiredGate({ accessKey, authClient, contactEmail, children, loc
|
|
|
134
138
|
const [accepting, setAccepting] = useState(false);
|
|
135
139
|
const [error, setError] = useState(null);
|
|
136
140
|
const access = accessResult.value;
|
|
141
|
+
const invitationNow = useInvitationExpirationClock(access.allowed || !access.invitation ? [] : [access.invitation]);
|
|
137
142
|
useEffect(() => {
|
|
138
143
|
if (!access.allowed)
|
|
139
144
|
return;
|
|
@@ -142,10 +147,13 @@ function MemberRequiredGate({ accessKey, authClient, contactEmail, children, loc
|
|
|
142
147
|
if (access.allowed)
|
|
143
148
|
return _jsx(_Fragment, { children: children });
|
|
144
149
|
const { invitation, organization } = access;
|
|
150
|
+
const invitationExpired = invitation
|
|
151
|
+
? isInvitationExpired(invitation, invitationNow)
|
|
152
|
+
: false;
|
|
145
153
|
const displayName = organizationDisplayName(invitation, organization, organizationId);
|
|
146
154
|
const resolvedContactEmail = organizationContactEmail(organization, contactEmail);
|
|
147
155
|
const acceptInvitation = async () => {
|
|
148
|
-
if (!invitation)
|
|
156
|
+
if (!invitation || isInvitationExpired(invitation))
|
|
149
157
|
return;
|
|
150
158
|
setAccepting(true);
|
|
151
159
|
setError(null);
|
|
@@ -166,12 +174,12 @@ function MemberRequiredGate({ accessKey, authClient, contactEmail, children, loc
|
|
|
166
174
|
};
|
|
167
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, {
|
|
168
176
|
organization: displayName,
|
|
169
|
-
}) })] }), _jsxs(CardContent, { className: "space-y-3", children: [invitation ? (_jsx("p", { className: "text-muted-foreground text-sm", children: interpolate(
|
|
170
|
-
|
|
171
|
-
|
|
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: {
|
|
172
180
|
copy: m.member_required_copy_email,
|
|
173
181
|
copied: m.member_required_copied_email,
|
|
174
|
-
} })] })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null] }), _jsx(CardFooter, { className: "flex flex-wrap gap-2", children: invitation ? (_jsxs(Button, { onClick: acceptInvitation, disabled: accepting, children: [accepting ? (_jsx(Loader2, { className: "size-4 animate-spin" })) : (_jsx(Check, { className: "size-4" })), accepting
|
|
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
|
|
175
183
|
? m.member_required_accepting_invite
|
|
176
184
|
: m.member_required_accept_invite] })) : null })] }) }));
|
|
177
185
|
}
|
|
@@ -24,11 +24,12 @@ declare const messages: {
|
|
|
24
24
|
readonly organization_invitation_status: "Status";
|
|
25
25
|
readonly organization_invitation_status_accepted: "Accepted";
|
|
26
26
|
readonly organization_invitation_status_canceled: "Canceled";
|
|
27
|
+
readonly organization_invitation_status_expired: "Expired";
|
|
27
28
|
readonly organization_invitation_status_pending: "Pending";
|
|
28
29
|
readonly organization_invitation_status_rejected: "Rejected";
|
|
29
|
-
readonly organization_invitations_description: "Track
|
|
30
|
-
readonly organization_invitations_empty: "No
|
|
31
|
-
readonly organization_invitations_heading: "
|
|
30
|
+
readonly organization_invitations_description: "Track pending and expired invitations.";
|
|
31
|
+
readonly organization_invitations_empty: "No invitations.";
|
|
32
|
+
readonly organization_invitations_heading: "Invitations";
|
|
32
33
|
readonly organization_invitations_load_error: "Could not load organization invitations.";
|
|
33
34
|
readonly organization_user_invitations_description: "Review invitations sent to your email address and choose which organizations to join.";
|
|
34
35
|
readonly organization_user_invitations_empty: "You have no pending invitations.";
|
|
@@ -110,11 +111,12 @@ declare const messages: {
|
|
|
110
111
|
readonly organization_invitation_status: "Statut";
|
|
111
112
|
readonly organization_invitation_status_accepted: "Acceptée";
|
|
112
113
|
readonly organization_invitation_status_canceled: "Annulée";
|
|
114
|
+
readonly organization_invitation_status_expired: "Expirée";
|
|
113
115
|
readonly organization_invitation_status_pending: "En attente";
|
|
114
116
|
readonly organization_invitation_status_rejected: "Refusée";
|
|
115
|
-
readonly organization_invitations_description: "Suivez les invitations
|
|
116
|
-
readonly organization_invitations_empty: "Aucune invitation
|
|
117
|
-
readonly organization_invitations_heading: "Invitations
|
|
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";
|
|
118
120
|
readonly organization_invitations_load_error: "Impossible de charger les invitations de l'organisation.";
|
|
119
121
|
readonly organization_user_invitations_description: "Consultez les invitations envoyées à votre adresse courriel et choisissez les organisations à rejoindre.";
|
|
120
122
|
readonly organization_user_invitations_empty: "Vous n'avez aucune invitation en attente.";
|
|
@@ -21,6 +21,7 @@ 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 = {
|
|
@@ -46,11 +47,12 @@ const messages = {
|
|
|
46
47
|
organization_invitation_status: "Status",
|
|
47
48
|
organization_invitation_status_accepted: "Accepted",
|
|
48
49
|
organization_invitation_status_canceled: "Canceled",
|
|
50
|
+
organization_invitation_status_expired: "Expired",
|
|
49
51
|
organization_invitation_status_pending: "Pending",
|
|
50
52
|
organization_invitation_status_rejected: "Rejected",
|
|
51
|
-
organization_invitations_description: "Track
|
|
52
|
-
organization_invitations_empty: "No
|
|
53
|
-
organization_invitations_heading: "
|
|
53
|
+
organization_invitations_description: "Track pending and expired invitations.",
|
|
54
|
+
organization_invitations_empty: "No invitations.",
|
|
55
|
+
organization_invitations_heading: "Invitations",
|
|
54
56
|
organization_invitations_load_error: "Could not load organization invitations.",
|
|
55
57
|
organization_user_invitations_description: "Review invitations sent to your email address and choose which organizations to join.",
|
|
56
58
|
organization_user_invitations_empty: "You have no pending invitations.",
|
|
@@ -132,11 +134,12 @@ const messages = {
|
|
|
132
134
|
organization_invitation_status: "Statut",
|
|
133
135
|
organization_invitation_status_accepted: "Acceptée",
|
|
134
136
|
organization_invitation_status_canceled: "Annulée",
|
|
137
|
+
organization_invitation_status_expired: "Expirée",
|
|
135
138
|
organization_invitation_status_pending: "En attente",
|
|
136
139
|
organization_invitation_status_rejected: "Refusée",
|
|
137
|
-
organization_invitations_description: "Suivez les invitations
|
|
138
|
-
organization_invitations_empty: "Aucune invitation
|
|
139
|
-
organization_invitations_heading: "Invitations
|
|
140
|
+
organization_invitations_description: "Suivez les invitations en attente et expirées.",
|
|
141
|
+
organization_invitations_empty: "Aucune invitation.",
|
|
142
|
+
organization_invitations_heading: "Invitations",
|
|
140
143
|
organization_invitations_load_error: "Impossible de charger les invitations de l'organisation.",
|
|
141
144
|
organization_user_invitations_description: "Consultez les invitations envoyées à votre adresse courriel et choisissez les organisations à rejoindre.",
|
|
142
145
|
organization_user_invitations_empty: "Vous n'avez aucune invitation en attente.",
|
|
@@ -231,6 +234,11 @@ const userInvitationsAtom = Atom.family((authClient) => Atom.keepAlive(Atom.make
|
|
|
231
234
|
},
|
|
232
235
|
catch: (error) => error,
|
|
233
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
|
+
}));
|
|
234
242
|
const emptyUserInvitationsAtom = Atom.make(Effect.try({
|
|
235
243
|
try: () => [],
|
|
236
244
|
catch: (error) => error,
|
|
@@ -375,6 +383,8 @@ const invitationStatusLabel = (status, m) => {
|
|
|
375
383
|
return m.organization_invitation_status_accepted();
|
|
376
384
|
case "canceled":
|
|
377
385
|
return m.organization_invitation_status_canceled();
|
|
386
|
+
case "expired":
|
|
387
|
+
return m.organization_invitation_status_expired();
|
|
378
388
|
case "pending":
|
|
379
389
|
return m.organization_invitation_status_pending();
|
|
380
390
|
case "rejected":
|
|
@@ -545,15 +555,18 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
545
555
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
546
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) => {
|
|
547
557
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
548
|
-
}, 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
|
|
549
559
|
? { activeOrganizationId: activeOrganization.data.id }
|
|
550
560
|
: {}), onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
551
561
|
}
|
|
552
|
-
function UserInvitationsManager({ authClient, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
562
|
+
function UserInvitationsManager({ authClient, baseUrl, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
553
563
|
const m = useOrganizationMessages();
|
|
554
564
|
const [actingInvitationId, setActingInvitationId] = useState(null);
|
|
555
565
|
const [actionError, setActionError] = useState(null);
|
|
566
|
+
const invitationNow = useInvitationExpirationClock(invitations);
|
|
556
567
|
const acceptInvitation = async (invitation) => {
|
|
568
|
+
if (isInvitationExpired(invitation))
|
|
569
|
+
return;
|
|
557
570
|
setActingInvitationId(invitation.id);
|
|
558
571
|
setActionError(null);
|
|
559
572
|
const result = await authClient.organization.acceptInvitation({
|
|
@@ -580,19 +593,33 @@ function UserInvitationsManager({ authClient, invitations, loading, error, activ
|
|
|
580
593
|
await onActionComplete(activeOrganizationId);
|
|
581
594
|
};
|
|
582
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,
|
|
583
597
|
m,
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
+
} })] }));
|
|
590
617
|
}
|
|
591
|
-
const userInvitationColumns = ({ m, }) => [
|
|
618
|
+
const userInvitationColumns = ({ baseUrl, m, now, }) => [
|
|
592
619
|
{
|
|
593
620
|
accessorKey: "organizationName",
|
|
594
621
|
header: m.organization_invitation_organization(),
|
|
595
|
-
cell: ({ row }) => (
|
|
622
|
+
cell: ({ row }) => (_jsx(InvitationOrganizationBrand, { baseUrl: baseUrl, invitation: row.original })),
|
|
596
623
|
},
|
|
597
624
|
{
|
|
598
625
|
accessorKey: "role",
|
|
@@ -602,7 +629,7 @@ const userInvitationColumns = ({ m, }) => [
|
|
|
602
629
|
{
|
|
603
630
|
accessorKey: "status",
|
|
604
631
|
header: m.organization_invitation_status(),
|
|
605
|
-
cell: ({ row }) => (_jsx(Badge, { children: invitationStatusLabel(row.original
|
|
632
|
+
cell: ({ row }) => (_jsx(Badge, { variant: isInvitationExpired(row.original, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(row.original, now), m) })),
|
|
606
633
|
},
|
|
607
634
|
{
|
|
608
635
|
accessorKey: "expiresAt",
|
|
@@ -610,11 +637,27 @@ const userInvitationColumns = ({ m, }) => [
|
|
|
610
637
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
|
|
611
638
|
},
|
|
612
639
|
];
|
|
613
|
-
|
|
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, }) => [
|
|
614
656
|
{
|
|
615
657
|
name: m.organization_invitation_accept(),
|
|
616
658
|
icon: _jsx(Check, {}),
|
|
617
|
-
visible: (invitation) => actingInvitationId !== invitation.id
|
|
659
|
+
visible: (invitation) => actingInvitationId !== invitation.id &&
|
|
660
|
+
!isInvitationExpired(invitation, now),
|
|
618
661
|
onClick: onAccept,
|
|
619
662
|
},
|
|
620
663
|
{
|
|
@@ -804,12 +847,14 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
804
847
|
onFailure: () => null,
|
|
805
848
|
onSuccess: ({ value }) => value,
|
|
806
849
|
});
|
|
807
|
-
const membersData = currentMembersData ??
|
|
850
|
+
const membersData = currentMembersData ??
|
|
851
|
+
lastMembersData ?? {
|
|
808
852
|
members: [],
|
|
809
853
|
invitations: [],
|
|
810
854
|
};
|
|
811
855
|
const members = membersData.members;
|
|
812
856
|
const invitations = membersData.invitations;
|
|
857
|
+
const invitationNow = useInvitationExpirationClock(invitations);
|
|
813
858
|
const [memberRoleOverrides, setMemberRoleOverrides] = useState({});
|
|
814
859
|
const displayedMembers = members.map((member) => ({
|
|
815
860
|
...member,
|
|
@@ -922,20 +967,33 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
922
967
|
baseUrl,
|
|
923
968
|
canChangeRoles: canManageMembers,
|
|
924
969
|
onRoleChange: updateRole,
|
|
925
|
-
}), data: displayedMembers,
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
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({
|
|
935
984
|
m,
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
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 } }) })] })] }));
|
|
939
997
|
}
|
|
940
998
|
const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
941
999
|
{
|
|
@@ -962,7 +1020,7 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
962
1020
|
return (_jsx(DataTableRelationshipCell, { emptyLabel: m.organization_member_role(), manageLabel: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
963
1021
|
label: organizationRoleLabel(role, m),
|
|
964
1022
|
value: role,
|
|
965
|
-
})), value: roleOptions,
|
|
1023
|
+
})), value: roleOptions, onAdd: (value) => {
|
|
966
1024
|
if (!isOrganizationRole(value))
|
|
967
1025
|
return;
|
|
968
1026
|
onRoleChange(member, Array.from(new Set([...roles, value])));
|
|
@@ -998,7 +1056,7 @@ const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganizat
|
|
|
998
1056
|
onClick: onRemove,
|
|
999
1057
|
},
|
|
1000
1058
|
];
|
|
1001
|
-
const invitationColumns = ({ m, }) => [
|
|
1059
|
+
const invitationColumns = ({ m, now, }) => [
|
|
1002
1060
|
{
|
|
1003
1061
|
accessorKey: "email",
|
|
1004
1062
|
header: m.organization_member_email(),
|
|
@@ -1012,7 +1070,7 @@ const invitationColumns = ({ m, }) => [
|
|
|
1012
1070
|
{
|
|
1013
1071
|
accessorKey: "status",
|
|
1014
1072
|
header: m.organization_invitation_status(),
|
|
1015
|
-
cell: ({ row }) => (_jsx(Badge, { children: invitationStatusLabel(row.original
|
|
1073
|
+
cell: ({ row }) => (_jsx(Badge, { variant: isInvitationExpired(row.original, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(row.original, now), m) })),
|
|
1016
1074
|
},
|
|
1017
1075
|
{
|
|
1018
1076
|
accessorKey: "expiresAt",
|
|
@@ -1092,7 +1150,16 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1092
1150
|
event.preventDefault();
|
|
1093
1151
|
event.stopPropagation();
|
|
1094
1152
|
createForm.handleSubmit();
|
|
1095
|
-
}, 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
|
+
} })] }));
|
|
1096
1163
|
}
|
|
1097
1164
|
const apiKeyColumns = ({ m, }) => [
|
|
1098
1165
|
{
|
|
@@ -766,7 +766,16 @@ function ApiKeyManager({ authClient, active, permissions = {}, }) {
|
|
|
766
766
|
event.preventDefault();
|
|
767
767
|
event.stopPropagation();
|
|
768
768
|
createForm.handleSubmit();
|
|
769
|
-
}, 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 })) }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _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() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : 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,
|
|
769
|
+
}, 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 })) }), permissionOptions.length > 0 ? (_jsxs(FieldSet, { children: [_jsx(FieldLegend, { children: m.user_api_key_permissions() }), _jsx(FieldDescription, { children: m.user_api_key_permissions_description() }), _jsx(FieldGroup, { "data-slot": "checkbox-group", className: "gap-3", children: permissionOptions.map((permission) => (_jsxs(Field, { orientation: "horizontal", children: [_jsx(Checkbox, { id: permission.id, checked: selectedPermissions[permission.id] ?? false, onCheckedChange: (checked) => togglePermission(permission.id, checked) }), _jsx(FieldContent, { children: _jsx(FieldLabel, { htmlFor: permission.id, children: permission.id }) })] }, permission.id))) })] })) : null, _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() }), _jsxs("div", { className: "grid min-w-0 gap-2 sm:grid-cols-[minmax(0,1fr)_auto] sm:items-center", children: [_jsx("code", { className: "bg-muted block max-w-full overflow-x-auto rounded-md p-3 text-sm whitespace-nowrap", children: createdKey }), _jsxs(Button, { type: "button", variant: "outline", onClick: copyCreatedKey, className: "self-start sm:self-auto", children: [copiedKey ? _jsx(Check, {}) : _jsx(Copy, {}), copiedKey ? m.user_api_key_copied() : m.user_api_key_copy()] })] })] })) : 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: {
|
|
770
|
+
export: { baseName: m.user_api_keys_export_file_name() },
|
|
771
|
+
gallery: false,
|
|
772
|
+
rowActions: {
|
|
773
|
+
items: apiKeyRowActions({ m, onDelete: deleteKey }),
|
|
774
|
+
},
|
|
775
|
+
}, searchState: "local", state: {
|
|
776
|
+
empty: loading ? m.user_loading() : m.table_empty(),
|
|
777
|
+
loading,
|
|
778
|
+
} })] }));
|
|
770
779
|
}
|
|
771
780
|
const apiKeyColumns = ({ m, }) => [
|
|
772
781
|
{
|