@krak-stack/auth 0.1.13 → 0.1.15

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,9 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useStore } from "@tanstack/react-form";
2
3
  import {} from "@tanstack/react-table";
3
4
  import { Schema } from "effect";
4
- import { Building2, ChevronsUpDown, KeyRound, PencilIcon, Trash2, UserPlus, Users, } from "lucide-react";
5
- import { useEffect, useEffectEvent, useState, } from "react";
5
+ import { Building2, Check, ChevronsUpDown, KeyRound, Mail, PencilIcon, Plus, Trash2, UserPlus, Users, X, } from "lucide-react";
6
+ import { createContext, useContext, useEffect, useEffectEvent, useState, } from "react";
6
7
  import { createDataTableActionsColumn, DataTable, } from "@/components/ui/data-table";
7
8
  import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
8
9
  import { AppBrand } from "@/components/ui/app-brand";
@@ -14,17 +15,202 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem,
14
15
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
15
16
  import { Separator } from "@/components/ui/separator";
16
17
  import { cn } from "@/lib/utils";
17
- import { m } from "@/paraglide/messages";
18
- import { getLocale } from "@/paraglide/runtime";
19
18
  import { OrganizationMetadata, } from "@krak-stack/auth/schema";
19
+ const messages = {
20
+ en: {
21
+ api_key_rate_limit_notice: "API keys are subject to the same rate limits as your account.",
22
+ organization_contact_email: "Contact email",
23
+ organization_create_description: "Create a workspace for team-based access.",
24
+ organization_create_error: "Could not create the organization.",
25
+ organization_create_slug_conflict: "That organization slug is already in use. Choose a different slug.",
26
+ organization_create_title: "Create organization",
27
+ organization_edit_description: "Update the active organization's canonical details and localized profile.",
28
+ organization_invitation_cancel: "Cancel invitation",
29
+ organization_invitation_cancel_error: "Could not cancel the invitation.",
30
+ organization_invitation_accept: "Accept invitation",
31
+ organization_invitation_accept_error: "Could not accept the invitation.",
32
+ organization_invitation_accepted: "Invitation accepted.",
33
+ organization_invitation_expires: "Expires",
34
+ organization_invitation_organization: "Organization",
35
+ organization_invitation_reject: "Decline invitation",
36
+ organization_invitation_reject_error: "Could not decline the invitation.",
37
+ organization_invitation_rejected: "Invitation declined.",
38
+ organization_invitation_status: "Status",
39
+ organization_invitations_description: "Track invitations that have not been accepted yet.",
40
+ organization_invitations_empty: "No pending invitations.",
41
+ organization_invitations_heading: "Pending invitations",
42
+ organization_invitations_load_error: "Could not load organization invitations.",
43
+ organization_user_invitations_description: "Review invitations sent to your email address and choose which organizations to join.",
44
+ organization_user_invitations_empty: "You have no pending invitations.",
45
+ organization_user_invitations_title: "Organization invitations",
46
+ organization_invite_error: "Could not send the invitation.",
47
+ organization_invite_member_description: "Send an invitation to join this organization with the selected role.",
48
+ organization_invite_member_title: "Invite a member",
49
+ organization_loading: "Loading...",
50
+ organization_location: "Location",
51
+ organization_icon: "Icon",
52
+ organization_logo: "Logo",
53
+ organization_logo_upload_error: "Could not upload the organization logo.",
54
+ organization_member_email: "Email",
55
+ organization_member_joined: "Joined",
56
+ organization_member_remove: "Remove member",
57
+ organization_member_remove_error: "Could not remove the member.",
58
+ organization_member_role: "Role",
59
+ organization_member_role_error: "Could not update the member role.",
60
+ organization_member_user: "User",
61
+ organization_members_description: "Review active members, update roles, and remove access when needed.",
62
+ organization_members_empty: "No members found.",
63
+ organization_members_heading: "Organization members",
64
+ organization_members_load_error: "Could not load organization members.",
65
+ organization_members_title: "Members",
66
+ organization_name: "Organization name",
67
+ organization_role_admin: "Admin",
68
+ organization_role_member: "Member",
69
+ organization_role_owner: "Owner",
70
+ organization_slug: "Organization slug",
71
+ organization_slug_description: "Leave blank to generate one from the name.",
72
+ organization_switcher_empty: "You do not belong to any organizations yet.",
73
+ organization_switcher_label: "Organization",
74
+ organization_switcher_manage: "Manage organization",
75
+ organization_switcher_no_other_organizations: "No other organizations.",
76
+ organization_translation_description: "Localized organization details stored in metadata.",
77
+ organization_translation_english: "English profile",
78
+ organization_translation_french: "French profile",
79
+ organization_translation_name: "Localized name",
80
+ organization_update_error: "Could not update the organization.",
81
+ table_empty: "No results.",
82
+ user_api_key_create_error: "Could not create the API key.",
83
+ user_api_key_created_description: "Copy this key now. You will not be able to see it again.",
84
+ user_api_key_created_title: "API key created",
85
+ user_api_key_delete_error: "Could not delete the API key.",
86
+ user_api_key_disabled: "Disabled",
87
+ user_api_key_enabled: "Enabled",
88
+ user_api_key_hidden: "Secret hidden",
89
+ user_api_key_name: "Key name",
90
+ user_api_key_starts_with: "Starts with {start}",
91
+ user_api_key_status: "Status",
92
+ user_api_keys_load_error: "Could not load API keys.",
93
+ user_api_keys_title: "API keys",
94
+ user_button_api_keys: "API keys",
95
+ user_delete: "Delete",
96
+ user_loading: "Loading...",
97
+ },
98
+ fr: {
99
+ api_key_rate_limit_notice: "Les clés API sont soumises aux mêmes limites de débit que votre compte.",
100
+ organization_contact_email: "E-mail de contact",
101
+ organization_create_description: "Créez un espace de travail pour l'accès en équipe.",
102
+ organization_create_error: "Impossible de créer l'organisation.",
103
+ organization_create_slug_conflict: "Ce slug d'organisation est déjà utilisé. Choisissez un autre slug.",
104
+ organization_create_title: "Créer une organisation",
105
+ organization_edit_description: "Mettez à jour les détails canoniques et le profil localisé de l'organisation active.",
106
+ organization_invitation_cancel: "Annuler l'invitation",
107
+ organization_invitation_cancel_error: "Impossible d'annuler l'invitation.",
108
+ organization_invitation_accept: "Accepter l'invitation",
109
+ organization_invitation_accept_error: "Impossible d'accepter l'invitation.",
110
+ organization_invitation_accepted: "Invitation acceptée.",
111
+ organization_invitation_expires: "Expire le",
112
+ organization_invitation_organization: "Organisation",
113
+ organization_invitation_reject: "Refuser l'invitation",
114
+ organization_invitation_reject_error: "Impossible de refuser l'invitation.",
115
+ organization_invitation_rejected: "Invitation refusée.",
116
+ organization_invitation_status: "Statut",
117
+ organization_invitations_description: "Suivez les invitations qui n'ont pas encore été acceptées.",
118
+ organization_invitations_empty: "Aucune invitation en attente.",
119
+ organization_invitations_heading: "Invitations en attente",
120
+ organization_invitations_load_error: "Impossible de charger les invitations de l'organisation.",
121
+ organization_user_invitations_description: "Consultez les invitations envoyées à votre adresse courriel et choisissez les organisations à rejoindre.",
122
+ organization_user_invitations_empty: "Vous n'avez aucune invitation en attente.",
123
+ organization_user_invitations_title: "Invitations d'organisation",
124
+ organization_invite_error: "Impossible d'envoyer l'invitation.",
125
+ organization_invite_member_description: "Envoyez une invitation à rejoindre cette organisation avec le rôle sélectionné.",
126
+ organization_invite_member_title: "Inviter un membre",
127
+ organization_loading: "Chargement...",
128
+ organization_location: "Emplacement",
129
+ organization_icon: "Icône",
130
+ organization_logo: "Logo",
131
+ organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.",
132
+ organization_member_email: "Courriel",
133
+ organization_member_joined: "Arrivée",
134
+ organization_member_remove: "Retirer le membre",
135
+ organization_member_remove_error: "Impossible de retirer le membre.",
136
+ organization_member_role: "Rôle",
137
+ organization_member_role_error: "Impossible de modifier le rôle du membre.",
138
+ organization_member_user: "Utilisateur",
139
+ organization_members_description: "Consultez les membres actifs, modifiez les rôles et retirez les accès au besoin.",
140
+ organization_members_empty: "Aucun membre trouvé.",
141
+ organization_members_heading: "Membres de l'organisation",
142
+ organization_members_load_error: "Impossible de charger les membres de l'organisation.",
143
+ organization_members_title: "Membres",
144
+ organization_name: "Nom de l'organisation",
145
+ organization_role_admin: "Admin",
146
+ organization_role_member: "Membre",
147
+ organization_role_owner: "Propriétaire",
148
+ organization_slug: "Slug de l'organisation",
149
+ organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
150
+ organization_switcher_empty: "Vous n'appartenez encore à aucune organisation.",
151
+ organization_switcher_label: "Organisation",
152
+ organization_switcher_manage: "Gérer l'organisation",
153
+ organization_switcher_no_other_organizations: "Aucune autre organisation.",
154
+ organization_translation_description: "Détails localisés de l'organisation stockés dans les métadonnées.",
155
+ organization_translation_english: "Profil anglais",
156
+ organization_translation_french: "Profil français",
157
+ organization_translation_name: "Nom localisé",
158
+ organization_update_error: "Impossible de mettre à jour l'organisation.",
159
+ table_empty: "Aucun résultat.",
160
+ user_api_key_create_error: "Impossible de créer la clé API.",
161
+ user_api_key_created_description: "Copiez cette clé maintenant. Vous ne pourrez plus la voir.",
162
+ user_api_key_created_title: "Clé API créée",
163
+ user_api_key_delete_error: "Impossible de supprimer la clé API.",
164
+ user_api_key_disabled: "Désactivée",
165
+ user_api_key_enabled: "Activée",
166
+ user_api_key_hidden: "Secret masqué",
167
+ user_api_key_name: "Nom de la clé",
168
+ user_api_key_starts_with: "Commence par {start}",
169
+ user_api_key_status: "Statut",
170
+ user_api_keys_load_error: "Impossible de charger les clés API.",
171
+ user_api_keys_title: "Clés API",
172
+ user_button_api_keys: "Clés API",
173
+ user_delete: "Supprimer",
174
+ user_loading: "Chargement...",
175
+ },
176
+ };
177
+ const getLocale = () => (globalThis.document?.documentElement.lang ||
178
+ globalThis.navigator?.language ||
179
+ "en")
180
+ .toLowerCase()
181
+ .startsWith("fr")
182
+ ? "fr"
183
+ : "en";
184
+ const organizationSwitcherMessages = (overrides) => ({
185
+ ...(getLocale().startsWith("fr") ? messages.fr : messages.en),
186
+ ...overrides,
187
+ });
188
+ const interpolate = (value, params) => params
189
+ ? value.replace(/\{([^}]+)\}/g, (_, key) => String(params[key] ?? `{${key}}`))
190
+ : value;
191
+ const organizationMessageFns = (labels) => new Proxy({}, {
192
+ get: (_target, key) => (params) => interpolate(labels[key], params),
193
+ });
194
+ const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
195
+ const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
20
196
  const slugify = (value) => value
