@krak-stack/auth 0.1.13 → 0.1.14
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import {} from "@tanstack/react-table";
|
|
3
3
|
import { Schema } from "effect";
|
|
4
|
-
import { Building2, ChevronsUpDown, KeyRound, PencilIcon, Trash2, UserPlus, Users, } from "lucide-react";
|
|
5
|
-
import { useEffect, useEffectEvent, useState, } from "react";
|
|
4
|
+
import { Building2, Check, ChevronsUpDown, KeyRound, Mail, PencilIcon, Plus, Trash2, UserPlus, Users, X, } from "lucide-react";
|
|
5
|
+
import { createContext, useContext, useEffect, useEffectEvent, useState, } from "react";
|
|
6
6
|
import { createDataTableActionsColumn, DataTable, } from "@/components/ui/data-table";
|
|
7
7
|
import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
|
|
8
8
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
@@ -14,9 +14,180 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem,
|
|
|
14
14
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
15
15
|
import { Separator } from "@/components/ui/separator";
|
|
16
16
|
import { cn } from "@/lib/utils";
|
|
17
|
-
import { m } from "@/paraglide/messages";
|
|
18
|
-
import { getLocale } from "@/paraglide/runtime";
|
|
19
17
|
import { OrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
18
|
+
const messages = {
|
|
19
|
+
en: {
|
|
20
|
+
api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
|
|
21
|
+
organization_contact_email: "Contact email",
|
|
22
|
+
organization_create_description: "Create a workspace for team-based access.",
|
|
23
|
+
organization_create_error: "Could not create the organization.",
|
|
24
|
+
organization_create_title: "Create organization",
|
|
25
|
+
organization_edit_description: "Update the active organization's canonical details and localized profile.",
|
|
26
|
+
organization_invitation_cancel: "Cancel invitation",
|
|
27
|
+
organization_invitation_cancel_error: "Could not cancel the invitation.",
|
|
28
|
+
organization_invitation_accept: "Accept invitation",
|
|
29
|
+
organization_invitation_accept_error: "Could not accept the invitation.",
|
|
30
|
+
organization_invitation_accepted: "Invitation accepted.",
|
|
31
|
+
organization_invitation_expires: "Expires",
|
|
32
|
+
organization_invitation_organization: "Organization",
|
|
33
|
+
organization_invitation_reject: "Decline invitation",
|
|
34
|
+
organization_invitation_reject_error: "Could not decline the invitation.",
|
|
35
|
+
organization_invitation_rejected: "Invitation declined.",
|
|
36
|
+
organization_invitation_status: "Status",
|
|
37
|
+
organization_invitations_description: "Track invitations that have not been accepted yet.",
|
|
38
|
+
organization_invitations_empty: "No pending invitations.",
|
|
39
|
+
organization_invitations_heading: "Pending invitations",
|
|
40
|
+
organization_invitations_load_error: "Could not load organization invitations.",
|
|
41
|
+
organization_user_invitations_description: "Review invitations sent to your email address and choose which organizations to join.",
|
|
42
|
+
organization_user_invitations_empty: "You have no pending invitations.",
|
|
43
|
+
organization_user_invitations_title: "Organization invitations",
|
|
44
|
+
organization_invite_error: "Could not send the invitation.",
|
|
45
|
+
organization_invite_member_description: "Send an invitation to join this organization with the selected role.",
|
|
46
|
+
organization_invite_member_title: "Invite a member",
|
|
47
|
+
organization_loading: "Loading...",
|
|
48
|
+
organization_location: "Location",
|
|
49
|
+
organization_logo: "Logo",
|
|
50
|
+
organization_logo_upload_error: "Could not upload the organization logo.",
|
|
51
|
+
organization_member_email: "Email",
|
|
52
|
+
organization_member_joined: "Joined",
|
|
53
|
+
organization_member_remove: "Remove member",
|
|
54
|
+
organization_member_remove_error: "Could not remove the member.",
|
|
55
|
+
organization_member_role: "Role",
|
|
56
|
+
organization_member_role_error: "Could not update the member role.",
|
|
57
|
+
organization_member_user: "User",
|
|
58
|
+
organization_members_description: "Review active members, update roles, and remove access when needed.",
|
|
59
|
+
organization_members_empty: "No members found.",
|
|
60
|
+
organization_members_heading: "Organization members",
|
|
61
|
+
organization_members_load_error: "Could not load organization members.",
|
|
62
|
+
organization_members_title: "Members",
|
|
63
|
+
organization_name: "Organization name",
|
|
64
|
+
organization_role_admin: "Admin",
|
|
65
|
+
organization_role_member: "Member",
|
|
66
|
+
organization_role_owner: "Owner",
|
|
67
|
+
organization_slug: "Organization slug",
|
|
68
|
+
organization_slug_description: "Leave blank to generate one from the name.",
|
|
69
|
+
organization_switcher_empty: "You do not belong to any organizations yet.",
|
|
70
|
+
organization_switcher_label: "Organization",
|
|
71
|
+
organization_switcher_manage: "Manage organization",
|
|
72
|
+
organization_switcher_no_other_organizations: "No other organizations.",
|
|
73
|
+
organization_translation_description: "Localized organization details stored in metadata.",
|
|
74
|
+
organization_translation_english: "English profile",
|
|
75
|
+
organization_translation_french: "French profile",
|
|
76
|
+
organization_translation_name: "Localized name",
|
|
77
|
+
organization_update_error: "Could not update the organization.",
|
|
78
|
+
table_empty: "No results.",
|
|
79
|
+
user_api_key_create_error: "Could not create the API key.",
|
|
80
|
+
user_api_key_created_description: "Copy this key now. You will not be able to see it again.",
|
|
81
|
+
user_api_key_created_title: "API key created",
|
|
82
|
+
user_api_key_delete_error: "Could not delete the API key.",
|
|
83
|
+
user_api_key_disabled: "Disabled",
|
|
84
|
+
user_api_key_enabled: "Enabled",
|
|
85
|
+
user_api_key_hidden: "Secret hidden",
|
|
86
|
+
user_api_key_name: "Key name",
|
|
87
|
+
user_api_key_starts_with: "Starts with {start}",
|
|
88
|
+
user_api_key_status: "Status",
|
|
89
|
+
user_api_keys_load_error: "Could not load API keys.",
|
|
90
|
+
user_api_keys_title: "API keys",
|
|
91
|
+
user_button_api_keys: "API keys",
|
|
92
|
+
user_delete: "Delete",
|
|
93
|
+
user_loading: "Loading...",
|
|
94
|
+
},
|
|
95
|
+
fr: {
|
|
96
|
+
api_key_rate_limit_notice: "Les clés API sont soumises aux mêmes limites de débit que votre compte.",
|
|
97
|
+
organization_contact_email: "E-mail de contact",
|
|
98
|
+
organization_create_description: "Créez un espace de travail pour l'accès en équipe.",
|
|
99
|
+
organization_create_error: "Impossible de créer l'organisation.",
|
|
100
|
+
organization_create_title: "Créer une organisation",
|
|
101
|
+
organization_edit_description: "Mettez à jour les détails canoniques et le profil localisé de l'organisation active.",
|
|
102
|
+
organization_invitation_cancel: "Annuler l'invitation",
|
|
103
|
+
organization_invitation_cancel_error: "Impossible d'annuler l'invitation.",
|
|
104
|
+
organization_invitation_accept: "Accepter l'invitation",
|
|
105
|
+
organization_invitation_accept_error: "Impossible d'accepter l'invitation.",
|
|
106
|
+
organization_invitation_accepted: "Invitation acceptée.",
|
|
107
|
+
organization_invitation_expires: "Expire le",
|
|
108
|
+
organization_invitation_organization: "Organisation",
|
|
109
|
+
organization_invitation_reject: "Refuser l'invitation",
|
|
110
|
+
organization_invitation_reject_error: "Impossible de refuser l'invitation.",
|
|
111
|
+
organization_invitation_rejected: "Invitation refusée.",
|
|
112
|
+
organization_invitation_status: "Statut",
|
|
113
|
+
organization_invitations_description: "Suivez les invitations qui n'ont pas encore été acceptées.",
|
|
114
|
+
organization_invitations_empty: "Aucune invitation en attente.",
|
|
115
|
+
organization_invitations_heading: "Invitations en attente",
|
|
116
|
+
organization_invitations_load_error: "Impossible de charger les invitations de l'organisation.",
|
|
117
|
+
organization_user_invitations_description: "Consultez les invitations envoyées à votre adresse courriel et choisissez les organisations à rejoindre.",
|
|
118
|
+
organization_user_invitations_empty: "Vous n'avez aucune invitation en attente.",
|
|
119
|
+
organization_user_invitations_title: "Invitations d'organisation",
|
|
120
|
+
organization_invite_error: "Impossible d'envoyer l'invitation.",
|
|
121
|
+
organization_invite_member_description: "Envoyez une invitation à rejoindre cette organisation avec le rôle sélectionné.",
|
|
122
|
+
organization_invite_member_title: "Inviter un membre",
|
|
123
|
+
organization_loading: "Chargement...",
|
|
124
|
+
organization_location: "Emplacement",
|
|
125
|
+
organization_logo: "Logo",
|
|
126
|
+
organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.",
|
|
127
|
+
organization_member_email: "Courriel",
|
|
128
|
+
organization_member_joined: "Arrivée",
|
|
129
|
+
organization_member_remove: "Retirer le membre",
|
|
130
|
+
organization_member_remove_error: "Impossible de retirer le membre.",
|
|
131
|
+
organization_member_role: "Rôle",
|
|
132
|
+
organization_member_role_error: "Impossible de modifier le rôle du membre.",
|
|
133
|
+
organization_member_user: "Utilisateur",
|
|
134
|
+
organization_members_description: "Consultez les membres actifs, modifiez les rôles et retirez les accès au besoin.",
|
|
135
|
+
organization_members_empty: "Aucun membre trouvé.",
|
|
136
|
+
organization_members_heading: "Membres de l'organisation",
|
|
137
|
+
organization_members_load_error: "Impossible de charger les membres de l'organisation.",
|
|
138
|
+
organization_members_title: "Membres",
|
|
139
|
+
organization_name: "Nom de l'organisation",
|
|
140
|
+
organization_role_admin: "Admin",
|
|
141
|
+
organization_role_member: "Membre",
|
|
142
|
+
organization_role_owner: "Propriétaire",
|
|
143
|
+
organization_slug: "Slug de l'organisation",
|
|
144
|
+
organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
|
|
145
|
+
organization_switcher_empty: "Vous n'appartenez encore à aucune organisation.",
|
|
146
|
+
organization_switcher_label: "Organisation",
|
|
147
|
+
organization_switcher_manage: "Gérer l'organisation",
|
|
148
|
+
organization_switcher_no_other_organizations: "Aucune autre organisation.",
|
|
149
|
+
organization_translation_description: "Détails localisés de l'organisation stockés dans les métadonnées.",
|
|
150
|
+
organization_translation_english: "Profil anglais",
|
|
151
|
+
organization_translation_french: "Profil français",
|
|
152
|
+
organization_translation_name: "Nom localisé",
|
|
153
|
+
organization_update_error: "Impossible de mettre à jour l'organisation.",
|
|
154
|
+
table_empty: "Aucun résultat.",
|
|
155
|
+
user_api_key_create_error: "Impossible de créer la clé API.",
|
|
156
|
+
user_api_key_created_description: "Copiez cette clé maintenant. Vous ne pourrez plus la voir.",
|
|
157
|
+
user_api_key_created_title: "Clé API créée",
|
|
158
|
+
user_api_key_delete_error: "Impossible de supprimer la clé API.",
|
|
159
|
+
user_api_key_disabled: "Désactivée",
|
|
160
|
+
user_api_key_enabled: "Activée",
|
|
161
|
+
user_api_key_hidden: "Secret masqué",
|
|
162
|
+
user_api_key_name: "Nom de la clé",
|
|
163
|
+
user_api_key_starts_with: "Commence par {start}",
|
|
164
|
+
user_api_key_status: "Statut",
|
|
165
|
+
user_api_keys_load_error: "Impossible de charger les clés API.",
|
|
166
|
+
user_api_keys_title: "Clés API",
|
|
167
|
+
user_button_api_keys: "Clés API",
|
|
168
|
+
user_delete: "Supprimer",
|
|
169
|
+
user_loading: "Chargement...",
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const getLocale = () => (globalThis.document?.documentElement.lang ||
|
|
173
|
+
globalThis.navigator?.language ||
|
|
174
|
+
"en")
|
|
175
|
+
.toLowerCase()
|
|
176
|
+
.startsWith("fr")
|
|
177
|
+
? "fr"
|
|
178
|
+
: "en";
|
|
179
|
+
const organizationSwitcherMessages = (overrides) => ({
|
|
180
|
+
...(getLocale().startsWith("fr") ? messages.fr : messages.en),
|
|
181
|
+
...overrides,
|
|
182
|
+
});
|
|
183
|
+
const interpolate = (value, params) => params
|
|
184
|
+
? value.replace(/\{([^}]+)\}/g, (_, key) => String(params[key] ?? `{${key}}`))
|
|
185
|
+
: value;
|
|
186
|
+
const organizationMessageFns = (labels) => new Proxy({}, {
|
|
187
|
+
get: (_target, key) => (params) => interpolate(labels[key], params),
|
|
188
|
+
});
|
|
189
|
+
const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
|
|
190
|
+
const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
|
|
20
191
|
const slugify = (value) => value
|
|
21
192
|
.trim()
|
|
22
193
|
.toLowerCase()
|
|
@@ -24,7 +195,7 @@ const slugify = (value) => value
|
|
|
24
195
|
.replace(/^-+|-+$/g, "");
|
|
25
196
|
const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
|
|
26
197
|
const centralAuthUrl = (path) => new URL(path, import.meta.env.VITE_KRAKSTACK_AUTH_URL).toString();
|
|
27
|
-
const parsePresignedUpload = (value) => {
|
|
198
|
+
const parsePresignedUpload = (value, m) => {
|
|
28
199
|
if (!isRecord(value) ||
|
|
29
200
|
typeof value.uploadUrl !== "string" ||
|
|
30
201
|
typeof value.url !== "string") {
|
|
@@ -33,7 +204,7 @@ const parsePresignedUpload = (value) => {
|
|
|
33
204
|
return { uploadUrl: value.uploadUrl, url: value.url };
|
|
34
205
|
};
|
|
35
206
|
const isRecord = (value) => typeof value === "object" && value !== null;
|
|
36
|
-
const uploadOrganizationLogo = async (file) => {
|
|
207
|
+
const uploadOrganizationLogo = async (file, m) => {
|
|
37
208
|
const contentType = file.type || "image/png";
|
|
38
209
|
const presignResponse = await fetch(centralAuthUrl("/api/organizations/logo/presign"), {
|
|
39
210
|
method: "POST",
|
|
@@ -44,7 +215,7 @@ const uploadOrganizationLogo = async (file) => {
|
|
|
44
215
|
if (!presignResponse.ok) {
|
|
45
216
|
throw new Error(m.organization_logo_upload_error());
|
|
46
217
|
}
|
|
47
|
-
const presigned = parsePresignedUpload(await presignResponse.json());
|
|
218
|
+
const presigned = parsePresignedUpload(await presignResponse.json(), m);
|
|
48
219
|
const uploadResponse = await fetch(presigned.uploadUrl, {
|
|
49
220
|
method: "PUT",
|
|
50
221
|
headers: { "Content-Type": contentType },
|
|
@@ -70,7 +241,7 @@ const findOrganizationTranslation = (organization, locale = currentOrganizationL
|
|
|
70
241
|
translations.find((translation) => translation.locale === "en") ??
|
|
71
242
|
translations[0]);
|
|
72
243
|
};
|
|
73
|
-
const organizationDisplay = (organization) => {
|
|
244
|
+
const organizationDisplay = (organization, m) => {
|
|
74
245
|
const translation = organization
|
|
75
246
|
? findOrganizationTranslation(organization)
|
|
76
247
|
: undefined;
|
|
@@ -101,10 +272,10 @@ const organizationFormDefaults = (organization) => {
|
|
|
101
272
|
frLocation: fr?.location ?? "",
|
|
102
273
|
};
|
|
103
274
|
};
|
|
104
|
-
const organizationLogoFromForm = async (file, fallback) => file ? await uploadOrganizationLogo(file) : nullableString(fallback);
|
|
275
|
+
const organizationLogoFromForm = async (file, fallback, m) => (file ? await uploadOrganizationLogo(file, m) : nullableString(fallback));
|
|
105
276
|
const organizationRoles = ["owner", "admin", "member"];
|
|
106
277
|
const normalizeOrganizationRole = (role) => role === "owner" || role === "admin" || role === "member" ? role : "member";
|
|
107
|
-
const organizationRoleLabel = (role) => {
|
|
278
|
+
const organizationRoleLabel = (role, m) => {
|
|
108
279
|
switch (normalizeOrganizationRole(role)) {
|
|
109
280
|
case "owner":
|
|
110
281
|
return m.organization_role_owner();
|
|
@@ -122,12 +293,12 @@ const initialsFromName = (name) => name
|
|
|
122
293
|
.map((part) => part[0])
|
|
123
294
|
.join("")
|
|
124
295
|
.toUpperCase() || "?";
|
|
125
|
-
const organizationMetadataFromForm = async (value) => {
|
|
296
|
+
const organizationMetadataFromForm = async (value, m) => {
|
|
126
297
|
const translations = [];
|
|
127
298
|
const enName = value.enName.trim() || value.name.trim();
|
|
128
299
|
const frName = value.frName.trim();
|
|
129
|
-
const enLogo = await organizationLogoFromForm(value.enLogo, value.enLogoUrl);
|
|
130
|
-
const frLogo = await organizationLogoFromForm(value.frLogo, value.frLogoUrl);
|
|
300
|
+
const enLogo = await organizationLogoFromForm(value.enLogo, value.enLogoUrl, m);
|
|
301
|
+
const frLogo = await organizationLogoFromForm(value.frLogo, value.frLogoUrl, m);
|
|
131
302
|
if (enName) {
|
|
132
303
|
translations.push({
|
|
133
304
|
locale: "en",
|
|
@@ -148,11 +319,36 @@ const organizationMetadataFromForm = async (value) => {
|
|
|
148
319
|
}
|
|
149
320
|
return { translations };
|
|
150
321
|
};
|
|
151
|
-
export function OrganizationSwitcher({ authClient, side = "bottom", className, renderUnauthenticated, locked = false, }) {
|
|
322
|
+
export function OrganizationSwitcher({ authClient, side = "bottom", className, renderUnauthenticated, locked = false, messages, }) {
|
|
323
|
+
const labels = organizationSwitcherMessages(messages);
|
|
324
|
+
const m = organizationMessageFns(labels);
|
|
152
325
|
const session = authClient.useSession();
|
|
153
326
|
const organizations = authClient.useListOrganizations();
|
|
154
327
|
const activeOrganization = authClient.useActiveOrganization();
|
|
155
328
|
const [dialog, setDialog] = useState(null);
|
|
329
|
+
const sessionUserId = session.data?.user.id;
|
|
330
|
+
const [userInvitations, setUserInvitations] = useState([]);
|
|
331
|
+
const [userInvitationsError, setUserInvitationsError] = useState(null);
|
|
332
|
+
const [loadingUserInvitations, setLoadingUserInvitations] = useState(false);
|
|
333
|
+
const loadUserInvitations = useEffectEvent(async () => {
|
|
334
|
+
if (!session.data)
|
|
335
|
+
return;
|
|
336
|
+
setLoadingUserInvitations(true);
|
|
337
|
+
setUserInvitationsError(null);
|
|
338
|
+
const result = await authClient.organization.listUserInvitations({});
|
|
339
|
+
if (result.error) {
|
|
340
|
+
setUserInvitationsError(result.error.message ?? m.organization_invitations_load_error());
|
|
341
|
+
setLoadingUserInvitations(false);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
setUserInvitations(result.data ?? []);
|
|
345
|
+
setLoadingUserInvitations(false);
|
|
346
|
+
});
|
|
347
|
+
useEffect(() => {
|
|
348
|
+
if (!sessionUserId)
|
|
349
|
+
return;
|
|
350
|
+
void loadUserInvitations();
|
|
351
|
+
}, [sessionUserId]);
|
|
156
352
|
if (!session.data) {
|
|
157
353
|
return _jsx(_Fragment, { children: renderUnauthenticated?.() });
|
|
158
354
|
}
|
|
@@ -165,16 +361,28 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
165
361
|
const refresh = async () => {
|
|
166
362
|
await organizations.refetch();
|
|
167
363
|
await activeOrganization.refetch();
|
|
364
|
+
await session.refetch();
|
|
365
|
+
};
|
|
366
|
+
const refreshAfterInvitationAction = async (previousActiveId) => {
|
|
367
|
+
await loadUserInvitations();
|
|
368
|
+
await refresh();
|
|
369
|
+
if (locked && previousActiveId) {
|
|
370
|
+
const result = await authClient.organization.setActive({
|
|
371
|
+
organizationId: previousActiveId,
|
|
372
|
+
});
|
|
373
|
+
if (!result.error)
|
|
374
|
+
await refresh();
|
|
375
|
+
}
|
|
168
376
|
};
|
|
169
|
-
const activeDisplay = organizationDisplay(active ?? null);
|
|
170
|
-
return (_jsxs(
|
|
377
|
+
const activeDisplay = organizationDisplay(active ?? null, m);
|
|
378
|
+
return (_jsxs(OrganizationMessagesContext.Provider, { value: m, children: [_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsxs(Button, { variant: "ghost", className: cn("h-11 w-full justify-between gap-2 !px-1 !py-0 group-data-[collapsible=icon]:size-8 group-data-[collapsible=icon]:justify-start group-data-[collapsible=icon]:!p-0", className), children: [_jsx(AppBrand, { to: null, label: activeName
|
|
171
379
|
? activeDisplay.name
|
|
172
380
|
: m.organization_switcher_label(), subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "min-w-0 flex-1 !p-0 text-left group-data-[collapsible=icon]:flex-none group-data-[collapsible=icon]:justify-start", ...(activeDisplay.logo
|
|
173
381
|
? { imageSrc: activeDisplay.logo }
|
|
174
382
|
: {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "min-w-64 rounded-lg", side: side, align: "end", sideOffset: 4, children: _jsxs(DropdownMenuGroup, { children: [_jsx(DropdownMenuLabel, { className: "p-0 font-normal", children: _jsx(AppBrand, { to: null, label: activeDisplay.name, subtitle: activeDisplay.subtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.logo
|
|
175
383
|
? { imageSrc: activeDisplay.logo }
|
|
176
384
|
: {}) }) }), hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizations.error ? (_jsx(DropdownMenuItem, { disabled: true, children: organizations.error.message })) : null, !locked && selectableOrganizations.length ? (selectableOrganizations.map((organization) => {
|
|
177
|
-
const display = organizationDisplay(organization);
|
|
385
|
+
const display = organizationDisplay(organization, m);
|
|
178
386
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
179
387
|
const result = await authClient.organization.setActive({
|
|
180
388
|
organizationId: organization.id,
|
|
@@ -184,7 +392,10 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
184
392
|
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: display.subtitle, icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.logo ? { imageSrc: display.logo } : {}) }) }, organization.id));
|
|
185
393
|
})) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
|
|
186
394
|
? m.organization_switcher_no_other_organizations()
|
|
187
|
-
: m.organization_switcher_empty() })) : null,
|
|
395
|
+
: m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
|
|
396
|
+
setDialog("invitations");
|
|
397
|
+
void loadUserInvitations();
|
|
398
|
+
}, children: [_jsx(Mail, {}), _jsxs("span", { className: "flex flex-1 items-center justify-between gap-3", children: [m.organization_user_invitations_title(), userInvitations.length ? (_jsx(Badge, { variant: "secondary", children: userInvitations.length })) : null] })] }), activeOrganization.data ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), _jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })] })) : null] }) })] }), _jsx(Dialog, { open: dialog === "create", onOpenChange: (open) => {
|
|
188
399
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
189
400
|
}, 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_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { authClient: authClient, onCreated: async () => {
|
|
190
401
|
await refresh();
|
|
@@ -195,9 +406,86 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
|
|
|
195
406
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
196
407
|
}, 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, organization: activeOrganization.data, currentUserId: session.data.user.id })) : null] }) }), _jsx(Dialog, { open: dialog === "apiKeys", onOpenChange: (open) => {
|
|
197
408
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
198
|
-
}, 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 })) : null] }) })
|
|
409
|
+
}, 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 })) : null] }) }), _jsx(Dialog, { open: dialog === "invitations", onOpenChange: (open) => {
|
|
410
|
+
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
411
|
+
}, 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, activeOrganizationId: activeOrganization.data?.id, onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
412
|
+
}
|
|
413
|
+
function UserInvitationsManager({ authClient, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
414
|
+
const m = useOrganizationMessages();
|
|
415
|
+
const [actingInvitationId, setActingInvitationId] = useState(null);
|
|
416
|
+
const [actionError, setActionError] = useState(null);
|
|
417
|
+
const acceptInvitation = async (invitation) => {
|
|
418
|
+
setActingInvitationId(invitation.id);
|
|
419
|
+
setActionError(null);
|
|
420
|
+
const result = await authClient.organization.acceptInvitation({
|
|
421
|
+
invitationId: invitation.id,
|
|
422
|
+
});
|
|
423
|
+
setActingInvitationId(null);
|
|
424
|
+
if (result.error) {
|
|
425
|
+
setActionError(result.error.message ?? m.organization_invitation_accept_error());
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
await onActionComplete(activeOrganizationId);
|
|
429
|
+
};
|
|
430
|
+
const rejectInvitation = async (invitation) => {
|
|
431
|
+
setActingInvitationId(invitation.id);
|
|
432
|
+
setActionError(null);
|
|
433
|
+
const result = await authClient.organization.rejectInvitation({
|
|
434
|
+
invitationId: invitation.id,
|
|
435
|
+
});
|
|
436
|
+
setActingInvitationId(null);
|
|
437
|
+
if (result.error) {
|
|
438
|
+
setActionError(result.error.message ?? m.organization_invitation_reject_error());
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
await onActionComplete(activeOrganizationId);
|
|
442
|
+
};
|
|
443
|
+
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({
|
|
444
|
+
m,
|
|
445
|
+
actingInvitationId,
|
|
446
|
+
onAccept: acceptInvitation,
|
|
447
|
+
onReject: rejectInvitation,
|
|
448
|
+
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false } })] }));
|
|
199
449
|
}
|
|
450
|
+
const userInvitationColumns = ({ m, actingInvitationId, onAccept, onReject, }) => [
|
|
451
|
+
{
|
|
452
|
+
accessorKey: "organizationName",
|
|
453
|
+
header: m.organization_invitation_organization(),
|
|
454
|
+
cell: ({ row }) => (_jsxs("div", { className: "flex min-w-48 flex-col gap-1", children: [_jsx("span", { className: "truncate font-medium", children: row.original.organizationName ?? row.original.organizationId }), _jsx("code", { className: "text-muted-foreground truncate text-xs", children: row.original.organizationId })] })),
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
accessorKey: "role",
|
|
458
|
+
header: m.organization_member_role(),
|
|
459
|
+
cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role, m) })),
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
accessorKey: "status",
|
|
463
|
+
header: m.organization_invitation_status(),
|
|
464
|
+
cell: ({ row }) => _jsx(Badge, { children: row.original.status }),
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
accessorKey: "expiresAt",
|
|
468
|
+
header: m.organization_invitation_expires(),
|
|
469
|
+
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
|
|
470
|
+
},
|
|
471
|
+
createDataTableActionsColumn([
|
|
472
|
+
{
|
|
473
|
+
name: m.organization_invitation_accept(),
|
|
474
|
+
icon: _jsx(Check, {}),
|
|
475
|
+
visible: (invitation) => actingInvitationId !== invitation.id,
|
|
476
|
+
onClick: onAccept,
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
name: m.organization_invitation_reject(),
|
|
480
|
+
icon: _jsx(X, {}),
|
|
481
|
+
variant: "destructive",
|
|
482
|
+
visible: (invitation) => actingInvitationId !== invitation.id,
|
|
483
|
+
onClick: onReject,
|
|
484
|
+
},
|
|
485
|
+
]),
|
|
486
|
+
];
|
|
200
487
|
function EditOrganizationSection({ authClient, organization, onUpdated, }) {
|
|
488
|
+
const m = useOrganizationMessages();
|
|
201
489
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
202
490
|
const defaultValues = organizationFormDefaults(organization);
|
|
203
491
|
const form = useAppForm({
|
|
@@ -206,7 +494,7 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
|
|
|
206
494
|
formApi.setErrorMap({ onSubmit: undefined });
|
|
207
495
|
const name = value.name.trim();
|
|
208
496
|
const slug = value.slug.trim().toLowerCase();
|
|
209
|
-
const metadata = await organizationMetadataFromForm(value);
|
|
497
|
+
const metadata = await organizationMetadataFromForm(value, m);
|
|
210
498
|
const result = await authClient.organization.update({
|
|
211
499
|
organizationId: organization.id,
|
|
212
500
|
data: { name, slug, metadata },
|
|
@@ -240,6 +528,7 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
|
|
|
240
528
|
} })) }), _jsx(form.AppField, { name: "frContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "frLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) }));
|
|
241
529
|
}
|
|
242
530
|
function CreateOrganizationSection({ authClient, onCreated, }) {
|
|
531
|
+
const m = useOrganizationMessages();
|
|
243
532
|
const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
|
|
244
533
|
const defaultValues = organizationFormDefaults();
|
|
245
534
|
const form = useAppForm({
|
|
@@ -252,7 +541,7 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
|
|
|
252
541
|
...value,
|
|
253
542
|
name,
|
|
254
543
|
slug,
|
|
255
|
-
});
|
|
544
|
+
}, m);
|
|
256
545
|
const result = await authClient.organization.create({
|
|
257
546
|
name,
|
|
258
547
|
slug,
|
|
@@ -288,12 +577,14 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
|
|
|
288
577
|
} })) }), _jsx(form.AppField, { name: "frContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "frLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })), _jsx(form.FormError, {}), _jsx(form.SubmitButton, {})] }) }) }));
|
|
289
578
|
}
|
|
290
579
|
function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleChange, }) {
|
|
580
|
+
const m = useOrganizationMessages();
|
|
291
581
|
const title = locale === "en"
|
|
292
582
|
? m.organization_translation_english()
|
|
293
583
|
: m.organization_translation_french();
|
|
294
584
|
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 })] }));
|
|
295
585
|
}
|
|
296
586
|
function OrganizationMembersManager({ authClient, organization, currentUserId, }) {
|
|
587
|
+
const m = useOrganizationMessages();
|
|
297
588
|
const [members, setMembers] = useState([]);
|
|
298
589
|
const [invitations, setInvitations] = useState([]);
|
|
299
590
|
const [error, setError] = useState(null);
|
|
@@ -398,19 +689,21 @@ function OrganizationMembersManager({ authClient, organization, currentUserId, }
|
|
|
398
689
|
event.stopPropagation();
|
|
399
690
|
inviteForm.handleSubmit();
|
|
400
691
|
}, 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) => ({
|
|
401
|
-
label: organizationRoleLabel(role),
|
|
692
|
+
label: organizationRoleLabel(role, m),
|
|
402
693
|
value: role,
|
|
403
694
|
})) })) }), _jsx("div", { className: "self-end", children: _jsx(inviteForm.SubmitButton, {}) }), _jsx(inviteForm.FormError, {})] }) }), error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex 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(DataTable, { columns: memberColumns({
|
|
695
|
+
m,
|
|
404
696
|
currentUserId,
|
|
405
697
|
updatingMemberId,
|
|
406
698
|
onRemove: removeMember,
|
|
407
699
|
onRoleChange: updateRole,
|
|
408
700
|
}), data: members, emptyLabel: loading ? m.user_loading() : m.organization_members_empty(), exportFileName: `${organization.slug}-members.csv`, features: { gallery: false } })] }), _jsxs("section", { className: "flex 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(DataTable, { columns: invitationColumns({
|
|
701
|
+
m,
|
|
409
702
|
cancellingInvitationId,
|
|
410
703
|
onCancel: cancelInvitation,
|
|
411
704
|
}), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false } })] })] }));
|
|
412
705
|
}
|
|
413
|
-
const memberColumns = ({ currentUserId, updatingMemberId, onRemove, onRoleChange, }) => [
|
|
706
|
+
const memberColumns = ({ m, currentUserId, updatingMemberId, onRemove, onRoleChange, }) => [
|
|
414
707
|
{
|
|
415
708
|
id: "user",
|
|
416
709
|
header: m.organization_member_user(),
|
|
@@ -423,13 +716,13 @@ const memberColumns = ({ currentUserId, updatingMemberId, onRemove, onRoleChange
|
|
|
423
716
|
const member = row.original;
|
|
424
717
|
const disabled = updatingMemberId === member.id;
|
|
425
718
|
return (_jsxs(Select, { items: organizationRoles.map((role) => ({
|
|
426
|
-
label: organizationRoleLabel(role),
|
|
719
|
+
label: organizationRoleLabel(role, m),
|
|
427
720
|
value: role,
|
|
428
721
|
})), value: normalizeOrganizationRole(member.role), onValueChange: (value) => {
|
|
429
722
|
if (value === "owner" || value === "admin" || value === "member") {
|
|
430
723
|
onRoleChange(member, value);
|
|
431
724
|
}
|
|
432
|
-
}, disabled: disabled, children: [_jsx(SelectTrigger, { className: "w-36", onClick: (event) => event.stopPropagation(), children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: organizationRoles.map((role) => (_jsx(SelectItem, { value: role, children: organizationRoleLabel(role) }, role))) })] }));
|
|
725
|
+
}, disabled: disabled, children: [_jsx(SelectTrigger, { className: "w-36", onClick: (event) => event.stopPropagation(), children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: organizationRoles.map((role) => (_jsx(SelectItem, { value: role, children: organizationRoleLabel(role, m) }, role))) })] }));
|
|
433
726
|
},
|
|
434
727
|
},
|
|
435
728
|
{
|
|
@@ -447,7 +740,7 @@ const memberColumns = ({ currentUserId, updatingMemberId, onRemove, onRoleChange
|
|
|
447
740
|
},
|
|
448
741
|
]),
|
|
449
742
|
];
|
|
450
|
-
const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
|
|
743
|
+
const invitationColumns = ({ m, cancellingInvitationId, onCancel, }) => [
|
|
451
744
|
{
|
|
452
745
|
accessorKey: "email",
|
|
453
746
|
header: m.organization_member_email(),
|
|
@@ -456,7 +749,7 @@ const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
|
|
|
456
749
|
{
|
|
457
750
|
accessorKey: "role",
|
|
458
751
|
header: m.organization_member_role(),
|
|
459
|
-
cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role) })),
|
|
752
|
+
cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role, m) })),
|
|
460
753
|
},
|
|
461
754
|
{
|
|
462
755
|
accessorKey: "status",
|
|
@@ -479,6 +772,7 @@ const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
|
|
|
479
772
|
]),
|
|
480
773
|
];
|
|
481
774
|
function OrganizationApiKeyManager({ authClient, organization, }) {
|
|
775
|
+
const m = useOrganizationMessages();
|
|
482
776
|
const [keys, setKeys] = useState([]);
|
|
483
777
|
const [createdKey, setCreatedKey] = useState(null);
|
|
484
778
|
const [error, setError] = useState(null);
|
|
@@ -539,9 +833,9 @@ function OrganizationApiKeyManager({ authClient, organization, }) {
|
|
|
539
833
|
event.preventDefault();
|
|
540
834
|
event.stopPropagation();
|
|
541
835
|
createForm.handleSubmit();
|
|
542
|
-
}, 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, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ onDelete: deleteKey }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false } })] }));
|
|
836
|
+
}, 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, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m, onDelete: deleteKey }), data: keys, emptyLabel: loading ? m.user_loading() : m.table_empty(), exportFileName: `${organization.slug}-api-keys.csv`, features: { gallery: false } })] }));
|
|
543
837
|
}
|
|
544
|
-
const apiKeyColumns = ({ onDelete, }) => [
|
|
838
|
+
const apiKeyColumns = ({ m, onDelete, }) => [
|
|
545
839
|
{
|
|
546
840
|
accessorKey: "name",
|
|
547
841
|
header: m.user_api_key_name(),
|