@krak-stack/auth 0.1.71 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -3
- package/dist/access.d.ts +5 -7
- package/dist/access.js +11 -7
- package/dist/admin/api.group.d.ts +53 -53
- package/dist/admin/api.group.js +15 -15
- package/dist/admin/schema.d.ts +18 -18
- package/dist/admin/schema.js +3 -3
- package/dist/api.d.ts +1995 -533
- package/dist/api.js +7 -7
- package/dist/auth/api.group.d.ts +793 -0
- package/dist/auth/api.group.js +241 -0
- package/dist/auth/schema.d.ts +808 -0
- package/dist/auth/schema.js +628 -0
- package/dist/components/admin-organization-form.d.ts +1 -1
- package/dist/components/admin-organization-form.js +17 -18
- package/dist/components/admin-organizations.d.ts +4 -5
- package/dist/components/admin-organizations.js +83 -73
- package/dist/components/admin-users.d.ts +5 -6
- package/dist/components/admin-users.js +160 -181
- package/dist/components/api-key-edit-form.d.ts +4 -3
- package/dist/components/api-key-edit-form.js +33 -27
- package/dist/components/api-key-permissions.d.ts +1 -1
- package/dist/components/api-key-rate-limit.d.ts +1 -1
- package/dist/components/api-key-referrers.d.ts +3 -2
- package/dist/components/api-key-referrers.js +2 -3
- package/dist/components/api-key.d.ts +0 -9
- package/dist/components/api-key.js +0 -39
- package/dist/components/auth-atoms.d.ts +178 -0
- package/dist/components/auth-atoms.js +46 -0
- package/dist/components/auth-client-api.d.ts +1371 -556
- package/dist/components/auth-client-api.js +22 -14
- package/dist/components/auth-forms.d.ts +1 -3
- package/dist/components/auth-forms.js +173 -195
- package/dist/components/auth-provider.d.ts +16 -20
- package/dist/components/auth-provider.js +56 -30
- package/dist/components/has-permission.js +1 -1
- package/dist/components/index.d.ts +19 -20
- package/dist/components/index.js +13 -13
- package/dist/components/member-required.d.ts +1 -3
- package/dist/components/member-required.js +102 -78
- package/dist/components/organization-switcher.d.ts +4 -6
- package/dist/components/organization-switcher.js +539 -390
- package/dist/components/project-access-matrix.d.ts +1 -1
- package/dist/components/project-access-matrix.js +9 -13
- package/dist/components/user-button.d.ts +5 -3
- package/dist/components/user-button.js +291 -336
- package/dist/components/utils.d.ts +3 -1
- package/dist/components/utils.js +4 -11
- package/dist/extra/api.group.d.ts +22 -22
- package/dist/extra/api.group.js +9 -9
- package/dist/extra/schema.d.ts +1 -2
- package/dist/extra/schema.js +2 -3
- package/dist/index.d.ts +11 -12
- package/dist/index.js +11 -12
- package/dist/query.d.ts +2 -2
- package/dist/query.js +5 -5
- package/dist/roles.d.ts +5 -4
- package/dist/roles.js +11 -7
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +26 -19
- package/dist/server/actor.d.ts +20 -22
- package/dist/server/actor.js +14 -17
- package/dist/server/api.group.d.ts +29 -29
- package/dist/server/api.group.js +14 -14
- package/dist/server/index.d.ts +14 -14
- package/dist/server/index.js +8 -8
- package/dist/server/middleware.d.ts +1 -1
- package/dist/server/middleware.js +1 -1
- package/dist/server/schema.js +1 -1
- package/dist/service.d.ts +1997 -583
- package/dist/service.js +23 -16
- package/package.json +10 -9
- package/dist/better-auth/api.group.d.ts +0 -62
- package/dist/better-auth/api.group.js +0 -39
- package/dist/better-auth/schema.d.ts +0 -72
- package/dist/better-auth/schema.js +0 -110
- package/dist/components/auth-client.d.ts +0 -50
- package/dist/components/auth-client.js +0 -46
|
@@ -2,12 +2,12 @@ import { createElement as _createElement } from "react";
|
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
4
4
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
5
|
-
import { Effect, Option, Schema } from "effect";
|
|
5
|
+
import { Effect, Option, Predicate, Schema } from "effect";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
7
|
import { ArrowLeft, Building2, Check, ChevronsUpDown, Copy, KeyRound, LogOut, Mail, PencilIcon, Plus, Trash2, UserIcon, UserPlus, Users, X, } from "lucide-react";
|
|
8
8
|
import { createContext, useContext, useEffect, useEffectEvent, useRef, useState, } from "react";
|
|
9
9
|
import { DataTable, DataTableRelationshipCell, } from "@krak-stack/registry/data-table";
|
|
10
|
-
import { ErrorMessage, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
10
|
+
import { ErrorMessage, CheckboxField, ImageField, SelectField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
11
11
|
import { EditingLocaleSwitcher } from "@krak-stack/registry/editing-locale-switcher";
|
|
12
12
|
import { AppBrand } from "@krak-stack/registry/app-brand";
|
|
13
13
|
import { Field, FieldLabel, FieldSet } from "@/components/ui/field";
|
|
@@ -20,18 +20,19 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem,
|
|
|
20
20
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select";
|
|
21
21
|
import { Separator } from "@/components/ui/separator";
|
|
22
22
|
import { OrganizationEmail, OrganizationAddress, OrganizationMetadata, OrganizationPhone, OrganizationSocial, OrganizationTranslation, OrganizationWebsite, decodeOrganizationMetadata, } from "@krak-stack/auth/schema";
|
|
23
|
-
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, parseRoleList, } from "../roles";
|
|
24
|
-
import { authClientApi } from "./auth-client-api";
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import { ApiKeyPermissions } from "./api-key-permissions";
|
|
29
|
-
import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit";
|
|
30
|
-
import { ApiKeyReferrers } from "./api-key-referrers";
|
|
31
|
-
import { useOpenedOnce } from "./hooks";
|
|
32
|
-
import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration";
|
|
33
|
-
import { ExtraUploadedAsset } from "../extra/schema";
|
|
34
|
-
import { assetPath, assetUrl, cn } from "./utils";
|
|
23
|
+
import { isOrganizationRole, normalizeOrganizationRole, normalizeOrganizationRoles, organizationRoles, parseRoleList, } from "../roles.js";
|
|
24
|
+
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
25
|
+
import { activeAuthOrganizationAtom, authOrganizationsAtom, authSessionAtom, notifyAuthChange, } from "./auth-atoms.js";
|
|
26
|
+
import { useKrakstackAuth } from "./auth-provider.js";
|
|
27
|
+
import { parseApiKeyReferrers } from "./api-key.js";
|
|
28
|
+
import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
29
|
+
import { ApiKeyRateLimit, apiKeyUsagePercent } from "./api-key-rate-limit.js";
|
|
30
|
+
import { ApiKeyReferrers, apiKeyReferrers } from "./api-key-referrers.js";
|
|
31
|
+
import { useOpenedOnce } from "./hooks.js";
|
|
32
|
+
import { invitationDisplayStatus, isInvitationExpired, useInvitationExpirationClock, } from "./invitation-expiration.js";
|
|
33
|
+
import { ExtraUploadedAsset } from "../extra/schema.js";
|
|
34
|
+
import { assetPath, assetUrl, cn } from "./utils.js";
|
|
35
|
+
import { ExtraApiKeyPermissions } from "../extra/schema.js";
|
|
35
36
|
const messages = {
|
|
36
37
|
en: {
|
|
37
38
|
organization_back: "Back",
|
|
@@ -320,73 +321,55 @@ const organizationSwitcherMessages = (overrides) => ({
|
|
|
320
321
|
const interpolate = (value, params) => params
|
|
321
322
|
? value.replace(/\{([^}]+)\}/g, (_, key) => String(params[key] ?? `{${key}}`))
|
|
322
323
|
: value;
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
324
|
+
const interpolateMessage = (labels, key, params) => {
|
|
325
|
+
const entry = Object.entries(labels).find(([labelKey]) => labelKey === key);
|
|
326
|
+
return interpolate(entry?.[1] ?? key, params);
|
|
327
|
+
};
|
|
328
|
+
const organizationMessageFns = (labels) => {
|
|
329
|
+
return new Proxy({}, {
|
|
330
|
+
get: (_target, key) => (params) => interpolateMessage(labels, key, params),
|
|
331
|
+
});
|
|
332
|
+
};
|
|
326
333
|
const OrganizationMessagesContext = createContext(organizationMessageFns(organizationSwitcherMessages()));
|
|
327
334
|
const useOrganizationMessages = () => useContext(OrganizationMessagesContext);
|
|
328
335
|
const normalizeInvitationRole = (role) => {
|
|
329
336
|
const normalized = normalizeOrganizationRole(role);
|
|
330
337
|
return normalized === "support" ? "member" : normalized;
|
|
331
338
|
};
|
|
332
|
-
const userInvitationsAtom = Atom.family((
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
339
|
-
return (result.data ?? []).filter((invitation) => invitation.status === "pending");
|
|
340
|
-
},
|
|
341
|
-
catch: (error) => error,
|
|
342
|
-
}))));
|
|
343
|
-
const invitationOrganizationProfileAtom = Atom.family(({ baseUrl, locale, organizationId, }) => authClientApi(baseUrl).query("authExtra", "getOrganizationPublicProfile", {
|
|
339
|
+
const userInvitationsAtom = Atom.family((baseUrl) => authClientApi(baseUrl).query("auth", "organizationListUserInvitations", {
|
|
340
|
+
query: {},
|
|
341
|
+
timeToLive: "1 minute",
|
|
342
|
+
reactivityKeys: ["auth-user-invitations"],
|
|
343
|
+
}));
|
|
344
|
+
const invitationOrganizationProfileAtom = Atom.family((baseUrl) => Atom.family((organizationId) => Atom.family((locale) => authClientApi(baseUrl).query("authExtra", "getOrganizationPublicProfile", {
|
|
344
345
|
query: { locale, organizationId },
|
|
345
346
|
timeToLive: "5 minutes",
|
|
346
347
|
serializationKey: `invitation-organization:${organizationId}:${locale}`,
|
|
348
|
+
}))));
|
|
349
|
+
const organizationMembersAtom = Atom.family((baseUrl) => Atom.family((organizationId) => authClientApi(baseUrl).query("auth", "organizationListMembers", {
|
|
350
|
+
query: { organizationId },
|
|
351
|
+
timeToLive: "1 minute",
|
|
352
|
+
reactivityKeys: ["auth-organization-members", organizationId],
|
|
353
|
+
serializationKey: `organization-members:${organizationId}`,
|
|
354
|
+
})));
|
|
355
|
+
const organizationInvitationsAtom = Atom.family((baseUrl) => Atom.family((organizationId) => authClientApi(baseUrl).query("auth", "organizationListInvitations", {
|
|
356
|
+
query: { organizationId },
|
|
357
|
+
timeToLive: "1 minute",
|
|
358
|
+
reactivityKeys: ["auth-organization-invitations", organizationId],
|
|
359
|
+
serializationKey: `organization-invitations:${organizationId}`,
|
|
360
|
+
})));
|
|
361
|
+
const emptyOrganizationMembersAtom = Atom.make(Effect.succeed({ members: Array(), total: 0 }));
|
|
362
|
+
const emptyOrganizationInvitationsAtom = Atom.make(Effect.succeed(Array()));
|
|
363
|
+
const organizationApiKeysAtom = Atom.family((baseUrl) => Atom.family((organizationId) => authClientApi(baseUrl).query("auth", "apiKeyList", {
|
|
364
|
+
query: { configId: "organization", organizationId },
|
|
365
|
+
timeToLive: "1 minute",
|
|
366
|
+
reactivityKeys: ["auth-organization-api-keys", organizationId],
|
|
367
|
+
serializationKey: `organization-api-keys:${organizationId}`,
|
|
368
|
+
})));
|
|
369
|
+
const emptyOrganizationApiKeysAtom = Atom.make(Effect.succeed({
|
|
370
|
+
apiKeys: Array(),
|
|
371
|
+
total: 0,
|
|
347
372
|
}));
|
|
348
|
-
const emptyUserInvitationsAtom = Atom.make(Effect.try({
|
|
349
|
-
try: () => [],
|
|
350
|
-
catch: (error) => error,
|
|
351
|
-
}));
|
|
352
|
-
const organizationMembersAtom = Atom.family((authClient) => Atom.family((organizationId) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
353
|
-
try: async () => {
|
|
354
|
-
const [membersResult, invitationsResult] = await Promise.all([
|
|
355
|
-
authClient.organization.listMembers({
|
|
356
|
-
query: { organizationId },
|
|
357
|
-
}),
|
|
358
|
-
authClient.organization.listInvitations({
|
|
359
|
-
query: { organizationId },
|
|
360
|
-
}),
|
|
361
|
-
]);
|
|
362
|
-
if (membersResult.error) {
|
|
363
|
-
throw new Error(membersResult.error.message ?? "Could not load members.");
|
|
364
|
-
}
|
|
365
|
-
if (invitationsResult.error) {
|
|
366
|
-
throw new Error(invitationsResult.error.message ??
|
|
367
|
-
"Could not load invitations.");
|
|
368
|
-
}
|
|
369
|
-
return {
|
|
370
|
-
members: membersResult.data?.members ?? [],
|
|
371
|
-
invitations: (invitationsResult.data ?? []).filter((invitation) => invitation.status === "pending"),
|
|
372
|
-
};
|
|
373
|
-
},
|
|
374
|
-
catch: (error) => error,
|
|
375
|
-
})))));
|
|
376
|
-
const emptyOrganizationMembersAtom = Atom.make(Effect.succeed({ members: [], invitations: [] }));
|
|
377
|
-
const organizationApiKeysAtom = Atom.family((authClient) => Atom.family((organizationId) => Atom.keepAlive(Atom.make(Effect.tryPromise({
|
|
378
|
-
try: async () => {
|
|
379
|
-
const result = await authClient.apiKey.list({
|
|
380
|
-
query: { configId: "organization", organizationId },
|
|
381
|
-
});
|
|
382
|
-
if (result.error) {
|
|
383
|
-
throw new Error(result.error.message ?? "Could not load API keys.");
|
|
384
|
-
}
|
|
385
|
-
return result.data?.apiKeys ?? [];
|
|
386
|
-
},
|
|
387
|
-
catch: (error) => error,
|
|
388
|
-
})))));
|
|
389
|
-
const emptyOrganizationApiKeysAtom = Atom.make(Effect.succeed([]));
|
|
390
373
|
const organizationImageSchema = Schema.Union([
|
|
391
374
|
Schema.String,
|
|
392
375
|
Schema.instanceOf(File),
|
|
@@ -540,35 +523,46 @@ const inviteMemberFormBuilder = FormBuilder.empty
|
|
|
540
523
|
const apiKeyFormBuilder = FormBuilder.empty
|
|
541
524
|
.addField("name", Schema.NonEmptyString)
|
|
542
525
|
.addField("referrers", Schema.String);
|
|
526
|
+
const editApiKeyFormBuilder = FormBuilder.empty
|
|
527
|
+
.addField("name", Schema.NonEmptyString)
|
|
528
|
+
.addField("enabled", Schema.Boolean)
|
|
529
|
+
.addField("referrers", Schema.String)
|
|
530
|
+
.addField("permissions", Schema.Record(Schema.String, Schema.Boolean));
|
|
531
|
+
const ApiKeyPermissionsField = ({ field, props }) => (_jsx(ApiKeyPermissions, { description: props.description, idPrefix: props.idPrefix, permissions: props.permissions, labels: props.labels, selected: field.value, title: props.title, onChange: (id, checked) => field.onChange({ ...field.value, [id]: checked }) }));
|
|
543
532
|
const slugify = (value) => value
|
|
544
533
|
.trim()
|
|
545
534
|
.toLowerCase()
|
|
546
535
|
.replace(/[^a-z0-9]+/g, "-")
|
|
547
536
|
.replace(/^-+|-+$/g, "");
|
|
548
537
|
const noParentOrganization = "__none__";
|
|
549
|
-
const
|
|
550
|
-
|
|
538
|
+
const OrganizationFailure = Schema.Struct({
|
|
539
|
+
code: Schema.optional(Schema.String),
|
|
540
|
+
message: Schema.optional(Schema.String),
|
|
541
|
+
});
|
|
542
|
+
const isOrganizationSlugConflict = (cause) => {
|
|
543
|
+
const decoded = Schema.decodeUnknownOption(OrganizationFailure)(cause);
|
|
544
|
+
if (Option.isNone(decoded))
|
|
551
545
|
return false;
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
return [code, message].some((value) => {
|
|
555
|
-
if (typeof value !== "string")
|
|
546
|
+
return [decoded.value.code, decoded.value.message].some((value) => {
|
|
547
|
+
if (!value)
|
|
556
548
|
return false;
|
|
557
549
|
const normalized = value.toLowerCase().replaceAll("_", " ");
|
|
558
550
|
return normalized.includes("organization already exists");
|
|
559
551
|
});
|
|
560
552
|
};
|
|
561
|
-
const
|
|
562
|
-
const
|
|
553
|
+
const organizationFailureMessage = (cause, fallback) => {
|
|
554
|
+
const decoded = Schema.decodeUnknownOption(OrganizationFailure)(cause);
|
|
555
|
+
return Option.isSome(decoded)
|
|
556
|
+
? (decoded.value.message ?? fallback)
|
|
557
|
+
: fallback;
|
|
558
|
+
};
|
|
559
|
+
const decodeUploadedAsset = Schema.decodeUnknownEffect(ExtraUploadedAsset);
|
|
560
|
+
const OrganizationMetadataRecord = Schema.Record(Schema.String, Schema.Json);
|
|
561
|
+
const normalizeOrganizationMetadata = (metadata) => Schema.decodeUnknownEffect(Schema.fromJsonString(OrganizationMetadataRecord))(metadata);
|
|
562
|
+
const uploadImageAsset = (file, m, uploadImage) => {
|
|
563
563
|
const payload = new FormData();
|
|
564
564
|
payload.append("file", file);
|
|
565
|
-
|
|
566
|
-
const uploaded = await decodeUploadedAsset(await uploadImage({ payload }));
|
|
567
|
-
return assetPath(uploaded.url);
|
|
568
|
-
}
|
|
569
|
-
catch {
|
|
570
|
-
throw new Error(m.organization_logo_upload_error());
|
|
571
|
-
}
|
|
565
|
+
return uploadImage({ payload }).pipe(Effect.flatMap(decodeUploadedAsset), Effect.map((uploaded) => assetPath(uploaded.url)), Effect.mapError(() => new Error(m.organization_logo_upload_error())));
|
|
572
566
|
};
|
|
573
567
|
const currentOrganizationLocale = () => getLocale() === "fr" ? "fr" : "en";
|
|
574
568
|
const parseOrganizationMetadata = decodeOrganizationMetadata;
|
|
@@ -643,12 +637,12 @@ const organizationFormDefaults = (organization, baseUrl) => {
|
|
|
643
637
|
frIcon: assetUrl(fr?.icon, baseUrl) || null,
|
|
644
638
|
};
|
|
645
639
|
};
|
|
646
|
-
const organizationLogoFromForm =
|
|
640
|
+
const organizationLogoFromForm = (value, m, uploadImage) => {
|
|
647
641
|
if (value instanceof File)
|
|
648
|
-
return
|
|
649
|
-
if (
|
|
650
|
-
return assetPath(value);
|
|
651
|
-
return null;
|
|
642
|
+
return uploadImageAsset(value, m, uploadImage);
|
|
643
|
+
if (Schema.is(Schema.String)(value))
|
|
644
|
+
return Effect.succeed(assetPath(value));
|
|
645
|
+
return Effect.succeed(null);
|
|
652
646
|
};
|
|
653
647
|
const organizationNameFromForm = (value, locale) => {
|
|
654
648
|
const preferredName = locale === "fr" ? value.frName : value.enName;
|
|
@@ -684,23 +678,19 @@ const invitationStatusLabel = (status, m) => {
|
|
|
684
678
|
}
|
|
685
679
|
};
|
|
686
680
|
const formatOrganizationDate = (date) => new Intl.DateTimeFormat(getLocale(), { dateStyle: "medium" }).format(new Date(date));
|
|
687
|
-
const organizationMetadataFromForm =
|
|
681
|
+
const organizationMetadataFromForm = Effect.fn(function* (value, m, uploadImage, existingMetadata) {
|
|
688
682
|
const existing = parseOrganizationMetadata(existingMetadata);
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
decodedExistingMetadata !== null &&
|
|
694
|
-
!Array.isArray(decodedExistingMetadata)
|
|
695
|
-
? decodedExistingMetadata
|
|
696
|
-
: {};
|
|
683
|
+
const preservedMetadata = Option.getOrElse(Schema.decodeUnknownOption(Schema.Union([
|
|
684
|
+
OrganizationMetadataRecord,
|
|
685
|
+
Schema.fromJsonString(OrganizationMetadataRecord),
|
|
686
|
+
]))(existingMetadata), () => ({}));
|
|
697
687
|
const translations = [];
|
|
698
688
|
const enName = value.enName.trim();
|
|
699
689
|
const frName = value.frName.trim();
|
|
700
|
-
const enLogo =
|
|
701
|
-
const enIcon =
|
|
702
|
-
const frLogo =
|
|
703
|
-
const frIcon =
|
|
690
|
+
const enLogo = yield* organizationLogoFromForm(value.enLogo, m, uploadImage);
|
|
691
|
+
const enIcon = yield* organizationLogoFromForm(value.enIcon, m, uploadImage);
|
|
692
|
+
const frLogo = yield* organizationLogoFromForm(value.frLogo, m, uploadImage);
|
|
693
|
+
const frIcon = yield* organizationLogoFromForm(value.frIcon, m, uploadImage);
|
|
704
694
|
const localized = (values) => (values ?? []).flatMap((translation) => {
|
|
705
695
|
const label = translation.label.trim();
|
|
706
696
|
return label ? [{ ...translation, label }] : [];
|
|
@@ -718,17 +708,13 @@ const organizationMetadataFromForm = async (value, m, uploadImage, existingMetad
|
|
|
718
708
|
});
|
|
719
709
|
const phones = value.phones.flatMap((phone) => {
|
|
720
710
|
const number = phone.number.trim();
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
translations: localized(phone.translations),
|
|
729
|
-
},
|
|
730
|
-
]
|
|
731
|
-
: [];
|
|
711
|
+
if (!number)
|
|
712
|
+
return [];
|
|
713
|
+
const extension = phone.extension?.trim();
|
|
714
|
+
const result = extension
|
|
715
|
+
? { number, extension, translations: localized(phone.translations) }
|
|
716
|
+
: { number, translations: localized(phone.translations) };
|
|
717
|
+
return [result];
|
|
732
718
|
});
|
|
733
719
|
const websites = value.websites.flatMap((website) => {
|
|
734
720
|
const url = website.url.trim();
|
|
@@ -747,17 +733,22 @@ const organizationMetadataFromForm = async (value, m, uploadImage, existingMetad
|
|
|
747
733
|
: [];
|
|
748
734
|
});
|
|
749
735
|
const addresses = value.addresses.flatMap((input) => {
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
736
|
+
let normalized = {};
|
|
737
|
+
const streetAddress = input.streetAddress?.trim();
|
|
738
|
+
const locality = input.locality?.trim();
|
|
739
|
+
const region = input.region?.trim();
|
|
740
|
+
const postalCode = input.postalCode?.trim();
|
|
741
|
+
const country = input.country?.trim();
|
|
742
|
+
if (streetAddress)
|
|
743
|
+
normalized = { ...normalized, streetAddress };
|
|
744
|
+
if (locality)
|
|
745
|
+
normalized = { ...normalized, locality };
|
|
746
|
+
if (region)
|
|
747
|
+
normalized = { ...normalized, region };
|
|
748
|
+
if (postalCode)
|
|
749
|
+
normalized = { ...normalized, postalCode };
|
|
750
|
+
if (country)
|
|
751
|
+
normalized = { ...normalized, country };
|
|
761
752
|
return Object.keys(normalized).length
|
|
762
753
|
? [
|
|
763
754
|
{
|
|
@@ -814,31 +805,56 @@ const organizationMetadataFromForm = async (value, m, uploadImage, existingMetad
|
|
|
814
805
|
socials,
|
|
815
806
|
addresses,
|
|
816
807
|
};
|
|
817
|
-
};
|
|
818
|
-
export function OrganizationSwitcher({
|
|
808
|
+
});
|
|
809
|
+
export function OrganizationSwitcher({ baseUrl: providedBaseUrl, side = "bottom", className, defaultDialog = null, features, hideTrigger = false, menuActions, renderUnauthenticated, allowedOrganizationIds, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, apiKeyPermissions, }) {
|
|
819
810
|
const auth = useKrakstackAuth();
|
|
820
|
-
const
|
|
821
|
-
if (!authClient) {
|
|
822
|
-
throw new Error("KrakstackAuthProvider is required to use authClient.");
|
|
823
|
-
}
|
|
811
|
+
const baseUrl = providedBaseUrl ?? auth?.baseUrl;
|
|
824
812
|
const labels = organizationSwitcherMessages(messages);
|
|
825
813
|
const m = organizationMessageFns(labels);
|
|
826
|
-
const
|
|
827
|
-
const
|
|
828
|
-
const
|
|
814
|
+
const sessionAtom = authSessionAtom(baseUrl);
|
|
815
|
+
const organizationsAtom = authOrganizationsAtom(baseUrl);
|
|
816
|
+
const sessionResult = useAtomValue(sessionAtom);
|
|
817
|
+
const organizationsResult = useAtomValue(organizationsAtom);
|
|
818
|
+
const session = AsyncResult.match(sessionResult, {
|
|
819
|
+
onInitial: () => null,
|
|
820
|
+
onFailure: () => null,
|
|
821
|
+
onSuccess: ({ value }) => value,
|
|
822
|
+
});
|
|
823
|
+
const activeOrganizationId = session?.session.activeOrganizationId ?? null;
|
|
824
|
+
const activeOrganizationAtom = activeAuthOrganizationAtom(baseUrl)(activeOrganizationId);
|
|
825
|
+
const activeOrganizationResult = useAtomValue(activeOrganizationAtom);
|
|
826
|
+
const activeOrganization = AsyncResult.match(activeOrganizationResult, {
|
|
827
|
+
onInitial: () => null,
|
|
828
|
+
onFailure: () => null,
|
|
829
|
+
onSuccess: ({ value }) => value,
|
|
830
|
+
});
|
|
831
|
+
const organizations = AsyncResult.match(organizationsResult, {
|
|
832
|
+
onInitial: () => Array(),
|
|
833
|
+
onFailure: () => Array(),
|
|
834
|
+
onSuccess: ({ value }) => Array.from(value),
|
|
835
|
+
});
|
|
836
|
+
const organizationsError = AsyncResult.match(organizationsResult, {
|
|
837
|
+
onInitial: () => null,
|
|
838
|
+
onFailure: () => m.organization_switcher_empty(),
|
|
839
|
+
onSuccess: () => null,
|
|
840
|
+
});
|
|
841
|
+
const refreshSession = useAtomRefresh(sessionAtom);
|
|
842
|
+
const refreshOrganizations = useAtomRefresh(organizationsAtom);
|
|
843
|
+
const refreshActiveOrganization = useAtomRefresh(activeOrganizationAtom);
|
|
844
|
+
const setActiveOrganization = (organizationId) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationSetActive({
|
|
845
|
+
payload: { organizationId },
|
|
846
|
+
})));
|
|
829
847
|
const lastAuthRefreshVersion = useRef(auth?.authRefreshVersion ?? 0);
|
|
830
848
|
const [uncontrolledDialog, setUncontrolledDialog] = useState(defaultDialog);
|
|
831
849
|
const [editingOrganizationLocale, setEditingOrganizationLocale] = useState(currentOrganizationLocale);
|
|
832
850
|
const dialog = controlledDialog !== undefined ? controlledDialog : uncontrolledDialog;
|
|
833
|
-
const invitationsAtom =
|
|
834
|
-
? userInvitationsAtom(authClient)
|
|
835
|
-
: emptyUserInvitationsAtom;
|
|
851
|
+
const invitationsAtom = userInvitationsAtom(baseUrl);
|
|
836
852
|
const invitationsResult = useAtomValue(invitationsAtom);
|
|
837
853
|
const refreshUserInvitations = useAtomRefresh(invitationsAtom);
|
|
838
854
|
const userInvitations = AsyncResult.match(invitationsResult, {
|
|
839
855
|
onInitial: () => [],
|
|
840
856
|
onFailure: () => [],
|
|
841
|
-
onSuccess: ({ value }) => Array.from(value),
|
|
857
|
+
onSuccess: ({ value }) => Array.from(value).filter((invitation) => invitation.status === "pending"),
|
|
842
858
|
});
|
|
843
859
|
const userInvitationsError = AsyncResult.match(invitationsResult, {
|
|
844
860
|
onInitial: () => null,
|
|
@@ -846,14 +862,14 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
846
862
|
onSuccess: () => null,
|
|
847
863
|
});
|
|
848
864
|
const loadingUserInvitations = invitationsResult._tag === "Initial";
|
|
849
|
-
const activeMemberRoles = parseRoleList(activeOrganization
|
|
865
|
+
const activeMemberRoles = parseRoleList(activeOrganization?.members.find((member) => member.userId === session?.user.id)?.role);
|
|
850
866
|
const canManageApiKeys = activeMemberRoles.some((role) => role === "owner" || role === "admin");
|
|
851
867
|
const canUpdateOrganization = canManageApiKeys;
|
|
852
868
|
const canSwitchOrganizations = features?.organizationSwitching ?? true;
|
|
853
869
|
const canCreateOrganization = features?.organizationCreation ?? true;
|
|
854
870
|
const canViewOrganizationInvitations = features?.userInvitations ?? true;
|
|
855
871
|
const setDialog = (next) => {
|
|
856
|
-
const nextDialog =
|
|
872
|
+
const nextDialog = Predicate.isFunction(next) ? next(dialog) : next;
|
|
857
873
|
if (nextDialog === dialog)
|
|
858
874
|
return;
|
|
859
875
|
if (controlledDialog === undefined)
|
|
@@ -862,9 +878,9 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
862
878
|
};
|
|
863
879
|
const openCreate = () => setDialog("create");
|
|
864
880
|
const refresh = async () => {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
881
|
+
refreshOrganizations();
|
|
882
|
+
refreshActiveOrganization();
|
|
883
|
+
refreshSession();
|
|
868
884
|
};
|
|
869
885
|
const refreshOnSessionChanged = useEffectEvent(() => {
|
|
870
886
|
void refresh();
|
|
@@ -876,30 +892,32 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
876
892
|
lastAuthRefreshVersion.current = version;
|
|
877
893
|
refreshOnSessionChanged();
|
|
878
894
|
}, [auth?.authRefreshVersion]);
|
|
879
|
-
if (!session
|
|
895
|
+
if (!session) {
|
|
880
896
|
return _jsx(_Fragment, { children: renderUnauthenticated?.() });
|
|
881
897
|
}
|
|
882
|
-
const active = activeOrganization
|
|
898
|
+
const active = activeOrganization;
|
|
883
899
|
const activeName = active?.name;
|
|
884
|
-
const visibleOrganizations = organizations.
|
|
885
|
-
allowedOrganizationIds.includes(organization.id))
|
|
900
|
+
const visibleOrganizations = organizations.filter((organization) => !allowedOrganizationIds ||
|
|
901
|
+
allowedOrganizationIds.includes(organization.id));
|
|
886
902
|
const selectableOrganizations = canSwitchOrganizations
|
|
887
903
|
? visibleOrganizations.filter((organization) => organization.id !== active?.id)
|
|
888
904
|
: [];
|
|
889
905
|
const scrollOrganizationList = selectableOrganizations.length > 5;
|
|
890
|
-
const hasOrganizationListItems =
|
|
891
|
-
Boolean(
|
|
906
|
+
const hasOrganizationListItems = organizationsResult._tag === "Initial" ||
|
|
907
|
+
Boolean(organizationsError) ||
|
|
892
908
|
canSwitchOrganizations;
|
|
893
909
|
const refreshAfterInvitationAction = async (previousActiveId) => {
|
|
894
910
|
refreshUserInvitations();
|
|
895
911
|
await refresh();
|
|
896
912
|
if (!canSwitchOrganizations && previousActiveId) {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
if (!result.error) {
|
|
913
|
+
try {
|
|
914
|
+
await Effect.runPromise(setActiveOrganization(previousActiveId));
|
|
915
|
+
notifyAuthChange();
|
|
901
916
|
await refresh();
|
|
902
|
-
onChange?.(organizations.
|
|
917
|
+
onChange?.(organizations.find((organization) => organization.id === previousActiveId) ?? null);
|
|
918
|
+
}
|
|
919
|
+
catch {
|
|
920
|
+
// The invitation action succeeded; keep the newly active organization.
|
|
903
921
|
}
|
|
904
922
|
}
|
|
905
923
|
};
|
|
@@ -911,61 +929,71 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
911
929
|
? { imageSrc: activeDisplay.image }
|
|
912
930
|
: {}) }), _jsx(ChevronsUpDown, { className: "text-muted-foreground size-4 shrink-0 group-data-[collapsible=icon]:hidden" })] }) }), _jsx(DropdownMenuContent, { className: "max-w-[calc(100vw-1rem)] 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: activeSubtitle, icon: Building2, variant: "sidebar", className: "px-1 py-1.5 text-left text-sm", ...(activeDisplay.image
|
|
913
931
|
? { imageSrc: activeDisplay.image }
|
|
914
|
-
: {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null,
|
|
932
|
+
: {}) }) }), menuActions ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), menuActions] })) : null, hasOrganizationListItems ? _jsx(DropdownMenuSeparator, {}) : null, organizationsResult._tag === "Initial" ? (_jsx(DropdownMenuItem, { disabled: true, children: m.organization_loading() })) : null, organizationsError ? (_jsx(DropdownMenuItem, { disabled: true, children: organizationsError })) : null, canSwitchOrganizations && selectableOrganizations.length ? (_jsx("div", { className: cn(scrollOrganizationList &&
|
|
915
933
|
"max-h-64 overflow-y-auto overscroll-contain"), children: selectableOrganizations.map((organization) => {
|
|
916
934
|
const display = organizationDisplay(organization, m, baseUrl);
|
|
917
935
|
return (_jsx(DropdownMenuItem, { onClick: async () => {
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
936
|
+
try {
|
|
937
|
+
const result = await Effect.runPromise(setActiveOrganization(organization.id));
|
|
938
|
+
if (!result)
|
|
939
|
+
return;
|
|
940
|
+
notifyAuthChange();
|
|
922
941
|
await refresh();
|
|
923
942
|
onChange?.(organization);
|
|
924
943
|
}
|
|
944
|
+
catch {
|
|
945
|
+
// Switching previously failed silently in this menu.
|
|
946
|
+
}
|
|
925
947
|
}, children: _jsx(AppBrand, { to: null, label: display.name, subtitle: organizationSwitcherSubtitle(organization, display.subtitle, m), icon: Building2, className: "w-full text-left [&>div:first-child]:size-7", ...(display.image
|
|
926
948
|
? { imageSrc: display.image }
|
|
927
949
|
: {}) }) }, organization.id));
|
|
928
|
-
}) })) : canSwitchOrganizations &&
|
|
950
|
+
}) })) : canSwitchOrganizations &&
|
|
951
|
+
organizationsResult._tag !== "Initial" ? (_jsx(DropdownMenuItem, { disabled: true, children: active
|
|
929
952
|
? m.organization_switcher_no_other_organizations()
|
|
930
953
|
: m.organization_switcher_empty() })) : null, canCreateOrganization || canViewOrganizationInvitations ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), canCreateOrganization ? (_jsxs(DropdownMenuItem, { onClick: openCreate, children: [_jsx(Plus, {}), m.organization_create_title()] })) : null, canViewOrganizationInvitations ? (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
931
954
|
setDialog("invitations");
|
|
932
|
-
}, 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", className: "bg-secondary! text-secondary-foreground!", children: userInvitations.length })) : null] })] })) : null] })) : null, activeOrganization
|
|
933
|
-
const organizationId = activeOrganization.
|
|
955
|
+
}, 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", className: "bg-secondary! text-secondary-foreground!", children: userInvitations.length })) : null] })] })) : null] })) : null, activeOrganization ? (_jsxs(_Fragment, { children: [_jsx(DropdownMenuSeparator, {}), (() => {
|
|
956
|
+
const organizationId = activeOrganization.id;
|
|
934
957
|
return (_jsxs(DropdownMenuItem, { onClick: () => {
|
|
935
958
|
void navigator.clipboard.writeText(organizationId);
|
|
936
959
|
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
937
960
|
})(), canUpdateOrganization ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("manage"), children: [_jsx(PencilIcon, {}), m.organization_switcher_manage()] })) : null, _jsxs(DropdownMenuItem, { onClick: () => setDialog("members"), children: [_jsx(Users, {}), m.organization_members_title()] }), canManageApiKeys ? (_jsxs(DropdownMenuItem, { onClick: () => setDialog("apiKeys"), children: [_jsx(KeyRound, {}), m.user_button_api_keys()] })) : null] })) : null] }) })] })), _jsx(Dialog, { open: dialog === "create" && canCreateOrganization, onOpenChange: (open) => {
|
|
938
961
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
939
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, {
|
|
962
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_create_title() }), _jsx(DialogDescription, { children: m.organization_create_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), _jsx(CreateOrganizationSection, { baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organizations: visibleOrganizations, onCreated: async (organization) => {
|
|
940
963
|
setDialog(null);
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
964
|
+
let activated = false;
|
|
965
|
+
try {
|
|
966
|
+
await Effect.runPromise(setActiveOrganization(organization.id));
|
|
967
|
+
activated = true;
|
|
968
|
+
notifyAuthChange();
|
|
969
|
+
}
|
|
970
|
+
catch {
|
|
971
|
+
// Creation succeeded even if activating the organization did not.
|
|
972
|
+
}
|
|
944
973
|
await refresh();
|
|
945
|
-
if (
|
|
974
|
+
if (activated) {
|
|
946
975
|
onCreate?.(organization);
|
|
947
976
|
onChange?.(organization);
|
|
948
977
|
}
|
|
949
978
|
} })] }) }), _jsx(Dialog, { open: dialog === "manage" && canUpdateOrganization, onOpenChange: (open) => {
|
|
950
979
|
setDialog((current) => open ? "manage" : current === "manage" ? null : current);
|
|
951
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), activeOrganization
|
|
980
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: m.organization_switcher_manage() }), _jsx(DialogDescription, { children: m.organization_edit_description() }), _jsx("div", { className: "pt-2", children: _jsx(EditingLocaleSwitcher, { value: editingOrganizationLocale, onValueChange: setEditingOrganizationLocale }) })] }), _jsx(Separator, {}), activeOrganization && canUpdateOrganization ? (_jsx(EditOrganizationSection, { baseUrl: baseUrl, editingLocale: editingOrganizationLocale, organization: activeOrganization, onUpdated: refresh })) : null] }) }), _jsx(Dialog, { open: dialog === "members", onOpenChange: (open) => {
|
|
952
981
|
setDialog((current) => open ? "members" : current === "members" ? null : current);
|
|
953
|
-
}, children: _jsx(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: activeOrganization
|
|
982
|
+
}, children: _jsx(DialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-4xl", children: activeOrganization ? (_jsx(OrganizationMembersManager, { baseUrl: baseUrl, canManageMembers: canManageApiKeys, organization: activeOrganization, currentUserId: session.user.id, active: dialog === "members", onLeft: async () => {
|
|
954
983
|
setDialog(null);
|
|
955
|
-
auth?.refreshAuth();
|
|
956
984
|
await refresh();
|
|
957
985
|
onChange?.(null);
|
|
958
986
|
} })) : null }) }), _jsx(Dialog, { open: dialog === "apiKeys" && canManageApiKeys, onOpenChange: (open) => {
|
|
959
987
|
setDialog((current) => open ? "apiKeys" : current === "apiKeys" ? null : current);
|
|
960
|
-
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization
|
|
988
|
+
}, children: _jsx(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden overflow-y-auto sm:max-w-3xl", children: activeOrganization ? (_jsx(OrganizationApiKeyManager, { baseUrl: baseUrl, organization: activeOrganization, active: dialog === "apiKeys" && canManageApiKeys, permissionLabels: auth?.accessLabels ?? undefined, permissions: apiKeyPermissions ??
|
|
961
989
|
auth?.access?.apiKeyPermissions.organization ??
|
|
962
990
|
{} })) : null }) }), _jsx(Dialog, { open: dialog === "invitations" && canViewOrganizationInvitations, onOpenChange: (open) => {
|
|
963
991
|
setDialog((current) => open ? "invitations" : current === "invitations" ? null : current);
|
|
964
|
-
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden 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, {
|
|
965
|
-
? { activeOrganizationId: activeOrganization.
|
|
992
|
+
}, children: _jsxs(DialogContent, { className: "max-h-[85vh] min-w-0 overflow-x-hidden 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, { baseUrl: baseUrl, invitations: userInvitations, loading: loadingUserInvitations, error: userInvitationsError, ...(activeOrganization
|
|
993
|
+
? { activeOrganizationId: activeOrganization.id }
|
|
966
994
|
: {}), onActionComplete: refreshAfterInvitationAction })] }) })] }));
|
|
967
995
|
}
|
|
968
|
-
function UserInvitationsManager({
|
|
996
|
+
function UserInvitationsManager({ baseUrl, invitations, loading, error, activeOrganizationId, onActionComplete, }) {
|
|
969
997
|
const m = useOrganizationMessages();
|
|
970
998
|
const [actingInvitationId, setActingInvitationId] = useState(null);
|
|
971
999
|
const [actionError, setActionError] = useState(null);
|
|
@@ -975,34 +1003,41 @@ function UserInvitationsManager({ authClient, baseUrl, invitations, loading, err
|
|
|
975
1003
|
return;
|
|
976
1004
|
setActingInvitationId(invitation.id);
|
|
977
1005
|
setActionError(null);
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
1006
|
+
try {
|
|
1007
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationAcceptInvitation({
|
|
1008
|
+
payload: { invitationId: invitation.id },
|
|
1009
|
+
}))));
|
|
1010
|
+
notifyAuthChange();
|
|
1011
|
+
await onActionComplete(activeOrganizationId);
|
|
1012
|
+
}
|
|
1013
|
+
catch (cause) {
|
|
1014
|
+
setActionError(organizationFailureMessage(cause, m.organization_invitation_accept_error()));
|
|
1015
|
+
}
|
|
1016
|
+
finally {
|
|
1017
|
+
setActingInvitationId(null);
|
|
985
1018
|
}
|
|
986
|
-
await onActionComplete(activeOrganizationId);
|
|
987
1019
|
};
|
|
988
1020
|
const rejectInvitation = async (invitation) => {
|
|
989
1021
|
setActingInvitationId(invitation.id);
|
|
990
1022
|
setActionError(null);
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1023
|
+
try {
|
|
1024
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationRejectInvitation({
|
|
1025
|
+
payload: { invitationId: invitation.id },
|
|
1026
|
+
}))));
|
|
1027
|
+
await onActionComplete(activeOrganizationId);
|
|
1028
|
+
}
|
|
1029
|
+
catch (cause) {
|
|
1030
|
+
setActionError(organizationFailureMessage(cause, m.organization_invitation_reject_error()));
|
|
1031
|
+
}
|
|
1032
|
+
finally {
|
|
1033
|
+
setActingInvitationId(null);
|
|
998
1034
|
}
|
|
999
|
-
await onActionComplete(activeOrganizationId);
|
|
1000
1035
|
};
|
|
1001
|
-
return (_jsxs("section", { className: "flex min-w-0 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("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, {
|
|
1036
|
+
return (_jsxs("section", { className: "flex min-w-0 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("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columnDefs: userInvitationColumns({
|
|
1002
1037
|
baseUrl,
|
|
1003
1038
|
m,
|
|
1004
1039
|
now: invitationNow,
|
|
1005
|
-
}),
|
|
1040
|
+
}), rowData: invitations, features: {
|
|
1006
1041
|
export: { baseName: "organization-invitations" },
|
|
1007
1042
|
gallery: false,
|
|
1008
1043
|
rowActions: {
|
|
@@ -1014,7 +1049,7 @@ function UserInvitationsManager({ authClient, baseUrl, invitations, loading, err
|
|
|
1014
1049
|
onReject: rejectInvitation,
|
|
1015
1050
|
}),
|
|
1016
1051
|
},
|
|
1017
|
-
},
|
|
1052
|
+
}, status: {
|
|
1018
1053
|
empty: loading
|
|
1019
1054
|
? m.user_loading()
|
|
1020
1055
|
: m.organization_user_invitations_empty(),
|
|
@@ -1023,33 +1058,29 @@ function UserInvitationsManager({ authClient, baseUrl, invitations, loading, err
|
|
|
1023
1058
|
}
|
|
1024
1059
|
const userInvitationColumns = ({ baseUrl, m, now, }) => [
|
|
1025
1060
|
{
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1061
|
+
field: "organizationName",
|
|
1062
|
+
headerName: m.organization_invitation_organization(),
|
|
1063
|
+
cellRenderer: ({ data }) => (_jsx(InvitationOrganizationBrand, { baseUrl: baseUrl, invitation: data })),
|
|
1029
1064
|
},
|
|
1030
1065
|
{
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1066
|
+
field: "role",
|
|
1067
|
+
headerName: m.organization_member_role(),
|
|
1068
|
+
cellRenderer: ({ data }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(data.role, m) })),
|
|
1034
1069
|
},
|
|
1035
1070
|
{
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1071
|
+
field: "status",
|
|
1072
|
+
headerName: m.organization_invitation_status(),
|
|
1073
|
+
cellRenderer: ({ data }) => (_jsx(Badge, { variant: isInvitationExpired(data, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(data, now), m) })),
|
|
1039
1074
|
},
|
|
1040
1075
|
{
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1076
|
+
field: "expiresAt",
|
|
1077
|
+
headerName: m.organization_invitation_expires(),
|
|
1078
|
+
cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(data.expiresAt) })),
|
|
1044
1079
|
},
|
|
1045
1080
|
];
|
|
1046
1081
|
function InvitationOrganizationBrand({ baseUrl, invitation, }) {
|
|
1047
1082
|
const locale = useKrakstackAuth()?.locale ?? currentOrganizationLocale();
|
|
1048
|
-
const profileResult = useAtomValue(invitationOrganizationProfileAtom(
|
|
1049
|
-
baseUrl,
|
|
1050
|
-
locale,
|
|
1051
|
-
organizationId: invitation.organizationId,
|
|
1052
|
-
}));
|
|
1083
|
+
const profileResult = useAtomValue(invitationOrganizationProfileAtom(baseUrl)(invitation.organizationId)(locale));
|
|
1053
1084
|
const profile = AsyncResult.match(profileResult, {
|
|
1054
1085
|
onInitial: () => null,
|
|
1055
1086
|
onFailure: () => null,
|
|
@@ -1076,34 +1107,40 @@ const userInvitationRowActions = ({ m, actingInvitationId, now, onAccept, onReje
|
|
|
1076
1107
|
onClick: onReject,
|
|
1077
1108
|
},
|
|
1078
1109
|
];
|
|
1079
|
-
function EditOrganizationSection({
|
|
1110
|
+
function EditOrganizationSection({ baseUrl, editingLocale, organization, onUpdated, }) {
|
|
1080
1111
|
const m = useOrganizationMessages();
|
|
1081
|
-
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
1082
1112
|
const [defaultLocale] = useState(currentOrganizationLocale);
|
|
1083
1113
|
const defaultValues = organizationFormDefaults(organization, baseUrl);
|
|
1084
1114
|
const [form] = useState(() => FormReact.make(organizationFormBuilder, {
|
|
1115
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
1085
1116
|
fields: organizationFormFields,
|
|
1086
|
-
onSubmit: (_, { decoded: value }) => Effect.
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1117
|
+
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1118
|
+
const name = organizationNameFromForm(value, defaultLocale);
|
|
1119
|
+
if (!name)
|
|
1120
|
+
return yield* Effect.fail(new Error(m.organization_name_required()));
|
|
1121
|
+
const slug = value.slug.trim().toLowerCase();
|
|
1122
|
+
const client = yield* authHttpClient(baseUrl);
|
|
1123
|
+
const metadata = yield* organizationMetadataFromForm(value, m, (input) => client.authExtra.uploadUserImage(input), organization.metadata);
|
|
1124
|
+
const normalizedMetadata = yield* normalizeOrganizationMetadata(metadata);
|
|
1125
|
+
const updated = yield* client.auth.organizationUpdate({
|
|
1126
|
+
payload: {
|
|
1094
1127
|
organizationId: organization.id,
|
|
1095
|
-
data: {
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
:
|
|
1106
|
-
|
|
1128
|
+
data: {
|
|
1129
|
+
name,
|
|
1130
|
+
slug,
|
|
1131
|
+
metadata: normalizedMetadata,
|
|
1132
|
+
},
|
|
1133
|
+
},
|
|
1134
|
+
});
|
|
1135
|
+
yield* Effect.sync(notifyAuthChange);
|
|
1136
|
+
yield* Effect.tryPromise({
|
|
1137
|
+
try: onUpdated,
|
|
1138
|
+
catch: (cause) => cause,
|
|
1139
|
+
});
|
|
1140
|
+
return updated;
|
|
1141
|
+
}).pipe(Effect.mapError((cause) => cause instanceof Error
|
|
1142
|
+
? cause
|
|
1143
|
+
: new Error(m.organization_update_error()))),
|
|
1107
1144
|
}));
|
|
1108
1145
|
const submit = useAtomSet(form.submit);
|
|
1109
1146
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1133,40 +1170,43 @@ function EditOrganizationSection({ authClient, baseUrl, editingLocale, organizat
|
|
|
1133
1170
|
suggestedHeight: 512,
|
|
1134
1171
|
} })] })] }), _jsx(Separator, { className: "my-2" }), _jsxs(OrganizationFormSection, { title: m.organization_contact(), children: [_jsx(OrganizationContactGroup, { title: m.organization_contact_email_type(), children: _jsx(form.emails, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_phone_type(), children: _jsx(form.phones, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_website_type(), children: _jsx(form.websites, { locale: editingLocale }) }), _jsx(OrganizationContactGroup, { title: m.organization_contact_social_type(), children: _jsx(form.socials, { locale: editingLocale }) })] }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationFormSection, { title: m.organization_address(), children: _jsx(form.addresses, { locale: editingLocale }) }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
1135
1172
|
}
|
|
1136
|
-
function CreateOrganizationSection({
|
|
1173
|
+
function CreateOrganizationSection({ baseUrl, editingLocale, organizations, onCreated, }) {
|
|
1137
1174
|
const m = useOrganizationMessages();
|
|
1138
|
-
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
1139
1175
|
const [defaultLocale] = useState(currentOrganizationLocale);
|
|
1140
1176
|
const defaultValues = organizationFormDefaults(undefined, baseUrl);
|
|
1141
1177
|
const [form] = useState(() => FormReact.make(organizationFormBuilder, {
|
|
1178
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
1142
1179
|
fields: organizationFormFields,
|
|
1143
|
-
onSubmit: (_, { decoded: value }) => Effect.
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1180
|
+
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1181
|
+
const name = organizationNameFromForm(value, defaultLocale);
|
|
1182
|
+
if (!name)
|
|
1183
|
+
return yield* Effect.fail(new Error(m.organization_name_required()));
|
|
1184
|
+
const slug = (value.slug.trim() || slugify(name)).toLowerCase();
|
|
1185
|
+
const client = yield* authHttpClient(baseUrl);
|
|
1186
|
+
const metadata = yield* organizationMetadataFromForm({ ...value, slug }, m, (input) => client.authExtra.uploadUserImage(input));
|
|
1187
|
+
const normalizedMetadata = yield* normalizeOrganizationMetadata(metadata);
|
|
1188
|
+
const createPayload = value.parentId === noParentOrganization
|
|
1189
|
+
? { name, slug, metadata: normalizedMetadata }
|
|
1190
|
+
: {
|
|
1151
1191
|
name,
|
|
1152
1192
|
slug,
|
|
1153
|
-
metadata,
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
})
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1193
|
+
metadata: normalizedMetadata,
|
|
1194
|
+
parentId: value.parentId,
|
|
1195
|
+
};
|
|
1196
|
+
const created = yield* client.auth
|
|
1197
|
+
.organizationCreate({ payload: createPayload })
|
|
1198
|
+
.pipe(Effect.mapError((cause) => new Error(isOrganizationSlugConflict(cause)
|
|
1199
|
+
? m.organization_create_slug_conflict()
|
|
1200
|
+
: organizationFailureMessage(cause, m.organization_create_error()))));
|
|
1201
|
+
yield* Effect.sync(notifyAuthChange);
|
|
1202
|
+
yield* Effect.tryPromise({
|
|
1203
|
+
try: () => onCreated(created),
|
|
1204
|
+
catch: (cause) => cause,
|
|
1205
|
+
});
|
|
1206
|
+
return created;
|
|
1207
|
+
}).pipe(Effect.mapError((cause) => cause instanceof Error
|
|
1208
|
+
? cause
|
|
1209
|
+
: new Error(m.organization_create_error()))),
|
|
1170
1210
|
}));
|
|
1171
1211
|
const submit = useAtomSet(form.submit);
|
|
1172
1212
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1219,24 +1259,40 @@ function OrganizationFormSection({ children, description, title, }) {
|
|
|
1219
1259
|
function OrganizationContactGroup({ children, title, }) {
|
|
1220
1260
|
return (_jsxs("div", { className: "flex flex-col gap-3", children: [_jsx("h4", { className: "text-sm font-medium", children: title }), children] }));
|
|
1221
1261
|
}
|
|
1222
|
-
function OrganizationMembersManager({
|
|
1262
|
+
function OrganizationMembersManager({ baseUrl, canManageMembers, organization, currentUserId, active, onLeft, }) {
|
|
1223
1263
|
const m = useOrganizationMessages();
|
|
1224
1264
|
const hasOpened = useOpenedOnce(active);
|
|
1225
1265
|
const membersAtom = hasOpened
|
|
1226
|
-
? organizationMembersAtom(
|
|
1266
|
+
? organizationMembersAtom(baseUrl)(organization.id)
|
|
1227
1267
|
: emptyOrganizationMembersAtom;
|
|
1268
|
+
const invitationsAtom = hasOpened
|
|
1269
|
+
? organizationInvitationsAtom(baseUrl)(organization.id)
|
|
1270
|
+
: emptyOrganizationInvitationsAtom;
|
|
1228
1271
|
const membersResult = useAtomValue(membersAtom);
|
|
1272
|
+
const invitationsResult = useAtomValue(invitationsAtom);
|
|
1229
1273
|
const refreshMembers = useAtomRefresh(membersAtom);
|
|
1274
|
+
const refreshInvitations = useAtomRefresh(invitationsAtom);
|
|
1230
1275
|
const [inviting, setInviting] = useState(false);
|
|
1231
1276
|
const [error, setError] = useState(null);
|
|
1232
1277
|
const [cancellingInvitationId, setCancellingInvitationId] = useState(null);
|
|
1233
1278
|
const [leavingOrganization, setLeavingOrganization] = useState(false);
|
|
1234
1279
|
const [lastMembersData, setLastMembersData] = useState(null);
|
|
1235
|
-
const
|
|
1280
|
+
const currentMembers = AsyncResult.match(membersResult, {
|
|
1281
|
+
onInitial: () => null,
|
|
1282
|
+
onFailure: () => null,
|
|
1283
|
+
onSuccess: ({ value }) => value.members,
|
|
1284
|
+
});
|
|
1285
|
+
const currentInvitations = AsyncResult.match(invitationsResult, {
|
|
1236
1286
|
onInitial: () => null,
|
|
1237
1287
|
onFailure: () => null,
|
|
1238
1288
|
onSuccess: ({ value }) => value,
|
|
1239
1289
|
});
|
|
1290
|
+
const currentMembersData = currentMembers && currentInvitations
|
|
1291
|
+
? {
|
|
1292
|
+
members: Array.from(currentMembers),
|
|
1293
|
+
invitations: Array.from(currentInvitations).filter((invitation) => invitation.status === "pending"),
|
|
1294
|
+
}
|
|
1295
|
+
: null;
|
|
1240
1296
|
const membersData = currentMembersData ??
|
|
1241
1297
|
lastMembersData ?? {
|
|
1242
1298
|
members: [],
|
|
@@ -1255,36 +1311,39 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
1255
1311
|
onFailure: () => m.organization_members_load_error(),
|
|
1256
1312
|
onSuccess: () => null,
|
|
1257
1313
|
});
|
|
1258
|
-
const
|
|
1314
|
+
const invitationsError = AsyncResult.match(invitationsResult, {
|
|
1315
|
+
onInitial: () => null,
|
|
1316
|
+
onFailure: () => m.organization_invitations_load_error(),
|
|
1317
|
+
onSuccess: () => null,
|
|
1318
|
+
});
|
|
1319
|
+
const loadError = membersError ?? invitationsError;
|
|
1320
|
+
const loading = !lastMembersData &&
|
|
1321
|
+
(membersResult._tag === "Initial" || invitationsResult._tag === "Initial");
|
|
1259
1322
|
const canInviteMembers = canManageMembers;
|
|
1260
1323
|
const canRemoveMembers = canManageMembers;
|
|
1261
1324
|
useEffect(() => {
|
|
1262
|
-
if (!
|
|
1325
|
+
if (!currentMembers || !currentInvitations)
|
|
1263
1326
|
return;
|
|
1264
|
-
setLastMembersData(
|
|
1265
|
-
|
|
1327
|
+
setLastMembersData({
|
|
1328
|
+
members: Array.from(currentMembers),
|
|
1329
|
+
invitations: Array.from(currentInvitations).filter((invitation) => invitation.status === "pending"),
|
|
1330
|
+
});
|
|
1331
|
+
}, [currentInvitations, currentMembers]);
|
|
1266
1332
|
const [inviteForm] = useState(() => FormReact.make(inviteMemberFormBuilder, {
|
|
1333
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
1267
1334
|
fields: {
|
|
1268
1335
|
email: TextField,
|
|
1269
1336
|
role: SelectField,
|
|
1270
1337
|
},
|
|
1271
|
-
onSubmit: (_, { decoded: value }) => Effect.
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
organizationId: organization.id,
|
|
1277
|
-
});
|
|
1278
|
-
if (result.error) {
|
|
1279
|
-
throw new Error(result.error.message ?? m.organization_invite_error());
|
|
1280
|
-
}
|
|
1281
|
-
refreshMembers();
|
|
1282
|
-
return result.data;
|
|
1338
|
+
onSubmit: (_, { decoded: value }) => authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationInviteMember({
|
|
1339
|
+
payload: {
|
|
1340
|
+
email: value.email.trim(),
|
|
1341
|
+
role: normalizeInvitationRole(value.role),
|
|
1342
|
+
organizationId: organization.id,
|
|
1283
1343
|
},
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
}),
|
|
1344
|
+
})), Effect.tap(() => Effect.sync(refreshInvitations)), Effect.mapError((cause) => cause instanceof Error
|
|
1345
|
+
? cause
|
|
1346
|
+
: new Error(m.organization_invite_error()))),
|
|
1288
1347
|
}));
|
|
1289
1348
|
const submitInvitation = useAtomSet(inviteForm.submit);
|
|
1290
1349
|
const resetInvitation = useAtomSet(inviteForm.reset);
|
|
@@ -1304,56 +1363,73 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
1304
1363
|
...current,
|
|
1305
1364
|
[member.id]: nextRole,
|
|
1306
1365
|
}));
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1366
|
+
try {
|
|
1367
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationUpdateMemberRole({
|
|
1368
|
+
payload: {
|
|
1369
|
+
memberId: member.id,
|
|
1370
|
+
role: Array.isArray(role)
|
|
1371
|
+
? role
|
|
1372
|
+
: normalizeOrganizationRole(role),
|
|
1373
|
+
organizationId: organization.id,
|
|
1374
|
+
},
|
|
1375
|
+
}))));
|
|
1376
|
+
refreshMembers();
|
|
1377
|
+
}
|
|
1378
|
+
catch (cause) {
|
|
1313
1379
|
setMemberRoleOverrides((current) => ({
|
|
1314
1380
|
...current,
|
|
1315
1381
|
[member.id]: member.role,
|
|
1316
1382
|
}));
|
|
1317
|
-
setError(
|
|
1383
|
+
setError(organizationFailureMessage(cause, m.organization_member_role_error()));
|
|
1318
1384
|
}
|
|
1319
1385
|
};
|
|
1320
1386
|
const removeMember = async (member) => {
|
|
1321
1387
|
setError(null);
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1388
|
+
try {
|
|
1389
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationRemoveMember({
|
|
1390
|
+
payload: {
|
|
1391
|
+
memberIdOrEmail: member.id,
|
|
1392
|
+
organizationId: organization.id,
|
|
1393
|
+
},
|
|
1394
|
+
}))));
|
|
1395
|
+
refreshMembers();
|
|
1396
|
+
}
|
|
1397
|
+
catch (cause) {
|
|
1398
|
+
setError(organizationFailureMessage(cause, m.organization_member_remove_error()));
|
|
1329
1399
|
}
|
|
1330
|
-
refreshMembers();
|
|
1331
1400
|
};
|
|
1332
1401
|
const leaveOrganization = async () => {
|
|
1333
1402
|
setLeavingOrganization(true);
|
|
1334
1403
|
setError(null);
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1404
|
+
try {
|
|
1405
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationLeave({
|
|
1406
|
+
payload: { organizationId: organization.id },
|
|
1407
|
+
}))));
|
|
1408
|
+
notifyAuthChange();
|
|
1409
|
+
await onLeft();
|
|
1410
|
+
}
|
|
1411
|
+
catch (cause) {
|
|
1412
|
+
setError(organizationFailureMessage(cause, m.organization_member_leave_error()));
|
|
1413
|
+
}
|
|
1414
|
+
finally {
|
|
1415
|
+
setLeavingOrganization(false);
|
|
1342
1416
|
}
|
|
1343
|
-
await onLeft();
|
|
1344
1417
|
};
|
|
1345
1418
|
const cancelInvitation = async (invitation) => {
|
|
1346
1419
|
setCancellingInvitationId(invitation.id);
|
|
1347
1420
|
setError(null);
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1421
|
+
try {
|
|
1422
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.organizationCancelInvitation({
|
|
1423
|
+
payload: { invitationId: invitation.id },
|
|
1424
|
+
}))));
|
|
1425
|
+
refreshInvitations();
|
|
1426
|
+
}
|
|
1427
|
+
catch (cause) {
|
|
1428
|
+
setError(organizationFailureMessage(cause, m.organization_invitation_cancel_error()));
|
|
1429
|
+
}
|
|
1430
|
+
finally {
|
|
1431
|
+
setCancellingInvitationId(null);
|
|
1355
1432
|
}
|
|
1356
|
-
refreshMembers();
|
|
1357
1433
|
};
|
|
1358
1434
|
return (_jsxs(_Fragment, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: inviting
|
|
1359
1435
|
? m.organization_invite_member_title()
|
|
@@ -1368,12 +1444,12 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
1368
1444
|
}, children: [_jsx(inviteForm.email, { label: m.organization_member_email(), placeholder: "teammate@example.com", type: "email", required: true }), _jsx(inviteForm.role, { label: m.organization_member_role(), options: organizationRoles.map((role) => ({
|
|
1369
1445
|
label: organizationRoleLabel(role, m),
|
|
1370
1446
|
value: role,
|
|
1371
|
-
})) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) })) : null, !inviting &&
|
|
1447
|
+
})) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) })) : null, !inviting && loadError ? (_jsx("p", { className: "text-destructive text-sm", children: loadError })) : null, !inviting && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columnDefs: memberColumns({
|
|
1372
1448
|
m,
|
|
1373
1449
|
baseUrl,
|
|
1374
1450
|
canChangeRoles: canManageMembers,
|
|
1375
1451
|
onRoleChange: updateRole,
|
|
1376
|
-
}),
|
|
1452
|
+
}), rowData: displayedMembers, features: {
|
|
1377
1453
|
export: { baseName: `${organization.slug}-members` },
|
|
1378
1454
|
gallery: false,
|
|
1379
1455
|
rowActions: {
|
|
@@ -1386,10 +1462,10 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
1386
1462
|
onRemove: removeMember,
|
|
1387
1463
|
}),
|
|
1388
1464
|
},
|
|
1389
|
-
},
|
|
1465
|
+
}, status: { empty: m.organization_members_empty(), loading } }) })] })) : null, !inviting ? (_jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_invitations_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_invitations_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columnDefs: invitationColumns({
|
|
1390
1466
|
m,
|
|
1391
1467
|
now: invitationNow,
|
|
1392
|
-
}),
|
|
1468
|
+
}), rowData: invitations, features: {
|
|
1393
1469
|
export: { baseName: `${organization.slug}-invitations` },
|
|
1394
1470
|
gallery: false,
|
|
1395
1471
|
rowActions: {
|
|
@@ -1399,22 +1475,22 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
1399
1475
|
onCancel: cancelInvitation,
|
|
1400
1476
|
}),
|
|
1401
1477
|
},
|
|
1402
|
-
},
|
|
1478
|
+
}, status: { empty: m.organization_invitations_empty(), loading } }) })] })) : null] })] }));
|
|
1403
1479
|
}
|
|
1404
1480
|
const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
1405
1481
|
{
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
const image = assetUrl(
|
|
1410
|
-
return (_jsx(AppBrand, { to: null, label:
|
|
1482
|
+
colId: "user",
|
|
1483
|
+
headerName: m.organization_member_user(),
|
|
1484
|
+
cellRenderer: ({ data }) => {
|
|
1485
|
+
const image = assetUrl(data.user.image, baseUrl);
|
|
1486
|
+
return (_jsx(AppBrand, { to: null, label: data.user.name, subtitle: data.user.email, icon: UserIcon, className: "min-w-0", ...(image ? { imageSrc: image } : {}) }));
|
|
1411
1487
|
},
|
|
1412
1488
|
},
|
|
1413
1489
|
{
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
const member =
|
|
1490
|
+
field: "role",
|
|
1491
|
+
headerName: m.organization_member_role(),
|
|
1492
|
+
cellRenderer: ({ data }) => {
|
|
1493
|
+
const member = data;
|
|
1418
1494
|
const roles = normalizeOrganizationRoles(member.role);
|
|
1419
1495
|
const roleOptions = roles.map((role) => ({
|
|
1420
1496
|
label: organizationRoleLabel(role, m),
|
|
@@ -1439,9 +1515,9 @@ const memberColumns = ({ m, baseUrl, canChangeRoles, onRoleChange, }) => [
|
|
|
1439
1515
|
},
|
|
1440
1516
|
},
|
|
1441
1517
|
{
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1518
|
+
field: "createdAt",
|
|
1519
|
+
headerName: m.organization_member_joined(),
|
|
1520
|
+
cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(data.createdAt) })),
|
|
1445
1521
|
},
|
|
1446
1522
|
];
|
|
1447
1523
|
const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganization, onLeave, onRemove, }) => [
|
|
@@ -1464,24 +1540,24 @@ const memberRowActions = ({ m, canRemoveMembers, currentUserId, leavingOrganizat
|
|
|
1464
1540
|
];
|
|
1465
1541
|
const invitationColumns = ({ m, now, }) => [
|
|
1466
1542
|
{
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1543
|
+
field: "email",
|
|
1544
|
+
headerName: m.organization_member_email(),
|
|
1545
|
+
cellRenderer: ({ data }) => (_jsx("p", { className: "truncate font-medium", children: data.email })),
|
|
1470
1546
|
},
|
|
1471
1547
|
{
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1548
|
+
field: "role",
|
|
1549
|
+
headerName: m.organization_member_role(),
|
|
1550
|
+
cellRenderer: ({ data }) => (_jsx(Badge, { variant: "secondary", children: organizationRoleLabel(data.role, m) })),
|
|
1475
1551
|
},
|
|
1476
1552
|
{
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1553
|
+
field: "status",
|
|
1554
|
+
headerName: m.organization_invitation_status(),
|
|
1555
|
+
cellRenderer: ({ data }) => (_jsx(Badge, { variant: isInvitationExpired(data, now) ? "destructive" : "default", children: invitationStatusLabel(invitationDisplayStatus(data, now), m) })),
|
|
1480
1556
|
},
|
|
1481
1557
|
{
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1558
|
+
field: "expiresAt",
|
|
1559
|
+
headerName: m.organization_invitation_expires(),
|
|
1560
|
+
cellRenderer: ({ data }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: formatOrganizationDate(data.expiresAt) })),
|
|
1485
1561
|
},
|
|
1486
1562
|
];
|
|
1487
1563
|
const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
|
|
@@ -1493,11 +1569,11 @@ const invitationRowActions = ({ m, cancellingInvitationId, onCancel, }) => [
|
|
|
1493
1569
|
onClick: onCancel,
|
|
1494
1570
|
},
|
|
1495
1571
|
];
|
|
1496
|
-
function OrganizationApiKeyManager({
|
|
1572
|
+
function OrganizationApiKeyManager({ baseUrl, organization, active, permissionLabels, permissions, }) {
|
|
1497
1573
|
const m = useOrganizationMessages();
|
|
1498
1574
|
const hasOpened = useOpenedOnce(active);
|
|
1499
1575
|
const keysAtom = hasOpened
|
|
1500
|
-
? organizationApiKeysAtom(
|
|
1576
|
+
? organizationApiKeysAtom(baseUrl)(organization.id)
|
|
1501
1577
|
: emptyOrganizationApiKeysAtom;
|
|
1502
1578
|
const keysResult = useAtomValue(keysAtom);
|
|
1503
1579
|
const refreshKeys = useAtomRefresh(keysAtom);
|
|
@@ -1514,7 +1590,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
|
|
|
1514
1590
|
const keys = AsyncResult.match(keysResult, {
|
|
1515
1591
|
onInitial: () => [],
|
|
1516
1592
|
onFailure: () => [],
|
|
1517
|
-
onSuccess: ({ value }) => Array.from(value),
|
|
1593
|
+
onSuccess: ({ value }) => Array.from(value.apiKeys),
|
|
1518
1594
|
});
|
|
1519
1595
|
const keysError = AsyncResult.match(keysResult, {
|
|
1520
1596
|
onInitial: () => null,
|
|
@@ -1523,26 +1599,29 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
|
|
|
1523
1599
|
});
|
|
1524
1600
|
const loading = keysResult._tag === "Initial";
|
|
1525
1601
|
const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
|
|
1602
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
1526
1603
|
fields: { name: TextField, referrers: TextAreaField },
|
|
1527
|
-
onSubmit: (_, { decoded: value }) => Effect.
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1604
|
+
onSubmit: (_, { decoded: value }) => Effect.gen(function* () {
|
|
1605
|
+
yield* Effect.sync(() => setCreatedKey(null));
|
|
1606
|
+
const client = yield* authHttpClient(baseUrl);
|
|
1607
|
+
const created = yield* client.authExtra.createApiKey({
|
|
1608
|
+
payload: {
|
|
1531
1609
|
configId: "organization",
|
|
1532
1610
|
organizationId: organization.id,
|
|
1533
1611
|
name: value.name.trim(),
|
|
1534
1612
|
permissions: organizationApiKeySelectedPermissions(permissionOptionsRef.current, selectedPermissionsRef.current),
|
|
1535
1613
|
referrers: parseApiKeyReferrers(value.referrers, m.user_api_key_referrers_error()),
|
|
1536
|
-
},
|
|
1614
|
+
},
|
|
1615
|
+
});
|
|
1616
|
+
yield* Effect.sync(() => {
|
|
1537
1617
|
setCreatedKey(created.key);
|
|
1538
1618
|
setSelectedPermissions({});
|
|
1539
1619
|
refreshKeys();
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
}),
|
|
1620
|
+
});
|
|
1621
|
+
return created;
|
|
1622
|
+
}).pipe(Effect.mapError((cause) => cause instanceof Error
|
|
1623
|
+
? cause
|
|
1624
|
+
: new Error(m.user_api_key_create_error()))),
|
|
1546
1625
|
}));
|
|
1547
1626
|
const submitApiKey = useAtomSet(createForm.submit);
|
|
1548
1627
|
const resetApiKey = useAtomSet(createForm.reset);
|
|
@@ -1555,15 +1634,16 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
|
|
|
1555
1634
|
resetApiKey();
|
|
1556
1635
|
}, [createResult, resetApiKey]);
|
|
1557
1636
|
const deleteKey = async (key) => {
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1637
|
+
setError(null);
|
|
1638
|
+
try {
|
|
1639
|
+
await Effect.runPromise(authHttpClient(baseUrl).pipe(Effect.flatMap((client) => client.auth.apiKeyDelete({
|
|
1640
|
+
payload: { configId: "organization", keyId: key.id },
|
|
1641
|
+
}))));
|
|
1642
|
+
refreshKeys();
|
|
1643
|
+
}
|
|
1644
|
+
catch (cause) {
|
|
1645
|
+
setError(organizationFailureMessage(cause, m.user_api_key_delete_error()));
|
|
1565
1646
|
}
|
|
1566
|
-
refreshKeys();
|
|
1567
1647
|
};
|
|
1568
1648
|
return (_jsxs(_Fragment, { children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { className: "text-2xl", children: editingKey
|
|
1569
1649
|
? m.user_api_key_edit_title()
|
|
@@ -1593,7 +1673,7 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
|
|
|
1593
1673
|
}, children: [_jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(createForm.referrers, { label: m.user_api_key_referrers(), description: m.user_api_key_referrers_description(), placeholder: m.user_api_key_referrers_placeholder(), rows: 3 }), _jsx(ApiKeyPermissions, { description: m.user_api_key_permissions_description(), idPrefix: "organization-create", permissions: permissions, labels: permissionLabels, selected: selectedPermissions, title: m.user_api_key_permissions(), onChange: togglePermission }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }) })) : null, creating && createdKey ? (_jsx("div", { className: "flex min-w-0 flex-col gap-3", children: _jsxs("div", { className: "bg-muted/50 flex min-w-0 items-center justify-between gap-3 rounded-md border px-3 py-2", children: [_jsx("code", { className: "block min-w-0 flex-1 overflow-x-auto text-sm whitespace-nowrap", children: createdKey }), _jsx(CopyButton, { className: "shrink-0", messages: {
|
|
1594
1674
|
copied: m.user_api_key_copied(),
|
|
1595
1675
|
copy: m.user_api_key_copy(),
|
|
1596
|
-
}, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0 overflow-x-hidden", children: _jsx(DataTable, {
|
|
1676
|
+
}, value: createdKey, variant: "ghost" })] }) })) : null, !creating && !editingKey && keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, !creating && !editingKey && error ? (_jsx("p", { className: "text-destructive text-sm", children: error })) : null, !creating && !editingKey ? (_jsx("div", { className: "max-w-full min-w-0 overflow-x-hidden", children: _jsx(DataTable, { columnDefs: apiKeyColumns({ m }), rowData: keys, features: {
|
|
1597
1677
|
export: { baseName: `${organization.slug}-api-keys` },
|
|
1598
1678
|
gallery: false,
|
|
1599
1679
|
rowActions: {
|
|
@@ -1603,10 +1683,10 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
|
|
|
1603
1683
|
onEdit: (key) => setEditingKey(key),
|
|
1604
1684
|
}),
|
|
1605
1685
|
},
|
|
1606
|
-
},
|
|
1686
|
+
}, status: {
|
|
1607
1687
|
empty: loading ? m.user_loading() : m.table_empty(),
|
|
1608
1688
|
loading,
|
|
1609
|
-
} }) })) : null, editingKey ? (_jsx(
|
|
1689
|
+
} }) })) : null, editingKey ? (_jsx(OrganizationApiKeyEditForm, { baseUrl: baseUrl, keyData: editingKey, permissions: permissions, permissionLabels: permissionLabels, messages: {
|
|
1610
1690
|
enabled: m.user_api_key_enabled(),
|
|
1611
1691
|
name: m.user_api_key_name(),
|
|
1612
1692
|
referrers: m.user_api_key_referrers(),
|
|
@@ -1621,41 +1701,110 @@ function OrganizationApiKeyManager({ authClient, organization, active, permissio
|
|
|
1621
1701
|
setEditingKey(null);
|
|
1622
1702
|
} }, editingKey.id)) : null] })] }));
|
|
1623
1703
|
}
|
|
1704
|
+
function OrganizationApiKeyEditForm({ baseUrl, keyData, messages, permissions, permissionLabels, onSaved, }) {
|
|
1705
|
+
const permissionOptions = Object.entries(permissions).flatMap(([project, actions]) => actions.map((action) => ({
|
|
1706
|
+
id: `${project}:${action}`,
|
|
1707
|
+
project,
|
|
1708
|
+
action,
|
|
1709
|
+
})));
|
|
1710
|
+
const currentPermissions = Schema.decodeUnknownOption(ExtraApiKeyPermissions)(keyData.permissions ?? {});
|
|
1711
|
+
const currentGrant = Option.isSome(currentPermissions)
|
|
1712
|
+
? currentPermissions.value
|
|
1713
|
+
: {};
|
|
1714
|
+
const initialSelectedPermissions = Object.fromEntries(permissionOptions.map((option) => [
|
|
1715
|
+
option.id,
|
|
1716
|
+
currentGrant[option.project]?.includes(option.action) ?? false,
|
|
1717
|
+
]));
|
|
1718
|
+
const permissionOptionsRef = useRef(permissionOptions);
|
|
1719
|
+
const permissionsRef = useRef(permissions);
|
|
1720
|
+
permissionOptionsRef.current = permissionOptions;
|
|
1721
|
+
permissionsRef.current = permissions;
|
|
1722
|
+
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
1723
|
+
runtime: authClientApi(baseUrl).runtime,
|
|
1724
|
+
fields: {
|
|
1725
|
+
name: TextField,
|
|
1726
|
+
enabled: CheckboxField,
|
|
1727
|
+
referrers: TextAreaField,
|
|
1728
|
+
permissions: ApiKeyPermissionsField,
|
|
1729
|
+
},
|
|
1730
|
+
mode: { validation: "onSubmit" },
|
|
1731
|
+
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
1732
|
+
const referrers = parseApiKeyReferrers(decoded.referrers, messages.referrersError);
|
|
1733
|
+
const selectedGrant = {};
|
|
1734
|
+
for (const project of Object.keys(permissionsRef.current)) {
|
|
1735
|
+
selectedGrant[project] = [];
|
|
1736
|
+
}
|
|
1737
|
+
for (const option of permissionOptionsRef.current) {
|
|
1738
|
+
if (!decoded.permissions[option.id])
|
|
1739
|
+
continue;
|
|
1740
|
+
selectedGrant[option.project] = [
|
|
1741
|
+
...(selectedGrant[option.project] ?? []),
|
|
1742
|
+
option.action,
|
|
1743
|
+
];
|
|
1744
|
+
}
|
|
1745
|
+
const client = yield* authHttpClient(baseUrl);
|
|
1746
|
+
const updated = yield* client.authExtra.updateApiKey({
|
|
1747
|
+
params: { keyId: keyData.id },
|
|
1748
|
+
payload: {
|
|
1749
|
+
configId: "organization",
|
|
1750
|
+
name: decoded.name.trim(),
|
|
1751
|
+
enabled: decoded.enabled,
|
|
1752
|
+
permissions: selectedGrant,
|
|
1753
|
+
referrers,
|
|
1754
|
+
},
|
|
1755
|
+
});
|
|
1756
|
+
yield* Effect.sync(onSaved);
|
|
1757
|
+
return updated;
|
|
1758
|
+
}).pipe(Effect.mapError((cause) => cause instanceof Error
|
|
1759
|
+
? cause
|
|
1760
|
+
: new Error(organizationFailureMessage(cause, messages.updateError)))),
|
|
1761
|
+
}));
|
|
1762
|
+
const submit = useAtomSet(form.submit);
|
|
1763
|
+
const submitResult = useAtomValue(form.submit);
|
|
1764
|
+
return (_jsx("section", { className: "w-full", children: _jsx(form.Initialize, { defaultValues: {
|
|
1765
|
+
name: keyData.name ?? "",
|
|
1766
|
+
enabled: keyData.enabled,
|
|
1767
|
+
referrers: apiKeyReferrers(keyData.metadata).join("\n"),
|
|
1768
|
+
permissions: initialSelectedPermissions,
|
|
1769
|
+
}, children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
1770
|
+
event.preventDefault();
|
|
1771
|
+
event.stopPropagation();
|
|
1772
|
+
submit();
|
|
1773
|
+
}, children: [_jsx(form.name, { label: messages.name, required: true }), _jsx(form.enabled, { label: messages.enabled }), _jsx(form.referrers, { label: messages.referrers, description: messages.referrersDescription, placeholder: messages.referrersPlaceholder, rows: 3 }), _jsx(form.permissions, { description: messages.permissionsDescription, idPrefix: `organization-edit-${keyData.id}`, labels: permissionLabels, permissions: permissions, title: messages.permissions }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
1774
|
+
}
|
|
1624
1775
|
const apiKeyColumns = ({ m, }) => [
|
|
1625
1776
|
{
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
? m.user_api_key_starts_with({ start:
|
|
1777
|
+
field: "name",
|
|
1778
|
+
headerName: m.user_api_key_name(),
|
|
1779
|
+
cellRenderer: ({ data }) => (_jsxs("div", { className: "min-w-0", children: [_jsx("p", { className: "truncate font-medium", children: data.name }), _jsx("p", { className: "text-muted-foreground text-sm", children: data.start
|
|
1780
|
+
? m.user_api_key_starts_with({ start: data.start })
|
|
1630
1781
|
: m.user_api_key_hidden() })] })),
|
|
1631
1782
|
},
|
|
1632
1783
|
{
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
? m.user_api_key_enabled()
|
|
1637
|
-
: m.user_api_key_disabled() })),
|
|
1784
|
+
field: "enabled",
|
|
1785
|
+
headerName: m.user_api_key_status(),
|
|
1786
|
+
cellRenderer: ({ data }) => (_jsx(Badge, { variant: data.enabled ? "default" : "secondary", children: data.enabled ? m.user_api_key_enabled() : m.user_api_key_disabled() })),
|
|
1638
1787
|
},
|
|
1639
1788
|
{
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
const values = organizationApiKeyFormattedPermissions(
|
|
1789
|
+
colId: "permissions",
|
|
1790
|
+
valueGetter: ({ data }) => data.permissions,
|
|
1791
|
+
headerName: m.user_api_key_permissions(),
|
|
1792
|
+
cellRenderer: ({ data }) => {
|
|
1793
|
+
const values = organizationApiKeyFormattedPermissions(data.permissions);
|
|
1645
1794
|
return values.length > 0 ? (_jsx("div", { className: "flex flex-wrap gap-1", children: values.map((value) => (_jsx(Badge, { variant: "outline", children: value }, value))) })) : (_jsx("span", { className: "text-muted-foreground text-sm", children: m.user_api_key_no_permissions() }));
|
|
1646
1795
|
},
|
|
1647
1796
|
},
|
|
1648
1797
|
{
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1798
|
+
colId: "referrers",
|
|
1799
|
+
valueGetter: ({ data }) => data.metadata,
|
|
1800
|
+
headerName: m.user_api_key_referrers_column(),
|
|
1801
|
+
cellRenderer: ({ data }) => (_jsx(ApiKeyReferrers, { metadata: data.metadata, unrestrictedLabel: m.user_api_key_referrers_any() })),
|
|
1653
1802
|
},
|
|
1654
1803
|
{
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1804
|
+
colId: "rateLimit",
|
|
1805
|
+
valueGetter: ({ data }) => apiKeyUsagePercent(data),
|
|
1806
|
+
headerName: m.user_api_key_rate_limit(),
|
|
1807
|
+
cellRenderer: ({ data }) => (_jsx(ApiKeyRateLimit, { keyData: data, messages: {
|
|
1659
1808
|
disabled: m.user_api_key_disabled(),
|
|
1660
1809
|
none: m.user_api_key_window_none(),
|
|
1661
1810
|
unlimited: m.user_api_key_unlimited(),
|