21
197
  .trim()
22
198
  .toLowerCase()
23
199
  .replace(/[^a-z0-9]+/g, "-")
24
200
  .replace(/^-+|-+$/g, "");
201
+ const isOrganizationSlugConflict = (error) => {
202
+ if (!isRecord(error))
203
+ return false;
204
+ const code = typeof error.code === "string" ? error.code : "";
205
+ const message = typeof error.message === "string" ? error.message : "";
206
+ return [code, message].some((value) => {
207
+ const normalized = value.toLowerCase().replaceAll("_", " ");
208
+ return normalized.includes("organization already exists");
209
+ });
210
+ };
25
211
  const nullableString = (value) => typeof value === "string" && value.trim() ? value.trim() : null;
26
212
  const centralAuthUrl = (path) => new URL(path, import.meta.env.VITE_KRAKSTACK_AUTH_URL).toString();
27
- const parsePresignedUpload = (value) => {
213
+ const parsePresignedUpload = (value, m) => {
28
214
  if (!isRecord(value) ||
29
215
  typeof value.uploadUrl !== "string" ||
30
216
  typeof value.url !== "string") {
@@ -33,7 +219,7 @@ const parsePresignedUpload = (value) => {
33
219
  return { uploadUrl: value.uploadUrl, url: value.url };
34
220
  };
35
221
  const isRecord = (value) => typeof value === "object" && value !== null;
36
- const uploadOrganizationLogo = async (file) => {
222
+ const uploadOrganizationLogo = async (file, m) => {
37
223
  const contentType = file.type || "image/png";
38
224
  const presignResponse = await fetch(centralAuthUrl("/api/organizations/logo/presign"), {
39
225
  method: "POST",
@@ -44,7 +230,7 @@ const uploadOrganizationLogo = async (file) => {
44
230
  if (!presignResponse.ok) {
45
231
  throw new Error(m.organization_logo_upload_error());
46
232
  }
47
- const presigned = parsePresignedUpload(await presignResponse.json());
233
+ const presigned = parsePresignedUpload(await presignResponse.json(), m);
48
234
  const uploadResponse = await fetch(presigned.uploadUrl, {
49
235
  method: "PUT",
50
236
  headers: { "Content-Type": contentType },
@@ -70,7 +256,7 @@ const findOrganizationTranslation = (organization, locale = currentOrganizationL
70
256
  translations.find((translation) => translation.locale === "en") ??
71
257
  translations[0]);
72
258
  };
73
- const organizationDisplay = (organization) => {
259
+ const organizationDisplay = (organization, m) => {
74
260
  const translation = organization
75
261
  ? findOrganizationTranslation(organization)
76
262
  : undefined;
@@ -92,19 +278,23 @@ const organizationFormDefaults = (organization) => {
92
278
  enName: en?.name || organization?.name || "",
93
279
  enLogo: null,
94
280
  enLogoUrl: en?.logo ?? "",
281
+ enIcon: null,
282
+ enIconUrl: en?.icon ?? "",
95
283
  enContactEmail: en?.contactEmail ?? "",
96
284
  enLocation: en?.location ?? "",
97
285
  frName: fr?.name ?? "",
98
286
  frLogo: null,
99
287
  frLogoUrl: fr?.logo ?? "",
288
+ frIcon: null,
289
+ frIconUrl: fr?.icon ?? "",
100
290
  frContactEmail: fr?.contactEmail ?? "",
101
291
  frLocation: fr?.location ?? "",
102
292
  };
103
293
  };
104
- const organizationLogoFromForm = async (file, fallback) => file ? await uploadOrganizationLogo(file) : nullableString(fallback);
294
+ const organizationLogoFromForm = async (file, fallback, m) => (file ? await uploadOrganizationLogo(file, m) : nullableString(fallback));
105
295
  const organizationRoles = ["owner", "admin", "member"];
106
296
  const normalizeOrganizationRole = (role) => role === "owner" || role === "admin" || role === "member" ? role : "member";
107
- const organizationRoleLabel = (role) => {
297
+ const organizationRoleLabel = (role, m) => {
108
298
  switch (normalizeOrganizationRole(role)) {
109
299
  case "owner":
110
300
  return m.organization_role_owner();
@@ -122,17 +312,20 @@ const initialsFromName = (name) => name
122
312
  .map((part) => part[0])
123
313
  .join("")
124
314
  .toUpperCase() || "?";
125
- const organizationMetadataFromForm = async (value) => {
315
+ const organizationMetadataFromForm = async (value, m) => {
126
316
  const translations = [];
127
317
  const enName = value.enName.trim() || value.name.trim();
128
318
  const frName = value.frName.trim();
129
- const enLogo = await organizationLogoFromForm(value.enLogo, value.enLogoUrl);
130
- const frLogo = await organizationLogoFromForm(value.frLogo, value.frLogoUrl);
319
+ const enLogo = await organizationLogoFromForm(value.enLogo, value.enLogoUrl, m);
320
+ const enIcon = await organizationLogoFromForm(value.enIcon, value.enIconUrl, m);
321
+ const frLogo = await organizationLogoFromForm(value.frLogo, value.frLogoUrl, m);
322
+ const frIcon = await organizationLogoFromForm(value.frIcon, value.frIconUrl, m);
131
323
  if (enName) {
132
324
  translations.push({
133
325
  locale: "en",
134
326
  name: enName,
135
327
  logo: enLogo,
328
+ icon: enIcon,
136
329
  contactEmail: nullableString(value.enContactEmail),
137
330
  location: nullableString(value.enLocation),
138
331
  });
@@ -142,17 +335,43 @@ const organizationMetadataFromForm = async (value) => {
142
335
  locale: "fr",
143
336
  name: frName,
144
337
  logo: frLogo,
338
+ icon: frIcon,
145
339
  contactEmail: nullableString(value.frContactEmail),
146
340
  location: nullableString(value.frLocation),
147
341
  });
148
342
  }
149
343
  return { translations };
150
344
  };
151
- export function OrganizationSwitcher({ authClient, side = "bottom", className, renderUnauthenticated, locked = false, }) {
345
+ export function OrganizationSwitcher({ authClient, side = "bottom", className, renderUnauthenticated, locked = false, messages, onChange, onCreate, }) {
346
+ const labels = organizationSwitcherMessages(messages);
347
+ const m = organizationMessageFns(labels);
152
348
  const session = authClient.useSession();
153
349
  const organizations = authClient.useListOrganizations();
154
350
  const activeOrganization = authClient.useActiveOrganization();
155
351
  const [dialog, setDialog] = useState(null);
352
+ const sessionUserId = session.data?.user.id;
353
+ const [userInvitations, setUserInvitations] = useState([]);
354
+ const [userInvitationsError, setUserInvitationsError] = useState(null);
355
+ const [loadingUserInvitations, setLoadingUserInvitations] = useState(false);
356
+ const loadUserInvitations = useEffectEvent(async () => {
357
+ if (!session.data)
358
+ return;
359
+ setLoadingUserInvitations(true);
360
+ setUserInvitationsError(null);
361
+ const result = await authClient.organization.listUserInvitations({});
362
+ if (result.error) {
363
+ setUserInvitationsError(result.error.message ?? m.organization_invitations_load_error());
364
+ setLoadingUserInvitations(false);
365
+ return;
366
+ }
367
+ setUserInvitations(result.data ?? []);
368
+ setLoadingUserInvitations(false);
369
+ });
370
+ useEffect(() => {
371
+ if (!sessionUserId)
372
+ return;
373
+ void loadUserInvitations();
374
+ }, [sessionUserId]);
156
375
  if (!session.data) {
157
376
  return _jsx(_Fragment, { children: renderUnauthenticated?.() });
158
377
  }
@@ -165,39 +384,141 @@ export function OrganizationSwitcher({ authClient, side = "bottom", className, r
165
384
  const refresh = async () => {
166
385
  await organizations.refetch();
167
386
  await activeOrganization.refetch();
387
+ await session.refetch();
388
+ };
389
+ const refreshAfterInvitationAction = async (previousActiveId) => {
390
+ await loadUserInvitations();
391
+ await refresh();
392
+ if (locked && previousActiveId) {
393
+ const result = await authClient.organization.setActive({
394
+ organizationId: previousActiveId,
395
+ });
396
+ if (!result.error) {
397
+ await refresh();
398
+ onChange?.(organizations.data?.find((organization) => organization.id === previousActiveId) ?? null);
399
+ }
400
+ }
168
401
  };
169
- const activeDisplay = organizationDisplay(active ?? null);
170
- return (_jsxs(_Fragment, { 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
402
+ const activeDisplay = organizationDisplay(active ?? null, m);
403
+ 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
404
  ? activeDisplay.name
172
405
  : 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
406
  ? { imageSrc: activeDisplay.logo }
174
407
  : {}) }), _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
408
  ? { imageSrc: activeDisplay.logo }
176
409
  : {}) }) }), 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);
410
+ const display = organizationDisplay(organization, m);
178
411
  return (_jsx(DropdownMenuItem, { onClick: async () => {
179
412
  const result = await authClient.organization.setActive({
180
413
  organizationId: organization.id,
181
414
  });
182
- if (!result.error)
415
+ if (!result.error) {
183
416
  await refresh();
417
+ onChange?.(organization);
418
+ }
184
419
  }, 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
420
  })) : !locked && !organizations.isPending ? (_jsx(DropdownMenuItem, { disabled: true, children: active
186
421
  ? m.organization_switcher_no_other_organizations()
187
- : m.organization_switcher_empty() })) : null, !locked ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Building2, {}), m.organization_create_title()] })] })) : 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) => {
422
+ : m.organization_switcher_empty() })) : null, _jsx(DropdownMenuSeparator, {}), !locked ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("create"), children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => {
423
+ setDialog("invitations");
424
+ void loadUserInvitations();
425
+ }, 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
426
  setDialog((current) => open ? "create" : current === "create" ? null : current);
