@krak-stack/auth 0.1.38 → 0.1.40
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/api.d.ts +22 -0
- package/dist/better-auth/api.d.ts +2 -0
- package/dist/better-auth/index.d.ts +1 -0
- package/dist/better-auth/schema.d.ts +1 -0
- package/dist/better-auth/schema.js +1 -0
- package/dist/components/admin-organization-form.d.ts +6 -0
- package/dist/components/admin-organization-form.js +136 -0
- package/dist/components/admin-organizations.d.ts +7 -0
- package/dist/components/admin-organizations.js +118 -0
- package/dist/components/admin-users.d.ts +8 -0
- package/dist/components/admin-users.js +265 -0
- package/dist/components/auth-api-client.d.ts +22 -0
- package/dist/components/auth-client.d.ts +3 -1
- package/dist/components/auth-forms.js +10 -24
- package/dist/components/auth-provider.d.ts +16 -15
- package/dist/components/auth-provider.js +51 -4
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +3 -0
- package/dist/components/user-button.d.ts +11 -1
- package/dist/components/user-button.js +73 -15
- package/dist/extra/api.d.ts +2 -0
- package/dist/extra/index.d.ts +1 -0
- package/dist/extra/schema.d.ts +1 -0
- package/dist/extra/schema.js +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +3 -0
- package/dist/server/api.d.ts +40 -0
- package/dist/server/index.d.ts +3 -0
- package/dist/server/index.js +1 -0
- package/dist/server/middleware.d.ts +23 -0
- package/dist/server/middleware.js +40 -0
- package/dist/server/schema.d.ts +6 -0
- package/dist/server/schema.js +8 -0
- package/dist/service.d.ts +516 -437
- package/dist/service.js +96 -12
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
20
20
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
21
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
22
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
23
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
23
24
|
readonly createdAt: import("effect/Schema").Date;
|
|
24
25
|
readonly updatedAt: import("effect/Schema").Date;
|
|
25
26
|
}>;
|
|
@@ -35,6 +36,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
35
36
|
readonly projectId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
36
37
|
readonly clientId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
37
38
|
readonly host: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
39
|
+
readonly rootHost: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
38
40
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
39
41
|
readonly projectKey: import("effect/Schema").String;
|
|
40
42
|
readonly name: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
@@ -100,7 +102,11 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
100
102
|
readonly hostname: import("effect/Schema").String;
|
|
101
103
|
readonly rootHostname: import("effect/Schema").String;
|
|
102
104
|
readonly projectId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
105
|
+
readonly projectName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
106
|
+
readonly projectLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
103
107
|
readonly organizationId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
108
|
+
readonly organizationName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
109
|
+
readonly organizationLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
104
110
|
readonly hostnameId: import("effect/Schema").String;
|
|
105
111
|
readonly managed: import("effect/Schema").Boolean;
|
|
106
112
|
readonly active: import("effect/Schema").Boolean;
|
|
@@ -113,7 +119,11 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
113
119
|
readonly hostname: import("effect/Schema").String;
|
|
114
120
|
readonly rootHostname: import("effect/Schema").String;
|
|
115
121
|
readonly projectId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
122
|
+
readonly projectName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
123
|
+
readonly projectLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
116
124
|
readonly organizationId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
125
|
+
readonly organizationName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
126
|
+
readonly organizationLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
117
127
|
readonly hostnameId: import("effect/Schema").String;
|
|
118
128
|
readonly managed: import("effect/Schema").Boolean;
|
|
119
129
|
readonly active: import("effect/Schema").Boolean;
|
|
@@ -126,7 +136,11 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
126
136
|
readonly hostname: import("effect/Schema").String;
|
|
127
137
|
readonly rootHostname: import("effect/Schema").String;
|
|
128
138
|
readonly projectId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
139
|
+
readonly projectName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
140
|
+
readonly projectLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
129
141
|
readonly organizationId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
142
|
+
readonly organizationName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
143
|
+
readonly organizationLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
130
144
|
readonly hostnameId: import("effect/Schema").String;
|
|
131
145
|
readonly managed: import("effect/Schema").Boolean;
|
|
132
146
|
readonly active: import("effect/Schema").Boolean;
|
|
@@ -139,7 +153,11 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
139
153
|
readonly hostname: import("effect/Schema").String;
|
|
140
154
|
readonly rootHostname: import("effect/Schema").String;
|
|
141
155
|
readonly projectId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
156
|
+
readonly projectName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
157
|
+
readonly projectLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
142
158
|
readonly organizationId: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
159
|
+
readonly organizationName: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
160
|
+
readonly organizationLogo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
143
161
|
readonly hostnameId: import("effect/Schema").String;
|
|
144
162
|
readonly managed: import("effect/Schema").Boolean;
|
|
145
163
|
readonly active: import("effect/Schema").Boolean;
|
|
@@ -170,6 +188,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
170
188
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
171
189
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
172
190
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
191
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
173
192
|
readonly createdAt: import("effect/Schema").Date;
|
|
174
193
|
readonly updatedAt: import("effect/Schema").Date;
|
|
175
194
|
}>;
|
|
@@ -207,6 +226,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
207
226
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
208
227
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
209
228
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
229
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
210
230
|
readonly createdAt: import("effect/Schema").Date;
|
|
211
231
|
readonly updatedAt: import("effect/Schema").Date;
|
|
212
232
|
}>;
|
|
@@ -242,6 +262,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
242
262
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
243
263
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
244
264
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
265
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
245
266
|
readonly createdAt: import("effect/Schema").Date;
|
|
246
267
|
readonly updatedAt: import("effect/Schema").Date;
|
|
247
268
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getUserActiveOrganization", "GET", "/api/organizations/user/:userId/active", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
@@ -259,6 +280,7 @@ export declare const AuthApi: HttpApi.HttpApi<"AuthApi", import("effect/unstable
|
|
|
259
280
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
260
281
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
261
282
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
283
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
262
284
|
readonly createdAt: import("effect/Schema").Date;
|
|
263
285
|
readonly updatedAt: import("effect/Schema").Date;
|
|
264
286
|
}>>;
|
|
@@ -22,6 +22,7 @@ export declare const BetterAuthApiGroup: HttpApiGroup.HttpApiGroup<"auth", HttpA
|
|
|
22
22
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
23
23
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
24
24
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
25
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
25
26
|
readonly createdAt: import("effect/Schema").Date;
|
|
26
27
|
readonly updatedAt: import("effect/Schema").Date;
|
|
27
28
|
}>;
|
|
@@ -47,6 +48,7 @@ export declare const BetterAuthApi: HttpApi.HttpApi<"BetterAuthApi", HttpApiGrou
|
|
|
47
48
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
48
49
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
49
50
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
51
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
50
52
|
readonly createdAt: import("effect/Schema").Date;
|
|
51
53
|
readonly updatedAt: import("effect/Schema").Date;
|
|
52
54
|
}>;
|
|
@@ -20,6 +20,7 @@ declare const BetterAuthApiClient_base: AtomHttpApi.AtomHttpApiClient<BetterAuth
|
|
|
20
20
|
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
21
21
|
readonly role: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
22
22
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
23
|
+
readonly lastLoginMethod: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
23
24
|
readonly createdAt: import("effect/Schema").Date;
|
|
24
25
|
readonly updatedAt: import("effect/Schema").Date;
|
|
25
26
|
}>;
|
|
@@ -21,6 +21,7 @@ export declare const GetSessionResponse: Schema.NullOr<Schema.Struct<{
|
|
|
21
21
|
readonly image: Schema.NullOr<Schema.String>;
|
|
22
22
|
readonly role: Schema.NullOr<Schema.String>;
|
|
23
23
|
readonly banned: Schema.NullOr<Schema.Boolean>;
|
|
24
|
+
readonly lastLoginMethod: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
24
25
|
readonly createdAt: Schema.Date;
|
|
25
26
|
readonly updatedAt: Schema.Date;
|
|
26
27
|
}>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Organization } from "@/services/organizations/schema";
|
|
2
|
+
export declare function AdminOrganizationForm({ organization, onClose, onSaved, }: {
|
|
3
|
+
organization?: Organization;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
onSaved: (organization: Organization) => void;
|
|
6
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { useAtomSet } from "@effect/atom-react";
|
|
4
|
+
import { Schema } from "effect";
|
|
5
|
+
import { Loader2 } from "lucide-react";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { toast } from "sonner";
|
|
8
|
+
import { ErrorMessage, useAppForm } from "@/components/ui/form";
|
|
9
|
+
import { Button } from "@/components/ui/button";
|
|
10
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
11
|
+
import { AdminApiClient } from "@/lib/admin-api-client";
|
|
12
|
+
import { ApiClient } from "@/lib/api-client";
|
|
13
|
+
import { assetPath, assetUrl } from "@/lib/assets";
|
|
14
|
+
import { authBaseUrl } from "@/services/auth/client";
|
|
15
|
+
import { CreateOrganizationPayload, } from "@/services/organizations/schema";
|
|
16
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
17
|
+
const defaultMessages = {
|
|
18
|
+
en: {
|
|
19
|
+
admin_organization_edit_description: "Update {name}'s canonical organization details.",
|
|
20
|
+
field_name: "Name",
|
|
21
|
+
form_submit: "Save",
|
|
22
|
+
organization_create_description: "Create an organization that can be used for Better Auth membership.",
|
|
23
|
+
organization_create_error: "Unable to create organization.",
|
|
24
|
+
organization_create_title: "Create organization",
|
|
25
|
+
organization_created_toast: "Organization created.",
|
|
26
|
+
organization_edit_title: "Edit organization",
|
|
27
|
+
organization_field_logo_url: "Logo",
|
|
28
|
+
organization_slug: "Slug",
|
|
29
|
+
organization_slug_description: "Leave blank to generate one from the name.",
|
|
30
|
+
organization_update_error: "Unable to update organization.",
|
|
31
|
+
organization_updated_toast: "Organization updated.",
|
|
32
|
+
},
|
|
33
|
+
fr: {
|
|
34
|
+
admin_organization_edit_description: "Mettez à jour les détails canoniques de l'organisation {name}.",
|
|
35
|
+
field_name: "Nom",
|
|
36
|
+
form_submit: "Enregistrer",
|
|
37
|
+
organization_create_description: "Créez une organisation utilisable pour les adhésions Better Auth.",
|
|
38
|
+
organization_create_error: "Impossible de créer l'organisation.",
|
|
39
|
+
organization_create_title: "Créer une organisation",
|
|
40
|
+
organization_created_toast: "Organisation créée.",
|
|
41
|
+
organization_edit_title: "Modifier l'organisation",
|
|
42
|
+
organization_field_logo_url: "Logo",
|
|
43
|
+
organization_slug: "Slug",
|
|
44
|
+
organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
|
|
45
|
+
organization_update_error: "Impossible de mettre à jour l'organisation.",
|
|
46
|
+
organization_updated_toast: "Organisation mise à jour.",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const labels = (locale) => ({
|
|
50
|
+
...defaultMessages[locale],
|
|
51
|
+
});
|
|
52
|
+
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
53
|
+
const slugify = (value) => value
|
|
54
|
+
.trim()
|
|
55
|
+
.toLowerCase()
|
|
56
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
57
|
+
.replace(/^-+|-+$/g, "");
|
|
58
|
+
const isFile = (value) => value instanceof File;
|
|
59
|
+
const createOrganizationAtom = AdminApiClient.mutation("admin", "createOrganization");
|
|
60
|
+
const updateOrganizationAtom = AdminApiClient.mutation("admin", "updateOrganization");
|
|
61
|
+
const uploadLogoAtom = ApiClient.mutation("organizations", "uploadOrganizationLogo");
|
|
62
|
+
const valuesToPayload = (value, logo) => Schema.decodeUnknownSync(CreateOrganizationPayload)({
|
|
63
|
+
name: value.name.trim(),
|
|
64
|
+
slug: slugify(value.slug || value.name),
|
|
65
|
+
logo: logo ?? undefined,
|
|
66
|
+
});
|
|
67
|
+
export function AdminOrganizationForm({ organization, onClose, onSaved, }) {
|
|
68
|
+
const auth = useKrakstackAuth();
|
|
69
|
+
const m = labels(auth?.locale ?? "en");
|
|
70
|
+
const createOrganization = useAtomSet(createOrganizationAtom, {
|
|
71
|
+
mode: "promise",
|
|
72
|
+
});
|
|
73
|
+
const updateOrganization = useAtomSet(updateOrganizationAtom, {
|
|
74
|
+
mode: "promise",
|
|
75
|
+
});
|
|
76
|
+
const uploadLogo = useAtomSet(uploadLogoAtom, {
|
|
77
|
+
mode: "promise",
|
|
78
|
+
});
|
|
79
|
+
const [error, setError] = useState("");
|
|
80
|
+
const isEditing = Boolean(organization);
|
|
81
|
+
const form = useAppForm({
|
|
82
|
+
defaultValues: {
|
|
83
|
+
name: organization?.name ?? "",
|
|
84
|
+
slug: organization?.slug ?? "",
|
|
85
|
+
logo: assetUrl(organization?.logo, authBaseUrl),
|
|
86
|
+
},
|
|
87
|
+
onSubmit: async ({ value }) => {
|
|
88
|
+
setError("");
|
|
89
|
+
try {
|
|
90
|
+
const logoFile = isFile(value.logo) ? value.logo : null;
|
|
91
|
+
const logo = logoFile
|
|
92
|
+
? await (async () => {
|
|
93
|
+
const payload = new FormData();
|
|
94
|
+
payload.append("file", logoFile);
|
|
95
|
+
return assetPath((await uploadLogo({ payload })).url);
|
|
96
|
+
})()
|
|
97
|
+
: assetPath(value.logo);
|
|
98
|
+
const payload = valuesToPayload(value, logo);
|
|
99
|
+
const saved = organization
|
|
100
|
+
? await updateOrganization({
|
|
101
|
+
params: { id: organization.id },
|
|
102
|
+
payload,
|
|
103
|
+
})
|
|
104
|
+
: await createOrganization({ payload });
|
|
105
|
+
toast.success(organization
|
|
106
|
+
? m.organization_updated_toast
|
|
107
|
+
: m.organization_created_toast);
|
|
108
|
+
onSaved(saved);
|
|
109
|
+
onClose();
|
|
110
|
+
}
|
|
111
|
+
catch (cause) {
|
|
112
|
+
setError(cause instanceof Error
|
|
113
|
+
? cause.message
|
|
114
|
+
: organization
|
|
115
|
+
? m.organization_update_error
|
|
116
|
+
: m.organization_create_error);
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
return (_jsx(Dialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(DialogContent, { className: "max-h-[90vh] overflow-y-auto sm:max-w-2xl", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEditing
|
|
121
|
+
? m.organization_edit_title
|
|
122
|
+
: m.organization_create_title }), _jsx(DialogDescription, { children: isEditing
|
|
123
|
+
? text(m.admin_organization_edit_description, {
|
|
124
|
+
name: organization?.name ?? "",
|
|
125
|
+
})
|
|
126
|
+
: m.organization_create_description })] }), _jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
event.stopPropagation();
|
|
129
|
+
form.handleSubmit();
|
|
130
|
+
}, children: [_jsx(form.AppField, { name: "name", children: (field) => _jsx(field.TextField, { label: m.field_name, autoFocus: true }) }), _jsx(form.AppField, { name: "slug", children: (field) => (_jsx(field.TextField, { label: m.organization_slug, description: m.organization_slug_description })) }), _jsx(form.AppField, { name: "logo", children: (field) => (_jsx(field.ImageField, { label: m.organization_field_logo_url, size: {
|
|
131
|
+
width: 96,
|
|
132
|
+
height: 96,
|
|
133
|
+
suggestedWidth: 512,
|
|
134
|
+
suggestedHeight: 512,
|
|
135
|
+
} })) }), _jsx(form.FormError, {}), error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(form.Subscribe, { selector: (state) => state.isSubmitting, children: (isSubmitting) => (_jsxs(Button, { disabled: isSubmitting, type: "submit", className: "self-start", children: [isSubmitting ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, m.form_submit] })) })] }) })] }) }));
|
|
136
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ValidateFromPath } from "@tanstack/react-router";
|
|
2
|
+
import { type TableParams } from "@/components/ui/data-table";
|
|
3
|
+
export declare function AdminOrganizationsTable({ from, reloadKey, search, }: {
|
|
4
|
+
from?: ValidateFromPath;
|
|
5
|
+
reloadKey?: number;
|
|
6
|
+
search: TableParams;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { useAtomValue } from "@effect/atom-react";
|
|
4
|
+
import {} from "@tanstack/react-table";
|
|
5
|
+
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
6
|
+
import { Building2 } from "lucide-react";
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import { DataTable } from "@/components/ui/data-table";
|
|
9
|
+
import { ErrorMessage } from "@/components/ui/form";
|
|
10
|
+
import { AppBrand } from "@/components/ui/app-brand";
|
|
11
|
+
import { Badge } from "@/components/ui/badge";
|
|
12
|
+
import { assetUrl } from "@/lib/assets";
|
|
13
|
+
import { authBaseUrl } from "@/services/auth/client";
|
|
14
|
+
import { organizationBranding } from "@/services/organizations/branding";
|
|
15
|
+
import { AdminApiClient } from "@/lib/admin-api-client";
|
|
16
|
+
import { useKrakstackAuth } from "./auth-provider";
|
|
17
|
+
const defaultMessages = {
|
|
18
|
+
en: {
|
|
19
|
+
admin_column_created: "Created",
|
|
20
|
+
admin_column_organization: "Organization",
|
|
21
|
+
admin_none: "None",
|
|
22
|
+
oauth_client_logo_configured: "Configured",
|
|
23
|
+
organization_fetch_error: "Unable to load organizations.",
|
|
24
|
+
organization_field_logo_url: "Logo",
|
|
25
|
+
},
|
|
26
|
+
fr: {
|
|
27
|
+
admin_column_created: "Créé",
|
|
28
|
+
admin_column_organization: "Organisation",
|
|
29
|
+
admin_none: "Aucun",
|
|
30
|
+
oauth_client_logo_configured: "Configuré",
|
|
31
|
+
organization_fetch_error: "Impossible de charger les organisations.",
|
|
32
|
+
organization_field_logo_url: "Logo",
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const labels = (locale) => ({
|
|
36
|
+
...defaultMessages[locale],
|
|
37
|
+
});
|
|
38
|
+
const organizationDisplay = (organization, locale) => {
|
|
39
|
+
const branding = organizationBranding(organization, locale);
|
|
40
|
+
return {
|
|
41
|
+
name: branding?.name ?? organization.name,
|
|
42
|
+
image: assetUrl(branding?.logo, authBaseUrl),
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const organizationsQuery = (search, projectId) => {
|
|
46
|
+
const query = {
|
|
47
|
+
page: search.page ?? 0,
|
|
48
|
+
pageSize: search.pageSize ?? 10,
|
|
49
|
+
...(search.globalFilter ? { globalFilter: search.globalFilter } : {}),
|
|
50
|
+
...(search.sort ? { sort: search.sort } : {}),
|
|
51
|
+
...(projectId ? { projectId } : {}),
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
query,
|
|
55
|
+
key: JSON.stringify(query),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const organizationsAtom = Atom.family(({ projectId, reloadKey, search, }) => {
|
|
59
|
+
const request = organizationsQuery(search, projectId);
|
|
60
|
+
return AdminApiClient.query("admin", "listOrganizations", {
|
|
61
|
+
query: request.query,
|
|
62
|
+
timeToLive: "1 minute",
|
|
63
|
+
reactivityKeys: [
|
|
64
|
+
"organizations",
|
|
65
|
+
...(projectId ? [`project:${projectId}`] : []),
|
|
66
|
+
],
|
|
67
|
+
serializationKey: `organizations:${reloadKey}:${request.key}`,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
71
|
+
const auth = useKrakstackAuth();
|
|
72
|
+
const locale = auth?.locale ?? "en";
|
|
73
|
+
const m = labels(locale);
|
|
74
|
+
const projectId = auth?.projectId;
|
|
75
|
+
const [refreshKey, setRefreshKey] = useState(0);
|
|
76
|
+
const result = useAtomValue(organizationsAtom({ projectId, reloadKey: reloadKey + refreshKey, search }));
|
|
77
|
+
const organizations = AsyncResult.match(result, {
|
|
78
|
+
onInitial: () => [],
|
|
79
|
+
onFailure: () => [],
|
|
80
|
+
onSuccess: ({ value }) => Array.from(value.data),
|
|
81
|
+
});
|
|
82
|
+
const total = AsyncResult.match(result, {
|
|
83
|
+
onInitial: () => 0,
|
|
84
|
+
onFailure: () => 0,
|
|
85
|
+
onSuccess: ({ value }) => value.meta.total,
|
|
86
|
+
});
|
|
87
|
+
const error = AsyncResult.match(result, {
|
|
88
|
+
onInitial: () => "",
|
|
89
|
+
onFailure: () => m.organization_fetch_error,
|
|
90
|
+
onSuccess: () => "",
|
|
91
|
+
});
|
|
92
|
+
const isLoading = AsyncResult.match(result, {
|
|
93
|
+
onInitial: () => true,
|
|
94
|
+
onFailure: () => false,
|
|
95
|
+
onSuccess: () => false,
|
|
96
|
+
});
|
|
97
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale), data: organizations, exportFileName: "organizations.csv", features: { gallery: false }, ...(from ? { from } : {}), isLoading: isLoading, onRefresh: () => setRefreshKey((current) => current + 1), serverPagination: { rowCount: total } })] }));
|
|
98
|
+
}
|
|
99
|
+
const organizationColumns = (m, locale) => [
|
|
100
|
+
{
|
|
101
|
+
accessorKey: "name",
|
|
102
|
+
header: m.admin_column_organization,
|
|
103
|
+
cell: ({ row }) => {
|
|
104
|
+
const display = organizationDisplay(row.original, locale);
|
|
105
|
+
return (_jsx(AppBrand, { to: null, label: display.name, subtitle: row.original.slug, icon: Building2, className: "min-w-56", ...(display.image ? { imageSrc: display.image } : {}) }));
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
accessorKey: "logo",
|
|
110
|
+
header: m.organization_field_logo_url,
|
|
111
|
+
cell: ({ row }) => row.original.logo ? (_jsx(Badge, { variant: "outline", children: m.oauth_client_logo_configured })) : (_jsx("span", { className: "text-muted-foreground text-sm", children: m.admin_none })),
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
accessorKey: "createdAt",
|
|
115
|
+
header: m.admin_column_created,
|
|
116
|
+
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(row.original.createdAt).toLocaleDateString() })),
|
|
117
|
+
},
|
|
118
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ValidateFromPath } from "@tanstack/react-router";
|
|
2
|
+
import { type TableParams } from "@/components/ui/data-table";
|
|
3
|
+
export declare function AdminUsersTable({ from, reloadKey, search, }: {
|
|
4
|
+
from?: ValidateFromPath;
|
|
5
|
+
reloadKey?: number;
|
|
6
|
+
search: TableParams;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
8
|
+
export declare function useAdminUsersTotal(search: TableParams): unknown;
|