@krak-stack/auth 0.1.52 → 0.1.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/api.group.d.ts +60 -0
- package/dist/admin/schema.d.ts +64 -0
- package/dist/admin/schema.js +41 -0
- package/dist/api.d.ts +297 -216
- package/dist/components/admin-organization-form.js +110 -69
- package/dist/components/admin-organizations.js +99 -6
- package/dist/components/admin-users.js +38 -4
- package/dist/components/auth-client-api.d.ts +60 -0
- package/dist/components/auth-client.d.ts +4 -0
- package/dist/components/auth-client.js +4 -0
- package/dist/components/auth-forms.js +274 -292
- package/dist/components/organization-switcher.d.ts +9 -1
- package/dist/components/organization-switcher.js +236 -191
- package/dist/components/user-button.js +197 -178
- package/dist/schema.d.ts +1 -0
- package/dist/schema.js +2 -0
- package/dist/server/api.group.d.ts +22 -1
- package/dist/server/api.group.js +10 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/schema.d.ts +20 -0
- package/dist/server/schema.js +5 -0
- package/dist/service.d.ts +50 -0
- package/package.json +1 -1
|
@@ -39,6 +39,9 @@ declare const messages: {
|
|
|
39
39
|
readonly organization_invite_member_title: "Invite a member";
|
|
40
40
|
readonly organization_loading: "Loading...";
|
|
41
41
|
readonly organization_location: "Location";
|
|
42
|
+
readonly organization_parent: "Parent organization";
|
|
43
|
+
readonly organization_parent_description: "Optionally group this organization under another organization.";
|
|
44
|
+
readonly organization_parent_none: "No parent organization";
|
|
42
45
|
readonly organization_icon: "Icon";
|
|
43
46
|
readonly organization_logo: "Logo";
|
|
44
47
|
readonly organization_logo_upload_error: "Could not upload the organization logo.";
|
|
@@ -127,6 +130,9 @@ declare const messages: {
|
|
|
127
130
|
readonly organization_invite_member_title: "Inviter un membre";
|
|
128
131
|
readonly organization_loading: "Chargement...";
|
|
129
132
|
readonly organization_location: "Emplacement";
|
|
133
|
+
readonly organization_parent: "Organisation parente";
|
|
134
|
+
readonly organization_parent_description: "Regroupez facultativement cette organisation sous une autre organisation.";
|
|
135
|
+
readonly organization_parent_none: "Aucune organisation parente";
|
|
130
136
|
readonly organization_icon: "Icône";
|
|
131
137
|
readonly organization_logo: "Logo";
|
|
132
138
|
readonly organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.";
|
|
@@ -191,6 +197,7 @@ export type OrganizationSwitcherProps = {
|
|
|
191
197
|
menuActions?: ReactNode;
|
|
192
198
|
renderUnauthenticated?: () => ReactNode;
|
|
193
199
|
locked?: boolean;
|
|
200
|
+
organizationWhitelist?: readonly string[];
|
|
194
201
|
messages?: OrganizationSwitcherMessages;
|
|
195
202
|
dialog?: OrganizationSwitcherDialog | null;
|
|
196
203
|
onChange?: (organization: OrganizationSummary | null) => void;
|
|
@@ -203,7 +210,8 @@ type OrganizationSummary = {
|
|
|
203
210
|
slug: string;
|
|
204
211
|
metadata?: unknown;
|
|
205
212
|
userId?: string | null;
|
|
213
|
+
parentId?: string | null;
|
|
206
214
|
};
|
|
207
215
|
export type OrganizationSwitcherDialog = "create" | "manage" | "members" | "apiKeys" | "invitations";
|
|
208
|
-
export declare function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side, className, defaultDialog, hideTrigger, menuActions, renderUnauthenticated, locked, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
216
|
+
export declare function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side, className, defaultDialog, hideTrigger, menuActions, renderUnauthenticated, locked, organizationWhitelist, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }: OrganizationSwitcherProps): import("react").JSX.Element;
|
|
209
217
|
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useAtomRefresh, useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
|
-
import {
|
|
3
|
+
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
4
|
import {} from "@tanstack/react-table";
|
|
5
|
-
import { Effect, Schema } from "effect";
|
|
5
|
+
import { Effect, Option, Schema } from "effect";
|
|
6
6
|
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
7
7
|
import { 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 "@/components/ui/data-table";
|
|
10
|
+
import { ImageField, SelectField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
|
|
10
11
|
import { EditingLocaleSwitcher } from "@/components/ui/editing-locale-switcher";
|
|
11
12
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
12
13
|
import { FieldSet } from "@/components/ui/field";
|
|
13
|
-
import { useAppForm } from "@/components/ui/form";
|
|
14
14
|
import { Badge } from "@/components/ui/badge";
|
|
15
15
|
import { Button } from "@/components/ui/button";
|
|
16
16
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
@@ -63,6 +63,9 @@ const messages = {
|
|
|
63
63
|
organization_invite_member_title: "Invite a member",
|
|
64
64
|
organization_loading: "Loading...",
|
|
65
65
|
organization_location: "Location",
|
|
66
|
+
organization_parent: "Parent organization",
|
|
67
|
+
organization_parent_description: "Optionally group this organization under another organization.",
|
|
68
|
+
organization_parent_none: "No parent organization",
|
|
66
69
|
organization_icon: "Icon",
|
|
67
70
|
organization_logo: "Logo",
|
|
68
71
|
organization_logo_upload_error: "Could not upload the organization logo.",
|
|
@@ -151,6 +154,9 @@ const messages = {
|
|
|
151
154
|
organization_invite_member_title: "Inviter un membre",
|
|
152
155
|
organization_loading: "Chargement...",
|
|
153
156
|
organization_location: "Emplacement",
|
|
157
|
+
organization_parent: "Organisation parente",
|
|
158
|
+
organization_parent_description: "Regroupez facultativement cette organisation sous une autre organisation.",
|
|
159
|
+
organization_parent_none: "Aucune organisation parente",
|
|
154
160
|
organization_icon: "Icône",
|
|
155
161
|
organization_logo: "Logo",
|
|
156
162
|
organization_logo_upload_error: "Impossible de téléverser le logo de l'organisation.",
|
|
@@ -284,11 +290,35 @@ const organizationApiKeysAtom = Atom.family((authClient) => Atom.family((organiz
|
|
|
284
290
|
catch: (error) => error,
|
|
285
291
|
})))));
|
|
286
292
|
const emptyOrganizationApiKeysAtom = Atom.make(Effect.succeed([]));
|
|
293
|
+
const organizationImageSchema = Schema.Union([
|
|
294
|
+
Schema.String,
|
|
295
|
+
Schema.instanceOf(File),
|
|
296
|
+
Schema.Null,
|
|
297
|
+
Schema.Undefined,
|
|
298
|
+
]);
|
|
299
|
+
const organizationFormBuilder = FormBuilder.empty
|
|
300
|
+
.addField("parentId", Schema.String)
|
|
301
|
+
.addField("slug", Schema.String)
|
|
302
|
+
.addField("enName", Schema.String)
|
|
303
|
+
.addField("enLogo", organizationImageSchema)
|
|
304
|
+
.addField("enIcon", organizationImageSchema)
|
|
305
|
+
.addField("enContactEmail", Schema.String)
|
|
306
|
+
.addField("enLocation", Schema.String)
|
|
307
|
+
.addField("frName", Schema.String)
|
|
308
|
+
.addField("frLogo", organizationImageSchema)
|
|
309
|
+
.addField("frIcon", organizationImageSchema)
|
|
310
|
+
.addField("frContactEmail", Schema.String)
|
|
311
|
+
.addField("frLocation", Schema.String);
|
|
312
|
+
const inviteMemberFormBuilder = FormBuilder.empty
|
|
313
|
+
.addField("email", Schema.NonEmptyString)
|
|
314
|
+
.addField("role", Schema.String);
|
|
315
|
+
const apiKeyFormBuilder = FormBuilder.empty.addField("name", Schema.NonEmptyString);
|
|
287
316
|
const slugify = (value) => value
|
|
288
317
|
.trim()
|
|
289
318
|
.toLowerCase()
|
|
290
319
|
.replace(/[^a-z0-9]+/g, "-")
|
|
291
320
|
.replace(/^-+|-+$/g, "");
|
|
321
|
+
const noParentOrganization = "__none__";
|
|
292
322
|
const isOrganizationSlugConflict = (error) => {
|
|
293
323
|
if (typeof error !== "object" || error === null)
|
|
294
324
|
return false;
|
|
@@ -345,11 +375,26 @@ const organizationDisplay = (organization, m, baseUrl) => {
|
|
|
345
375
|
const organizationSwitcherSubtitle = (organization, subtitle, m) => organization?.userId
|
|
346
376
|
? `${m.organization_switcher_personal()} · ${subtitle}`
|
|
347
377
|
: subtitle;
|
|
378
|
+
const organizationParentOptions = (organizations, m, excludedOrganizationId) => [
|
|
379
|
+
{
|
|
380
|
+
label: m.organization_parent_none(),
|
|
381
|
+
value: noParentOrganization,
|
|
382
|
+
},
|
|
383
|
+
...organizations
|
|
384
|
+
.filter((organization) => organization.id !== excludedOrganizationId &&
|
|
385
|
+
!organization.userId &&
|
|
386
|
+
!organization.parentId)
|
|
387
|
+
.map((organization) => ({
|
|
388
|
+
label: organizationDisplay(organization, m).name,
|
|
389
|
+
value: organization.id,
|
|
390
|
+
})),
|
|
391
|
+
];
|
|
348
392
|
const organizationFormDefaults = (organization, baseUrl) => {
|
|
349
393
|
const translations = parseOrganizationMetadata(organization?.metadata).translations;
|
|
350
394
|
const en = translations.find((translation) => translation.locale === "en");
|
|
351
395
|
const fr = translations.find((translation) => translation.locale === "fr");
|
|
352
396
|
return {
|
|
397
|
+
parentId: organization?.parentId ?? noParentOrganization,
|
|
353
398
|
slug: organization?.slug ?? "",
|
|
354
399
|
enName: en?.name || organization?.name || "",
|
|
355
400
|
enLogo: assetUrl(en?.logo, baseUrl) || null,
|
|
@@ -434,7 +479,7 @@ const organizationMetadataFromForm = async (value, m, uploadImage) => {
|
|
|
434
479
|
}
|
|
435
480
|
return { translations };
|
|
436
481
|
};
|
|
437
|
-
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, menuActions, renderUnauthenticated, locked = false, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
482
|
+
export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl, side = "bottom", className, defaultDialog = null, hideTrigger = false, menuActions, renderUnauthenticated, locked = false, organizationWhitelist, messages, dialog: controlledDialog, onChange, onCreate, onDialogChange, }) {
|
|
438
483
|
const auth = useKrakstackAuth();
|
|
439
484
|
const authClient = providedAuthClient ?? auth?.authClient;
|
|
440
485
|
if (!authClient) {
|
|
@@ -496,8 +541,10 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
496
541
|
}
|
|
497
542
|
const active = activeOrganization.data;
|
|
498
543
|
const activeName = active?.name;
|
|
544
|
+
const visibleOrganizations = organizations.data?.filter((organization) => !organizationWhitelist ||
|
|
545
|
+
organizationWhitelist.includes(organization.id)) ?? [];
|
|
499
546
|
const selectableOrganizations = !locked
|
|
500
|
-
?
|
|
547
|
+
? visibleOrganizations.filter((organization) => organization.id !== active?.id)
|
|
501
548
|
: [];
|
|
502
549
|
const hasOrganizationListItems = organizations.isPending || Boolean(organizations.error) || !locked;
|
|
503
550
|
const refreshAfterInvitationAction = async (previousActiveId) => {
|
|
@@ -543,7 +590,7 @@ export function OrganizationSwitcher({ authClient: providedAuthClient, baseUrl,
|
|
|
543
590
|
}, children: [_jsx(Copy, {}), m.organization_copy_id()] }));
|
|
544
591
|
})(), 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", onOpenChange: (open) => {
|
|
545
592
|
setDialog((current) => open ? "create" : current === "create" ? null : current);
|
|
546
|
-
}, 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, baseUrl: baseUrl, onCreated: async (organization) => {
|
|
593
|
+
}, 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, baseUrl: baseUrl, organizations: visibleOrganizations, onCreated: async (organization) => {
|
|
547
594
|
setDialog(null);
|
|
548
595
|
const activeResult = await authClient.organization.setActive({
|
|
549
596
|
organizationId: organization.id,
|
|
@@ -685,21 +732,26 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
|
|
|
685
732
|
const [defaultLocale] = useState(currentOrganizationLocale);
|
|
686
733
|
const [editingLocale, setEditingLocale] = useState(defaultLocale);
|
|
687
734
|
const defaultValues = organizationFormDefaults(organization, baseUrl);
|
|
688
|
-
const form =
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
735
|
+
const [form] = useState(() => FormReact.make(organizationFormBuilder, {
|
|
736
|
+
fields: {
|
|
737
|
+
parentId: SelectField,
|
|
738
|
+
slug: TextField,
|
|
739
|
+
enName: TextField,
|
|
740
|
+
enLogo: ImageField,
|
|
741
|
+
enIcon: ImageField,
|
|
742
|
+
enContactEmail: TextField,
|
|
743
|
+
enLocation: TextField,
|
|
744
|
+
frName: TextField,
|
|
745
|
+
frLogo: ImageField,
|
|
746
|
+
frIcon: ImageField,
|
|
747
|
+
frContactEmail: TextField,
|
|
748
|
+
frLocation: TextField,
|
|
749
|
+
},
|
|
750
|
+
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
751
|
+
try: async () => {
|
|
693
752
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
694
|
-
if (!name)
|
|
695
|
-
|
|
696
|
-
onSubmit: {
|
|
697
|
-
form: m.organization_name_required(),
|
|
698
|
-
fields: {},
|
|
699
|
-
},
|
|
700
|
-
});
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
753
|
+
if (!name)
|
|
754
|
+
throw new Error(m.organization_name_required());
|
|
703
755
|
const slug = value.slug.trim().toLowerCase();
|
|
704
756
|
const metadata = await organizationMetadataFromForm(value, m, uploadImage);
|
|
705
757
|
const result = await authClient.organization.update({
|
|
@@ -707,151 +759,137 @@ function EditOrganizationSection({ authClient, baseUrl, organization, onUpdated,
|
|
|
707
759
|
data: { name, slug, metadata },
|
|
708
760
|
});
|
|
709
761
|
if (result.error) {
|
|
710
|
-
|
|
711
|
-
onSubmit: {
|
|
712
|
-
form: result.error.message ?? m.organization_update_error(),
|
|
713
|
-
fields: {},
|
|
714
|
-
},
|
|
715
|
-
});
|
|
716
|
-
return;
|
|
762
|
+
throw new Error(result.error.message ?? m.organization_update_error());
|
|
717
763
|
}
|
|
718
764
|
await onUpdated();
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
},
|
|
731
|
-
});
|
|
732
|
-
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) => {
|
|
765
|
+
return result.data;
|
|
766
|
+
},
|
|
767
|
+
catch: (cause) => cause instanceof Error
|
|
768
|
+
? cause
|
|
769
|
+
: new Error(m.organization_update_error()),
|
|
770
|
+
}),
|
|
771
|
+
}));
|
|
772
|
+
const submit = useAtomSet(form.submit);
|
|
773
|
+
const submitResult = useAtomValue(form.submit);
|
|
774
|
+
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
733
775
|
event.preventDefault();
|
|
734
776
|
event.stopPropagation();
|
|
735
|
-
|
|
736
|
-
}, children: [_jsx(form.
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
777
|
+
submit();
|
|
778
|
+
}, children: [_jsx(form.slug, { label: m.organization_slug(), required: true }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationTranslationHeader, { locale: editingLocale, editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
|
|
779
|
+
width: 175,
|
|
780
|
+
height: 50,
|
|
781
|
+
suggestedWidth: 350,
|
|
782
|
+
suggestedHeight: 100,
|
|
783
|
+
} }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
|
|
784
|
+
width: 96,
|
|
785
|
+
height: 96,
|
|
786
|
+
suggestedWidth: 512,
|
|
787
|
+
suggestedHeight: 512,
|
|
788
|
+
} }), _jsx(form.enContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.enLocation, { label: m.organization_location() })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
|
|
789
|
+
width: 175,
|
|
790
|
+
height: 50,
|
|
791
|
+
suggestedWidth: 350,
|
|
792
|
+
suggestedHeight: 100,
|
|
793
|
+
} }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
|
|
794
|
+
width: 96,
|
|
795
|
+
height: 96,
|
|
796
|
+
suggestedWidth: 512,
|
|
797
|
+
suggestedHeight: 512,
|
|
798
|
+
} }), _jsx(form.frContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.frLocation, { label: m.organization_location() })] }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
757
799
|
}
|
|
758
|
-
function CreateOrganizationSection({ authClient, baseUrl, onCreated, }) {
|
|
800
|
+
function CreateOrganizationSection({ authClient, baseUrl, organizations, onCreated, }) {
|
|
759
801
|
const m = useOrganizationMessages();
|
|
760
802
|
const uploadImage = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
|
|
761
803
|
const [defaultLocale] = useState(currentOrganizationLocale);
|
|
762
804
|
const [editingLocale, setEditingLocale] = useState(defaultLocale);
|
|
763
805
|
const defaultValues = organizationFormDefaults(undefined, baseUrl);
|
|
764
|
-
const form =
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
806
|
+
const [form] = useState(() => FormReact.make(organizationFormBuilder, {
|
|
807
|
+
fields: {
|
|
808
|
+
parentId: SelectField,
|
|
809
|
+
slug: TextField,
|
|
810
|
+
enName: TextField,
|
|
811
|
+
enLogo: ImageField,
|
|
812
|
+
enIcon: ImageField,
|
|
813
|
+
enContactEmail: TextField,
|
|
814
|
+
enLocation: TextField,
|
|
815
|
+
frName: TextField,
|
|
816
|
+
frLogo: ImageField,
|
|
817
|
+
frIcon: ImageField,
|
|
818
|
+
frContactEmail: TextField,
|
|
819
|
+
frLocation: TextField,
|
|
820
|
+
},
|
|
821
|
+
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
822
|
+
try: async () => {
|
|
769
823
|
const name = organizationNameFromForm(value, defaultLocale);
|
|
770
|
-
if (!name)
|
|
771
|
-
|
|
772
|
-
onSubmit: {
|
|
773
|
-
form: m.organization_name_required(),
|
|
774
|
-
fields: {},
|
|
775
|
-
},
|
|
776
|
-
});
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
824
|
+
if (!name)
|
|
825
|
+
throw new Error(m.organization_name_required());
|
|
779
826
|
const slug = (value.slug.trim() || slugify(name)).toLowerCase();
|
|
780
|
-
const metadata = await organizationMetadataFromForm({
|
|
781
|
-
...value,
|
|
782
|
-
slug,
|
|
783
|
-
}, m, uploadImage);
|
|
827
|
+
const metadata = await organizationMetadataFromForm({ ...value, slug }, m, uploadImage);
|
|
784
828
|
const result = await authClient.organization.create({
|
|
785
829
|
name,
|
|
786
830
|
slug,
|
|
787
831
|
metadata,
|
|
832
|
+
...(value.parentId === noParentOrganization
|
|
833
|
+
? {}
|
|
834
|
+
: { parentId: value.parentId }),
|
|
788
835
|
});
|
|
789
836
|
if (result.error) {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
fields: {
|
|
794
|
-
slug: { message: m.organization_create_slug_conflict() },
|
|
795
|
-
},
|
|
796
|
-
},
|
|
797
|
-
});
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
formApi.setErrorMap({
|
|
801
|
-
onSubmit: {
|
|
802
|
-
form: result.error.message ?? m.organization_create_error(),
|
|
803
|
-
fields: {},
|
|
804
|
-
},
|
|
805
|
-
});
|
|
806
|
-
return;
|
|
837
|
+
throw new Error(isOrganizationSlugConflict(result.error)
|
|
838
|
+
? m.organization_create_slug_conflict()
|
|
839
|
+
: (result.error.message ?? m.organization_create_error()));
|
|
807
840
|
}
|
|
808
|
-
form.reset();
|
|
809
841
|
await onCreated(result.data);
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
const name = useStore(form.store, (state) => organizationNameFromForm(state.values, defaultLocale));
|
|
824
|
-
const slugIsDirty = useStore(form.store, (state) => state.fieldMeta.slug?.isDirty ?? false);
|
|
842
|
+
return result.data;
|
|
843
|
+
},
|
|
844
|
+
catch: (cause) => cause instanceof Error
|
|
845
|
+
? cause
|
|
846
|
+
: new Error(m.organization_create_error()),
|
|
847
|
+
}),
|
|
848
|
+
}));
|
|
849
|
+
const submit = useAtomSet(form.submit);
|
|
850
|
+
const submitResult = useAtomValue(form.submit);
|
|
851
|
+
const values = useAtomValue(form.values);
|
|
852
|
+
const setSlug = useAtomSet(form.getFieldAtoms(form.fields.slug).setValue);
|
|
853
|
+
const lastGeneratedSlug = useRef("");
|
|
854
|
+
const slugWasEdited = useRef(false);
|
|
825
855
|
useEffect(() => {
|
|
826
|
-
if (
|
|
827
|
-
|
|
856
|
+
if (Option.isNone(values) || slugWasEdited.current)
|
|
857
|
+
return;
|
|
858
|
+
if (values.value.slug !== lastGeneratedSlug.current) {
|
|
859
|
+
slugWasEdited.current = true;
|
|
860
|
+
return;
|
|
828
861
|
}
|
|
829
|
-
|
|
830
|
-
|
|
862
|
+
const generatedSlug = slugify(organizationNameFromForm(values.value, defaultLocale));
|
|
863
|
+
if (generatedSlug === values.value.slug)
|
|
864
|
+
return;
|
|
865
|
+
lastGeneratedSlug.current = generatedSlug;
|
|
866
|
+
setSlug(generatedSlug);
|
|
867
|
+
}, [defaultLocale, setSlug, values]);
|
|
868
|
+
return (_jsx("section", { className: "flex flex-col gap-4", children: _jsx(form.Initialize, { defaultValues: defaultValues, children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
831
869
|
event.preventDefault();
|
|
832
870
|
event.stopPropagation();
|
|
833
|
-
|
|
834
|
-
}, children: [_jsx(form.
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
871
|
+
submit();
|
|
872
|
+
}, children: [_jsx(form.slug, { label: m.organization_slug(), description: m.organization_slug_description() }), _jsx(form.parentId, { label: m.organization_parent(), description: m.organization_parent_description(), options: organizationParentOptions(organizations, m) }), _jsx(Separator, { className: "my-2" }), _jsx(OrganizationTranslationHeader, { locale: editingLocale, editingLocale: editingLocale, onEditingLocaleChange: setEditingLocale }), _jsxs(FieldSet, { disabled: editingLocale !== "en", className: editingLocale === "en" ? "contents" : "hidden", children: [_jsx(form.enName, { label: m.organization_translation_name() }), _jsx(form.enLogo, { label: m.organization_logo(), size: {
|
|
873
|
+
width: 175,
|
|
874
|
+
height: 50,
|
|
875
|
+
suggestedWidth: 350,
|
|
876
|
+
suggestedHeight: 100,
|
|
877
|
+
} }), _jsx(form.enIcon, { label: m.organization_icon(), size: {
|
|
878
|
+
width: 96,
|
|
879
|
+
height: 96,
|
|
880
|
+
suggestedWidth: 512,
|
|
881
|
+
suggestedHeight: 512,
|
|
882
|
+
} }), _jsx(form.enContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.enLocation, { label: m.organization_location() })] }), _jsxs(FieldSet, { disabled: editingLocale !== "fr", className: editingLocale === "fr" ? "contents" : "hidden", children: [_jsx(form.frName, { label: m.organization_translation_name() }), _jsx(form.frLogo, { label: m.organization_logo(), size: {
|
|
883
|
+
width: 175,
|
|
884
|
+
height: 50,
|
|
885
|
+
suggestedWidth: 350,
|
|
886
|
+
suggestedHeight: 100,
|
|
887
|
+
} }), _jsx(form.frIcon, { label: m.organization_icon(), size: {
|
|
888
|
+
width: 96,
|
|
889
|
+
height: 96,
|
|
890
|
+
suggestedWidth: 512,
|
|
891
|
+
suggestedHeight: 512,
|
|
892
|
+
} }), _jsx(form.frContactEmail, { label: m.organization_contact_email(), placeholder: "team@example.com", type: "email" }), _jsx(form.frLocation, { label: m.organization_location() })] }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form })] }) }) }));
|
|
855
893
|
}
|
|
856
894
|
function OrganizationTranslationHeader({ locale, editingLocale, onEditingLocaleChange, }) {
|
|
857
895
|
const m = useOrganizationMessages();
|
|
@@ -903,28 +941,36 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
903
941
|
return;
|
|
904
942
|
setLastMembersData(currentMembersData);
|
|
905
943
|
}, [currentMembersData]);
|
|
906
|
-
const inviteForm =
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
const result = await authClient.organization.inviteMember({
|
|
911
|
-
email: value.email.trim(),
|
|
912
|
-
role: normalizeInvitationRole(value.role),
|
|
913
|
-
organizationId: organization.id,
|
|
914
|
-
});
|
|
915
|
-
if (result.error) {
|
|
916
|
-
formApi.setErrorMap({
|
|
917
|
-
onSubmit: {
|
|
918
|
-
form: result.error.message ?? m.organization_invite_error(),
|
|
919
|
-
fields: {},
|
|
920
|
-
},
|
|
921
|
-
});
|
|
922
|
-
return;
|
|
923
|
-
}
|
|
924
|
-
inviteForm.reset();
|
|
925
|
-
refreshMembers();
|
|
944
|
+
const [inviteForm] = useState(() => FormReact.make(inviteMemberFormBuilder, {
|
|
945
|
+
fields: {
|
|
946
|
+
email: TextField,
|
|
947
|
+
role: SelectField,
|
|
926
948
|
},
|
|
927
|
-
|
|
949
|
+
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
950
|
+
try: async () => {
|
|
951
|
+
const result = await authClient.organization.inviteMember({
|
|
952
|
+
email: value.email.trim(),
|
|
953
|
+
role: normalizeInvitationRole(value.role),
|
|
954
|
+
organizationId: organization.id,
|
|
955
|
+
});
|
|
956
|
+
if (result.error) {
|
|
957
|
+
throw new Error(result.error.message ?? m.organization_invite_error());
|
|
958
|
+
}
|
|
959
|
+
refreshMembers();
|
|
960
|
+
return result.data;
|
|
961
|
+
},
|
|
962
|
+
catch: (cause) => cause instanceof Error
|
|
963
|
+
? cause
|
|
964
|
+
: new Error(m.organization_invite_error()),
|
|
965
|
+
}),
|
|
966
|
+
}));
|
|
967
|
+
const submitInvitation = useAtomSet(inviteForm.submit);
|
|
968
|
+
const resetInvitation = useAtomSet(inviteForm.reset);
|
|
969
|
+
const inviteResult = useAtomValue(inviteForm.submit);
|
|
970
|
+
useEffect(() => {
|
|
971
|
+
if (AsyncResult.isSuccess(inviteResult))
|
|
972
|
+
resetInvitation();
|
|
973
|
+
}, [inviteResult, resetInvitation]);
|
|
928
974
|
const updateRole = async (member, role) => {
|
|
929
975
|
setError(null);
|
|
930
976
|
const nextRole = Array.isArray(role)
|
|
@@ -985,14 +1031,14 @@ function OrganizationMembersManager({ authClient, baseUrl, canManageMembers, org
|
|
|
985
1031
|
}
|
|
986
1032
|
refreshMembers();
|
|
987
1033
|
};
|
|
988
|
-
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx("div", { className: "min-h-40 rounded-lg border p-4", children: _jsx(inviteForm.
|
|
1034
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-5", children: [canInviteMembers ? (_jsx("div", { className: "min-h-40 rounded-lg border p-4", children: _jsx(inviteForm.Initialize, { defaultValues: { email: "", role: "member" }, children: _jsxs("form", { className: "grid gap-4 sm:grid-cols-[minmax(0,1fr)_12rem_auto] sm:items-end", onSubmit: (event) => {
|
|
989
1035
|
event.preventDefault();
|
|
990
1036
|
event.stopPropagation();
|
|
991
|
-
|
|
992
|
-
}, 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.
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1037
|
+
submitInvitation();
|
|
1038
|
+
}, 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.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) => ({
|
|
1039
|
+
label: organizationRoleLabel(role, m),
|
|
1040
|
+
value: role,
|
|
1041
|
+
})) }), _jsx("div", { className: "self-end", children: _jsx(SubmitButton, { form: inviteForm }) }), _jsx(SubmitError, { result: inviteResult })] }) }) })) : null, membersError ? (_jsx("p", { className: "text-destructive text-sm", children: membersError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsxs("section", { className: "flex min-w-0 flex-col gap-3", children: [_jsxs("div", { children: [_jsx("h3", { className: "font-medium", children: m.organization_members_heading() }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.organization_members_description() })] }), _jsx("div", { className: "-m-1 min-w-0 overflow-x-auto p-1", children: _jsx(DataTable, { columns: memberColumns({
|
|
996
1042
|
m,
|
|
997
1043
|
baseUrl,
|
|
998
1044
|
canChangeRoles: canManageMembers,
|
|
@@ -1138,33 +1184,32 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1138
1184
|
onSuccess: () => null,
|
|
1139
1185
|
});
|
|
1140
1186
|
const loading = keysResult._tag === "Initial";
|
|
1141
|
-
const createForm =
|
|
1142
|
-
|
|
1143
|
-
onSubmit:
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
try {
|
|
1187
|
+
const [createForm] = useState(() => FormReact.make(apiKeyFormBuilder, {
|
|
1188
|
+
fields: { name: TextField },
|
|
1189
|
+
onSubmit: (_, { decoded: value }) => Effect.tryPromise({
|
|
1190
|
+
try: async () => {
|
|
1191
|
+
setCreatedKey(null);
|
|
1147
1192
|
const created = await createApiKey({
|
|
1148
1193
|
configId: "organization",
|
|
1149
1194
|
organizationId: organization.id,
|
|
1150
1195
|
name: value.name.trim(),
|
|
1151
1196
|
}, m.user_api_key_create_error());
|
|
1152
1197
|
setCreatedKey(created.key);
|
|
1153
|
-
createForm.reset();
|
|
1154
1198
|
refreshKeys();
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1199
|
+
return created;
|
|
1200
|
+
},
|
|
1201
|
+
catch: (cause) => cause instanceof Error
|
|
1202
|
+
? cause
|
|
1203
|
+
: new Error(m.user_api_key_create_error()),
|
|
1204
|
+
}),
|
|
1205
|
+
}));
|
|
1206
|
+
const submitApiKey = useAtomSet(createForm.submit);
|
|
1207
|
+
const resetApiKey = useAtomSet(createForm.reset);
|
|
1208
|
+
const createResult = useAtomValue(createForm.submit);
|
|
1209
|
+
useEffect(() => {
|
|
1210
|
+
if (AsyncResult.isSuccess(createResult))
|
|
1211
|
+
resetApiKey();
|
|
1212
|
+
}, [createResult, resetApiKey]);
|
|
1168
1213
|
const deleteKey = async (key) => {
|
|
1169
1214
|
const result = await authClient.apiKey.delete({
|
|
1170
1215
|
configId: "organization",
|
|
@@ -1176,11 +1221,11 @@ function OrganizationApiKeyManager({ authClient, organization, active, }) {
|
|
|
1176
1221
|
}
|
|
1177
1222
|
refreshKeys();
|
|
1178
1223
|
};
|
|
1179
|
-
return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsx(createForm.
|
|
1224
|
+
return (_jsxs("div", { className: "flex flex-col gap-5", children: [_jsx(createForm.Initialize, { defaultValues: { name: "" }, children: _jsxs("form", { className: "flex max-w-xl flex-col gap-4", onSubmit: (event) => {
|
|
1180
1225
|
event.preventDefault();
|
|
1181
1226
|
event.stopPropagation();
|
|
1182
|
-
|
|
1183
|
-
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.
|
|
1227
|
+
submitApiKey();
|
|
1228
|
+
}, children: [_jsx("p", { className: "text-muted-foreground text-sm", children: m.api_key_rate_limit_notice() }), _jsx(createForm.name, { label: m.user_api_key_name(), required: true }), _jsx(SubmitError, { result: createResult }), _jsx(SubmitButton, { form: createForm })] }) }), createdKey ? (_jsxs("div", { className: "flex flex-col gap-2 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2 font-medium", children: [_jsx(KeyRound, {}), m.user_api_key_created_title()] }), _jsx("p", { className: "text-muted-foreground text-sm", children: m.user_api_key_created_description() }), _jsx("code", { className: "bg-muted overflow-x-auto rounded-md p-3 text-sm", children: createdKey })] })) : null, keysError ? (_jsx("p", { className: "text-destructive text-sm", children: keysError })) : null, error ? _jsx("p", { className: "text-destructive text-sm", children: error }) : null, _jsx(Separator, {}), _jsx(DataTable, { columns: apiKeyColumns({ m }), data: keys, features: {
|
|
1184
1229
|
export: { baseName: `${organization.slug}-api-keys` },
|
|
1185
1230
|
gallery: false,
|
|
1186
1231
|
rowActions: {
|