189
- }, 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
- await refresh();
427
+ }, 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 (organization) => {
428
+ onCreate?.(organization);
191
429
  setDialog(null);
430
+ const activeResult = await authClient.organization.setActive({
431
+ organizationId: organization.id,
432
+ });
433
+ await refresh();
434
+ if (!activeResult.error)
435
+ onChange?.(organization);
192
436
  } })] }) }), _jsx(Dialog, { open: dialog === "manage", onOpenChange: (open) => {
193
437
  setDialog((current) => open ? "manage" : current === "manage" ? null : current);
194
438
  }, 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 ? (_jsx(EditOrganizationSection, { authClient: authClient, organization: activeOrganization.data, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
195
439
  setDialog((current) => open ? "members" : current === "members" ? null : current);
196
440
  }, 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
441
  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] }) })] }));
442
+ }, 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) => {
443
+ setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
444
+ }, 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 })] }) })] }));
445
+ }
446
+ function UserInvitationsManager({ authClient, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
447
+ const m = useOrganizationMessages();
448
+ const [actingInvitationId, setActingInvitationId] = useState(null);
449
+ const [actionError, setActionError] = useState(null);
450
+ const acceptInvitation = async (invitation) => {
451
+ setActingInvitationId(invitation.id);
452
+ setActionError(null);
453
+ const result = await authClient.organization.acceptInvitation({
454
+ invitationId: invitation.id,
455
+ });
456
+ setActingInvitationId(null);
457
+ if (result.error) {
458
+ setActionError(result.error.message ?? m.organization_invitation_accept_error());
459
+ return;
460
+ }
461
+ await onActionComplete(activeOrganizationId);
462
+ };
463
+ const rejectInvitation = async (invitation) => {
464
+ setActingInvitationId(invitation.id);
465
+ setActionError(null);
466
+ const result = await authClient.organization.rejectInvitation({
467
+ invitationId: invitation.id,
468
+ });
469
+ setActingInvitationId(null);
470
+ if (result.error) {
471
+ setActionError(result.error.message ?? m.organization_invitation_reject_error());
472
+ return;
473
+ }
474
+ await onActionComplete(activeOrganizationId);
475
+ };
476
+ 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({
477
+ m,
478
+ actingInvitationId,
479
+ onAccept: acceptInvitation,
480
+ onReject: rejectInvitation,
481
+ }), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_user_invitations_empty(), exportFileName: "organization-invitations.csv", features: { gallery: false } })] }));
199
482
  }
483
+ const userInvitationColumns = ({ m, actingInvitationId, onAccept, onReject, }) => [
484
+ {
485
+ accessorKey: "organizationName",
486
+ header: m.organization_invitation_organization(),
487
+ 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 })] })),
488
+ },
489
+ {
490
+ accessorKey: "role",
491
+ header: m.organization_member_role(),
492
+ cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role, m) })),
493
+ },
494
+ {
495
+ accessorKey: "status",
496
+ header: m.organization_invitation_status(),
497
+ cell: ({ row }) => _jsx(Badge, { children: row.original.status }),
498
+ },
499
+ {
500
+ accessorKey: "expiresAt",
501
+ header: m.organization_invitation_expires(),
502
+ cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(row.original.expiresAt) })),
503
+ },
504
+ createDataTableActionsColumn([
505
+ {
506
+ name: m.organization_invitation_accept(),
507
+ icon: _jsx(Check, {}),
508
+ visible: (invitation) => actingInvitationId !== invitation.id,
509
+ onClick: onAccept,
510
+ },
511
+ {
512
+ name: m.organization_invitation_reject(),
513
+ icon: _jsx(X, {}),
514
+ variant: "destructive",
515
+ visible: (invitation) => actingInvitationId !== invitation.id,
516
+ onClick: onReject,
517
+ },
518
+ ]),
519
+ ];
200
520
  function EditOrganizationSection({ authClient, organization, onUpdated, }) {
521
+ const m = useOrganizationMessages();
201
522
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
202
523
  const defaultValues = organizationFormDefaults(organization);
203
524
  const form = useAppForm({
@@ -206,7 +527,7 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
206
527
  formApi.setErrorMap({ onSubmit: undefined });
207
528
  const name = value.name.trim();
208
529
  const slug = value.slug.trim().toLowerCase();
209
- const metadata = await organizationMetadataFromForm(value);
530
+ const metadata = await organizationMetadataFromForm(value, m);
210
531
  const result = await authClient.organization.update({
211
532
  organizationId: organization.id,
212
533
  data: { name, slug, metadata },
@@ -228,18 +549,39 @@ function EditOrganizationSection({ authClient, organization, onUpdated, }) {
228
549
  event.stopPropagation();
229
550
  form.handleSubmit();
230
551
  }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), required: true })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.enLogoUrl, size: {
552
+ width: 175,
553
+ height: 50,
554
+ suggestedWidth: 350,
555
+ suggestedHeight: 100,
556
+ } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.enIconUrl, size: {
231
557
  width: 96,
232
558
  height: 96,
233
559
  suggestedWidth: 512,
234
560
  suggestedHeight: 512,
235
561
  } })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.frLogoUrl, size: {
562
+ width: 175,
563
+ height: 50,
564
+ suggestedWidth: 350,
565
+ suggestedHeight: 100,
566
+ } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.frIconUrl, size: {
236
567
  width: 96,
237
568
  height: 96,
238
569
  suggestedWidth: 512,
239
570
  suggestedHeight: 512,
240
571
  } })) }), _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
572
  }
573
+ function CreateOrganizationSlugAutoFill({ form, }) {
574
+ const name = useStore(form.store, (state) => state.values.name);
575
+ const slugIsDirty = useStore(form.store, (state) => state.fieldMeta.slug?.isDirty ?? false);
576
+ useEffect(() => {
577
+ if (!slugIsDirty) {
578
+ form.setFieldValue("slug", slugify(name), { dontUpdateMeta: true });
579
+ }
580
+ }, [form, name, slugIsDirty]);
581
+ return null;
582
+ }
242
583
  function CreateOrganizationSection({ authClient, onCreated, }) {
584
+ const m = useOrganizationMessages();
243
585
  const [editingLocale, setEditingLocale] = useState(currentOrganizationLocale());
244
586
  const defaultValues = organizationFormDefaults();
245
587
  const form = useAppForm({
@@ -252,13 +594,23 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
252
594
  ...value,
253
595
  name,
254
596
  slug,
255
- });
597
+ }, m);
256
598
  const result = await authClient.organization.create({
257
599
  name,
258
600
  slug,
259
601
  metadata,
260
602
  });
261
603
  if (result.error) {
604
+ if (isOrganizationSlugConflict(result.error)) {
605
+ formApi.setErrorMap({
606
+ onSubmit: {
607
+ fields: {
608
+ slug: { message: m.organization_create_slug_conflict() },
609
+ },
610
+ },
611
+ });
612
+ return;
613
+ }
262
614
  formApi.setErrorMap({
263
615
  onSubmit: {
264
616
  form: result.error.message ?? m.organization_create_error(),
@@ -268,19 +620,29 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
268
620
  return;
269
621
  }
270
622
  form.reset();
271
- await onCreated();
623
+ await onCreated(result.data);
272
624
  },
273
625
  });
274
626
  return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.AppForm, { children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
275
627
  event.preventDefault();
276
628
  event.stopPropagation();
277
629
  form.handleSubmit();
278
- }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.enLogoUrl, size: {
630
+ }, children: [_jsx(form.AppField, { name: "name", children: (field) => (_jsx(field.TextField, { label: m.organization_name(), required: true })) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug(), description: m.organization_slug_description() })) }), _jsx(CreateOrganizationSlugAutoFill, { form: form }), _jsx(Separator, { className: "my-2" }), editingLocale === "en" ? (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "en", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "enName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name(), required: true })) }), _jsx(form.AppField, { name: "enLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.enLogoUrl, size: {
631
+ width: 175,
632
+ height: 50,
633
+ suggestedWidth: 350,
634
+ suggestedHeight: 100,
635
+ } })) }), _jsx(form.AppField, { name: "enIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.enIconUrl, size: {
279
636
  width: 96,
280
637
  height: 96,
281
638
  suggestedWidth: 512,
282
639
  suggestedHeight: 512,
283
640
  } })) }), _jsx(form.AppField, { name: "enContactEmail", children: (field) => (_jsx(field.TextField, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" })) }), _jsx(form.AppField, { name: "enLocation", children: (field) => (_jsx(field.TextField, { label: m.organization_location() })) })] })) : (_jsxs(_Fragment, { children: [_jsx(OrganizationTranslationHeader, { locale: "fr", editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsx(form.AppField, { name: "frName", children: (field) => (_jsx(field.TextField, { label: m.organization_translation_name() })) }), _jsx(form.AppField, { name: "frLogo", children: (field) => (_jsx(field.ImageField, { label: m.organization_logo(), defaultImageUrl: defaultValues.frLogoUrl, size: {
641
+ width: 175,
642
+ height: 50,
643
+ suggestedWidth: 350,
644
+ suggestedHeight: 100,
645
+ } })) }), _jsx(form.AppField, { name: "frIcon", children: (field) => (_jsx(field.ImageField, { label: m.organization_icon(), defaultImageUrl: defaultValues.frIconUrl, size: {
284
646
  width: 96,
285
647
  height: 96,
286
648
  suggestedWidth: 512,
@@ -288,12 +650,14 @@ function CreateOrganizationSection({ authClient, onCreated, }) {
288
650
  } })) }), _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
651
  }
290
652
  function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleChange, }) {
653
+ const m = useOrganizationMessages();
291
654
  const title = locale === "en"
292
655
  ? m.organization_translation_english()
293
656
  : m.organization_translation_french();
294
657
  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
658
  }
296
659
  function OrganizationMembersManager({ authClient, organization, currentUserId, }) {
660
+ const m = useOrganizationMessages();
297
661
  const [members, setMembers] = useState([]);
298
662
  const [invitations, setInvitations] = useState([]);
299
663
  const [error, setError] = useState(null);
@@ -398,19 +762,21 @@ function OrganizationMembersManager({ authClient, organization, currentUserId, }
398
762
  event.stopPropagation();
399
763
  inviteForm.handleSubmit();
400
764
  }, 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),
765
+ label: organizationRoleLabel(role, m),
402
766
  value: role,
403
767
  })) })) }), _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({
768
+ m,
404
769
  currentUserId,
405
770
  updatingMemberId,
406
771
  onRemove: removeMember,
407
772
  onRoleChange: updateRole,
408
773
  }), 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({
774
+ m,
409
775
  cancellingInvitationId,
410
776
  onCancel: cancelInvitation,
411
777
  }), data: invitations, emptyLabel: loading ? m.user_loading() : m.organization_invitations_empty(), exportFileName: `${organization.slug}-invitations.csv`, features: { gallery: false } })] })] }));
412
778
  }
413
- const memberColumns = ({ currentUserId, updatingMemberId, onRemove, onRoleChange, }) => [
779
+ const memberColumns = ({ m, currentUserId, updatingMemberId, onRemove, onRoleChange, }) => [
414
780
  {
415
781
  id: "user",
416
782
  header: m.organization_member_user(),
@@ -423,13 +789,13 @@ const memberColumns = ({ currentUserId, updatingMemberId, onRemove, onRoleChange
423
789
  const member = row.original;
424
790
  const disabled = updatingMemberId === member.id;
425
791
  return (_jsxs(Select, { items: organizationRoles.map((role) => ({
426
- label: organizationRoleLabel(role),
792
+ label: organizationRoleLabel(role, m),
427
793
  value: role,
428
794
  })), value: normalizeOrganizationRole(member.role), onValueChange: (value) => {
429
795
  if (value === "owner" || value === "admin" || value === "member") {
430
796
  onRoleChange(member, value);
431
797
  }
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))) })] }));
798
+ }, 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
799
  },
434
800
  },
435
801
  {
@@ -447,7 +813,7 @@ const memberColumns = ({ currentUserId, updatingMemberId, onRemove, onRoleChange
447
813
  },
448
814
  ]),
449
815
  ];
450
- const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
816
+ const invitationColumns = ({ m, cancellingInvitationId, onCancel, }) => [
451
817
  {
452
818
  accessorKey: "email",
453
819
  header: m.organization_member_email(),
@@ -456,7 +822,7 @@ const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
456
822
  {
457
823
  accessorKey: "role",
458
824
  header: m.organization_member_role(),
459
- cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role) })),
825
+ cell: ({ row }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(row.original.role, m) })),
460
826
  },
461
827
  {
462
828
  accessorKey: "status",
@@ -479,6 +845,7 @@ const invitationColumns = ({ cancellingInvitationId, onCancel, }) => [
479
845
  ]),
480
846
  ];
481
847
  function OrganizationApiKeyManager({ authClient, organization, }) {
848
+ const m = useOrganizationMessages();
482
849
  const [keys, setKeys] = useState([]);
483
850
  const [createdKey, setCreatedKey] = useState(null);
484
851
  const [error, setError] = useState(null);
@@ -539,9 +906,9 @@ function OrganizationApiKeyManager({ authClient, organization, }) {
539
906
  event.preventDefault();
540
907
  event.stopPropagation();
541
908
  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 } })] }));
909
+ }, 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
910
  }
544
- const apiKeyColumns = ({ onDelete, }) => [
911
+ const apiKeyColumns = ({ m, onDelete, }) => [
545
912
  {
546
913
  accessorKey: "name",
547
914
  header: m.user_api_key_name(),