@krak-stack/auth 0.1.51 → 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 +17 -1
- package/dist/components/auth-client.js +15 -1
- package/dist/components/auth-forms.d.ts +1 -0
- package/dist/components/auth-forms.js +309 -252
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/organization-switcher.d.ts +18 -7
- package/dist/components/organization-switcher.js +264 -189
- package/dist/components/user-button.js +197 -178
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- 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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { useAtomSubscribe, useAtomValue } from "@effect/atom-react";
|
|
3
|
+
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
|
+
import { Effect, Schema } from "effect";
|
|
5
|
+
import { AsyncResult, Atom } from "effect/unstable/reactivity";
|
|
5
6
|
import { useState } from "react";
|
|
6
7
|
import { toast } from "sonner";
|
|
7
|
-
import {
|
|
8
|
-
import { Button } from "@/components/ui/button";
|
|
8
|
+
import { ImageField, SingleSearchableSelectField, SubmitButton, SubmitError, TextField, } from "@/components/ui/effect-form";
|
|
9
9
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
|
|
10
10
|
import { AdminCreateOrganizationPayload, } from "../admin/schema";
|
|
11
11
|
import { authClientApi } from "./auth-client-api";
|
|
@@ -22,6 +22,11 @@ const defaultMessages = {
|
|
|
22
22
|
organization_created_toast: "Organization created.",
|
|
23
23
|
organization_edit_title: "Edit organization",
|
|
24
24
|
organization_field_logo_url: "Logo",
|
|
25
|
+
organization_parent: "Parent organization",
|
|
26
|
+
organization_parent_description: "Optionally group this organization under another organization.",
|
|
27
|
+
organization_parent_empty: "No organizations found.",
|
|
28
|
+
organization_parent_none: "No parent organization",
|
|
29
|
+
organization_parent_search: "Search organizations...",
|
|
25
30
|
organization_slug: "Slug",
|
|
26
31
|
organization_slug_description: "Leave blank to generate one from the name.",
|
|
27
32
|
organization_update_error: "Unable to update organization.",
|
|
@@ -37,89 +42,125 @@ const defaultMessages = {
|
|
|
37
42
|
organization_created_toast: "Organisation créée.",
|
|
38
43
|
organization_edit_title: "Modifier l'organisation",
|
|
39
44
|
organization_field_logo_url: "Logo",
|
|
45
|
+
organization_parent: "Organisation parente",
|
|
46
|
+
organization_parent_description: "Regroupez facultativement cette organisation sous une autre organisation.",
|
|
47
|
+
organization_parent_empty: "Aucune organisation trouvée.",
|
|
48
|
+
organization_parent_none: "Aucune organisation parente",
|
|
49
|
+
organization_parent_search: "Rechercher des organisations...",
|
|
40
50
|
organization_slug: "Slug",
|
|
41
51
|
organization_slug_description: "Laissez vide pour en générer un à partir du nom.",
|
|
42
52
|
organization_update_error: "Impossible de mettre à jour l'organisation.",
|
|
43
53
|
organization_updated_toast: "Organisation mise à jour.",
|
|
44
54
|
},
|
|
45
55
|
};
|
|
46
|
-
const labels = (locale) =>
|
|
47
|
-
...defaultMessages[locale],
|
|
48
|
-
});
|
|
56
|
+
const labels = (locale) => defaultMessages[locale];
|
|
49
57
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
58
|
+
const noParentOrganization = "__none__";
|
|
59
|
+
const organizationOptionsAtom = Atom.family((baseUrl) => authClientApi(baseUrl).query("admin", "listOrganizations", {
|
|
60
|
+
query: { page: 0, pageSize: 100 },
|
|
61
|
+
timeToLive: "1 minute",
|
|
62
|
+
reactivityKeys: ["organizations"],
|
|
63
|
+
}));
|
|
64
|
+
const createOrganizationAtom = Atom.family((baseUrl) => authClientApi(baseUrl).mutation("admin", "createOrganization"));
|
|
65
|
+
const updateOrganizationAtom = Atom.family((baseUrl) => authClientApi(baseUrl).mutation("admin", "updateOrganization"));
|
|
66
|
+
const uploadOrganizationLogoAtom = Atom.family((baseUrl) => authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"));
|
|
50
67
|
const slugify = (value) => value
|
|
51
68
|
.trim()
|
|
52
69
|
.toLowerCase()
|
|
53
70
|
.replace(/[^a-z0-9]+/g, "-")
|
|
54
71
|
.replace(/^-+|-+$/g, "");
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
72
|
+
const organizationFormBuilder = FormBuilder.empty
|
|
73
|
+
.addField("name", Schema.NonEmptyString)
|
|
74
|
+
.addField("slug", Schema.String)
|
|
75
|
+
.addField("logo", Schema.UndefinedOr(Schema.NullOr(Schema.Union([Schema.String, Schema.instanceOf(File)]))))
|
|
76
|
+
.addField("parentId", Schema.String);
|
|
77
|
+
const makeOrganizationForm = ({ baseUrl, organization, }) => FormReact.make(organizationFormBuilder, {
|
|
78
|
+
fields: {
|
|
79
|
+
name: TextField,
|
|
80
|
+
slug: TextField,
|
|
81
|
+
logo: ImageField,
|
|
82
|
+
parentId: SingleSearchableSelectField,
|
|
83
|
+
},
|
|
84
|
+
mode: { validation: "onSubmit" },
|
|
85
|
+
onSubmit: (_, { decoded, get }) => Effect.gen(function* () {
|
|
86
|
+
const logoValue = decoded.logo;
|
|
87
|
+
let logo = assetPath(logoValue instanceof File ? null : logoValue);
|
|
88
|
+
if (logoValue instanceof File) {
|
|
89
|
+
const payload = new FormData();
|
|
90
|
+
payload.append("file", logoValue);
|
|
91
|
+
const uploaded = yield* get.setResult(uploadOrganizationLogoAtom(baseUrl), { payload });
|
|
92
|
+
logo = assetPath(uploaded.url);
|
|
93
|
+
}
|
|
94
|
+
const payload = Schema.decodeUnknownSync(AdminCreateOrganizationPayload)({
|
|
95
|
+
name: decoded.name.trim(),
|
|
96
|
+
slug: slugify(decoded.slug || decoded.name),
|
|
97
|
+
logo: logo ?? undefined,
|
|
98
|
+
...(decoded.parentId === noParentOrganization
|
|
99
|
+
? {}
|
|
100
|
+
: { parentId: decoded.parentId }),
|
|
101
|
+
});
|
|
102
|
+
const saved = organization
|
|
103
|
+
? yield* get.setResult(updateOrganizationAtom(baseUrl), {
|
|
104
|
+
params: { id: organization.id },
|
|
105
|
+
payload: {
|
|
106
|
+
...payload,
|
|
107
|
+
parentId: decoded.parentId === noParentOrganization
|
|
108
|
+
? null
|
|
109
|
+
: decoded.parentId,
|
|
110
|
+
},
|
|
111
|
+
})
|
|
112
|
+
: yield* get.setResult(createOrganizationAtom(baseUrl), { payload });
|
|
113
|
+
return saved;
|
|
114
|
+
}),
|
|
60
115
|
});
|
|
61
116
|
export function AdminOrganizationForm({ organization, onClose, onSaved, }) {
|
|
62
117
|
const auth = useKrakstackAuth();
|
|
63
118
|
const m = labels(auth?.locale ?? "en");
|
|
64
119
|
const baseUrl = auth?.baseUrl;
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
? await (async () => {
|
|
82
|
-
const payload = new FormData();
|
|
83
|
-
payload.append("file", logoFile);
|
|
84
|
-
return assetPath((await uploadLogo({ payload })).url);
|
|
85
|
-
})()
|
|
86
|
-
: assetPath(value.logo);
|
|
87
|
-
const payload = valuesToPayload(value, logo);
|
|
88
|
-
const saved = organization
|
|
89
|
-
? await updateOrganization({
|
|
90
|
-
params: { id: organization.id },
|
|
91
|
-
payload,
|
|
92
|
-
})
|
|
93
|
-
: await createOrganization({ payload });
|
|
94
|
-
toast.success(organization
|
|
95
|
-
? m.organization_updated_toast
|
|
96
|
-
: m.organization_created_toast);
|
|
97
|
-
onSaved(saved);
|
|
98
|
-
onClose();
|
|
99
|
-
}
|
|
100
|
-
catch (cause) {
|
|
101
|
-
setError(cause instanceof Error
|
|
102
|
-
? cause.message
|
|
103
|
-
: organization
|
|
104
|
-
? m.organization_update_error
|
|
105
|
-
: m.organization_create_error);
|
|
106
|
-
}
|
|
107
|
-
},
|
|
120
|
+
const organizationsResult = useAtomValue(organizationOptionsAtom(baseUrl));
|
|
121
|
+
const organizations = AsyncResult.match(organizationsResult, {
|
|
122
|
+
onInitial: () => [],
|
|
123
|
+
onFailure: () => [],
|
|
124
|
+
onSuccess: ({ value }) => Array.from(value.data),
|
|
125
|
+
});
|
|
126
|
+
const [form] = useState(() => makeOrganizationForm({ baseUrl, organization }));
|
|
127
|
+
const submitResult = useAtomValue(form.submit);
|
|
128
|
+
useAtomSubscribe(form.submit, (result) => {
|
|
129
|
+
if (!AsyncResult.isSuccess(result))
|
|
130
|
+
return;
|
|
131
|
+
toast.success(organization
|
|
132
|
+
? m.organization_updated_toast
|
|
133
|
+
: m.organization_created_toast);
|
|
134
|
+
onSaved(result.value);
|
|
135
|
+
onClose();
|
|
108
136
|
});
|
|
109
|
-
|
|
137
|
+
const parentOptions = [
|
|
138
|
+
{ label: m.organization_parent_none, value: noParentOrganization },
|
|
139
|
+
...organizations
|
|
140
|
+
.filter((candidate) => candidate.id !== organization?.id &&
|
|
141
|
+
!candidate.userId &&
|
|
142
|
+
!candidate.parentId)
|
|
143
|
+
.map((candidate) => ({
|
|
144
|
+
label: candidate.name,
|
|
145
|
+
value: candidate.id,
|
|
146
|
+
data: candidate,
|
|
147
|
+
})),
|
|
148
|
+
];
|
|
149
|
+
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: organization
|
|
110
150
|
? m.organization_edit_title
|
|
111
|
-
: m.organization_create_title }), _jsx(DialogDescription, { children:
|
|
151
|
+
: m.organization_create_title }), _jsx(DialogDescription, { children: organization
|
|
112
152
|
? text(m.admin_organization_edit_description, {
|
|
113
|
-
name: organization
|
|
153
|
+
name: organization.name,
|
|
114
154
|
})
|
|
115
|
-
: m.organization_create_description })] }), _jsx(form.
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
155
|
+
: m.organization_create_description })] }), _jsx(form.Initialize, { defaultValues: {
|
|
156
|
+
name: organization?.name ?? "",
|
|
157
|
+
slug: organization?.slug ?? "",
|
|
158
|
+
logo: assetUrl(organization?.logo, baseUrl),
|
|
159
|
+
parentId: organization?.parentId ?? noParentOrganization,
|
|
160
|
+
}, children: _jsxs("div", { className: "flex flex-col gap-4", children: [_jsx(form.name, { autoFocus: true, label: m.field_name }), _jsx(form.slug, { description: m.organization_slug_description, label: m.organization_slug }), _jsx(form.logo, { label: m.organization_field_logo_url, size: {
|
|
161
|
+
width: 96,
|
|
162
|
+
height: 96,
|
|
163
|
+
suggestedWidth: 512,
|
|
164
|
+
suggestedHeight: 512,
|
|
165
|
+
} }), _jsx(form.parentId, { description: m.organization_parent_description, emptyLabel: m.organization_parent_empty, items: parentOptions, label: m.organization_parent, messages: { search: m.organization_parent_search }, placeholder: m.organization_parent_none }), _jsx(SubmitError, { result: submitResult }), _jsx(SubmitButton, { form: form, children: m.form_submit })] }) })] }) }));
|
|
125
166
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useAtomValue } from "@effect/atom-react";
|
|
2
|
+
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import {} from "@tanstack/react-table";
|
|
4
4
|
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
5
|
-
import { Building2 } from "lucide-react";
|
|
5
|
+
import { Building2, Pencil, Trash2 } from "lucide-react";
|
|
6
6
|
import { useState } from "react";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { toast } from "sonner";
|
|
8
|
+
import { DataTable, DataTableListSummary, } from "@/components/ui/data-table";
|
|
9
|
+
import { ErrorMessage } from "@/components/ui/effect-form";
|
|
9
10
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
11
|
+
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
12
|
+
import { AdminOrganizationForm } from "./admin-organization-form";
|
|
10
13
|
import { authClientApi } from "./auth-client-api";
|
|
11
14
|
import { useKrakstackAuth } from "./auth-provider";
|
|
12
15
|
import { assetUrl, organizationBranding } from "./utils";
|
|
@@ -15,12 +18,30 @@ const defaultMessages = {
|
|
|
15
18
|
admin_column_created: "Created",
|
|
16
19
|
admin_column_members: "Members",
|
|
17
20
|
admin_column_organization: "Organization",
|
|
21
|
+
admin_column_projects: "Projects",
|
|
22
|
+
organization_action_delete: "Delete organization",
|
|
23
|
+
organization_action_edit: "Edit organization",
|
|
24
|
+
organization_delete_cancel: "Cancel",
|
|
25
|
+
organization_delete_confirm: "Delete",
|
|
26
|
+
organization_delete_description: "Are you sure you want to delete {name}? This action cannot be undone.",
|
|
27
|
+
organization_delete_error: "Unable to delete organization.",
|
|
28
|
+
organization_delete_title: "Delete organization",
|
|
29
|
+
organization_deleted_toast: "Organization deleted.",
|
|
18
30
|
organization_fetch_error: "Unable to load organizations.",
|
|
19
31
|
},
|
|
20
32
|
fr: {
|
|
21
33
|
admin_column_created: "Créé",
|
|
22
34
|
admin_column_members: "Membres",
|
|
23
35
|
admin_column_organization: "Organisation",
|
|
36
|
+
admin_column_projects: "Projets",
|
|
37
|
+
organization_action_delete: "Supprimer l'organisation",
|
|
38
|
+
organization_action_edit: "Modifier l'organisation",
|
|
39
|
+
organization_delete_cancel: "Annuler",
|
|
40
|
+
organization_delete_confirm: "Supprimer",
|
|
41
|
+
organization_delete_description: "Êtes-vous sûr de vouloir supprimer {name} ? Cette action est irréversible.",
|
|
42
|
+
organization_delete_error: "Impossible de supprimer l'organisation.",
|
|
43
|
+
organization_delete_title: "Supprimer l'organisation",
|
|
44
|
+
organization_deleted_toast: "Organisation supprimée.",
|
|
24
45
|
organization_fetch_error: "Impossible de charger les organisations.",
|
|
25
46
|
},
|
|
26
47
|
};
|
|
@@ -66,6 +87,8 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
66
87
|
const baseUrl = auth?.baseUrl;
|
|
67
88
|
const projectId = auth?.projectId;
|
|
68
89
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
90
|
+
const [editingOrganization, setEditingOrganization] = useState(null);
|
|
91
|
+
const [deletingOrganization, setDeletingOrganization] = useState(null);
|
|
69
92
|
const [localSearch, setLocalSearch] = useState({
|
|
70
93
|
globalFilter: "",
|
|
71
94
|
});
|
|
@@ -76,6 +99,7 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
76
99
|
reloadKey: reloadKey + refreshKey,
|
|
77
100
|
search: tableSearch,
|
|
78
101
|
}));
|
|
102
|
+
const deleteOrganization = useAtomSet(authClientApi(baseUrl).mutation("admin", "deleteOrganization"), { mode: "promise" });
|
|
79
103
|
const organizations = AsyncResult.match(result, {
|
|
80
104
|
onInitial: () => [],
|
|
81
105
|
onFailure: () => [],
|
|
@@ -100,13 +124,36 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
100
124
|
export: { baseName: "organizations" },
|
|
101
125
|
gallery: false,
|
|
102
126
|
pagination: { mode: "server", rowCount: total },
|
|
127
|
+
rowActions: {
|
|
128
|
+
items: [
|
|
129
|
+
{
|
|
130
|
+
name: m.organization_action_edit,
|
|
131
|
+
icon: _jsx(Pencil, { className: "size-4" }),
|
|
132
|
+
onClick: setEditingOrganization,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: m.organization_action_delete,
|
|
136
|
+
icon: _jsx(Trash2, { className: "size-4" }),
|
|
137
|
+
variant: "destructive",
|
|
138
|
+
onClick: setDeletingOrganization,
|
|
139
|
+
visible: (organization) => !organization.userId,
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
},
|
|
103
143
|
}, ...(from ? { routeFrom: from } : {}), ...(!search
|
|
104
144
|
? {
|
|
105
145
|
search: tableSearch,
|
|
106
146
|
onSearchChange: setLocalSearch,
|
|
107
147
|
searchState: "local",
|
|
108
148
|
}
|
|
109
|
-
: {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { loading: isLoading } })
|
|
149
|
+
: {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { loading: isLoading } }), editingOrganization ? (_jsx(AdminOrganizationForm, { organization: editingOrganization, onClose: () => setEditingOrganization(null), onSaved: () => setRefreshKey((current) => current + 1) })) : null, deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, onClose: () => setDeletingOrganization(null), onDelete: async () => {
|
|
150
|
+
await deleteOrganization({
|
|
151
|
+
params: { id: deletingOrganization.id },
|
|
152
|
+
});
|
|
153
|
+
toast.success(m.organization_deleted_toast);
|
|
154
|
+
setDeletingOrganization(null);
|
|
155
|
+
setRefreshKey((current) => current + 1);
|
|
156
|
+
} })) : null] }));
|
|
110
157
|
}
|
|
111
158
|
const organizationColumns = (m, locale, baseUrl) => [
|
|
112
159
|
{
|
|
@@ -120,7 +167,19 @@ const organizationColumns = (m, locale, baseUrl) => [
|
|
|
120
167
|
{
|
|
121
168
|
accessorKey: "memberCount",
|
|
122
169
|
header: m.admin_column_members,
|
|
123
|
-
cell: ({ row }) => (_jsx(
|
|
170
|
+
cell: ({ row }) => (_jsx(OrganizationMembers, { baseUrl: baseUrl, members: row.original.memberPreviews ?? [], total: row.original.memberCount ?? 0 })),
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
accessorKey: "projects",
|
|
174
|
+
header: m.admin_column_projects,
|
|
175
|
+
cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: (row.original.projects ?? []).map((project) => {
|
|
176
|
+
const logo = assetUrl(project.logo, baseUrl);
|
|
177
|
+
return {
|
|
178
|
+
label: project.name,
|
|
179
|
+
value: project.id,
|
|
180
|
+
icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
|
|
181
|
+
};
|
|
182
|
+
}), variant: "icon" })),
|
|
124
183
|
},
|
|
125
184
|
{
|
|
126
185
|
accessorKey: "createdAt",
|
|
@@ -128,3 +187,37 @@ const organizationColumns = (m, locale, baseUrl) => [
|
|
|
128
187
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(row.original.createdAt).toLocaleDateString() })),
|
|
129
188
|
},
|
|
130
189
|
];
|
|
190
|
+
const initials = (name) => name
|
|
191
|
+
.split(/\s+/)
|
|
192
|
+
.slice(0, 2)
|
|
193
|
+
.map((part) => part[0])
|
|
194
|
+
.join("")
|
|
195
|
+
.toUpperCase();
|
|
196
|
+
function OrganizationMembers({ baseUrl, members, total, }) {
|
|
197
|
+
return (_jsx(DataTableListSummary, { emptyLabel: "0", items: members.map((member) => {
|
|
198
|
+
const image = assetUrl(member.image, baseUrl);
|
|
199
|
+
return {
|
|
200
|
+
label: member.name,
|
|
201
|
+
value: member.id,
|
|
202
|
+
icon: image ? (_jsx("img", { alt: "", className: "size-full object-cover", src: image })) : (initials(member.name)),
|
|
203
|
+
};
|
|
204
|
+
}), totalCount: total, variant: "icon" }));
|
|
205
|
+
}
|
|
206
|
+
function DeleteOrganizationDialog({ labels: m, organization, onClose, onDelete, }) {
|
|
207
|
+
const [error, setError] = useState("");
|
|
208
|
+
const [isPending, setIsPending] = useState(false);
|
|
209
|
+
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.organization_delete_title }), _jsx(AlertDialogDescription, { children: m.organization_delete_description.replace("{name}", organization.name) })] }), error ? _jsx(ErrorMessage, { text: error }) : null, _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: isPending, children: m.organization_delete_cancel }), _jsx(AlertDialogAction, { disabled: isPending, onClick: async (event) => {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
setError("");
|
|
212
|
+
setIsPending(true);
|
|
213
|
+
try {
|
|
214
|
+
await onDelete();
|
|
215
|
+
}
|
|
216
|
+
catch (cause) {
|
|
217
|
+
setError(cause instanceof Error
|
|
218
|
+
? cause.message
|
|
219
|
+
: m.organization_delete_error);
|
|
220
|
+
setIsPending(false);
|
|
221
|
+
}
|
|
222
|
+
}, children: m.organization_delete_confirm })] })] }) }));
|
|
223
|
+
}
|
|
@@ -5,8 +5,8 @@ import {} from "@tanstack/react-table";
|
|
|
5
5
|
import { Atom, AsyncResult } from "effect/unstable/reactivity";
|
|
6
6
|
import { Ban, Building2, Loader2, ShieldOff, UserCog, UserIcon, } from "lucide-react";
|
|
7
7
|
import { useState } from "react";
|
|
8
|
-
import { DataTable } from "@/components/ui/data-table";
|
|
9
|
-
import { ErrorMessage } from "@/components/ui/form";
|
|
8
|
+
import { DataTable, DataTableListSummary, } from "@/components/ui/data-table";
|
|
9
|
+
import { ErrorMessage } from "@/components/ui/effect-form";
|
|
10
10
|
import { AppBrand } from "@/components/ui/app-brand";
|
|
11
11
|
import { Badge } from "@/components/ui/badge";
|
|
12
12
|
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog";
|
|
@@ -23,6 +23,8 @@ const defaultMessages = {
|
|
|
23
23
|
admin_ban_title: "Ban user",
|
|
24
24
|
admin_column_created: "Created",
|
|
25
25
|
admin_column_last_signed_in: "Last signed in",
|
|
26
|
+
admin_column_organizations: "Organizations",
|
|
27
|
+
admin_column_projects: "Projects",
|
|
26
28
|
admin_column_role: "Role",
|
|
27
29
|
admin_column_status: "Status",
|
|
28
30
|
admin_column_unverified: "Unverified",
|
|
@@ -50,6 +52,8 @@ const defaultMessages = {
|
|
|
50
52
|
admin_ban_title: "Bannir l'utilisateur",
|
|
51
53
|
admin_column_created: "Créé",
|
|
52
54
|
admin_column_last_signed_in: "Dernière connexion",
|
|
55
|
+
admin_column_organizations: "Organisations",
|
|
56
|
+
admin_column_projects: "Projets",
|
|
53
57
|
admin_column_role: "Rôle",
|
|
54
58
|
admin_column_status: "Statut",
|
|
55
59
|
admin_column_unverified: "Non vérifié",
|
|
@@ -72,6 +76,12 @@ const defaultMessages = {
|
|
|
72
76
|
const labels = (locale) => ({
|
|
73
77
|
...defaultMessages[locale],
|
|
74
78
|
});
|
|
79
|
+
const initials = (name) => name
|
|
80
|
+
.split(/\s+/)
|
|
81
|
+
.slice(0, 2)
|
|
82
|
+
.map((part) => part[0])
|
|
83
|
+
.join("")
|
|
84
|
+
.toUpperCase();
|
|
75
85
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
76
86
|
const adminUsersQuery = (search, projectId) => {
|
|
77
87
|
const query = {
|
|
@@ -171,7 +181,7 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
171
181
|
await navigate({ to: "/" });
|
|
172
182
|
await router.invalidate();
|
|
173
183
|
};
|
|
174
|
-
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m), data: users, features: {
|
|
184
|
+
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m, baseUrl), data: users, features: {
|
|
175
185
|
export: { baseName: "users" },
|
|
176
186
|
gallery: false,
|
|
177
187
|
pagination: { mode: "server", rowCount: total },
|
|
@@ -271,7 +281,7 @@ export function useAdminUsersTotal(search) {
|
|
|
271
281
|
onSuccess: ({ value }) => value.meta.total,
|
|
272
282
|
});
|
|
273
283
|
}
|
|
274
|
-
const userColumns = (m) => [
|
|
284
|
+
const userColumns = (m, baseUrl) => [
|
|
275
285
|
{
|
|
276
286
|
accessorKey: "email",
|
|
277
287
|
header: m.admin_column_user,
|
|
@@ -280,6 +290,30 @@ const userColumns = (m) => [
|
|
|
280
290
|
return (_jsx(AppBrand, { to: null, label: row.original.email, subtitle: row.original.name, icon: UserIcon, className: "min-w-48", ...(image ? { imageSrc: image } : {}) }));
|
|
281
291
|
},
|
|
282
292
|
},
|
|
293
|
+
{
|
|
294
|
+
accessorKey: "organizations",
|
|
295
|
+
header: m.admin_column_organizations,
|
|
296
|
+
cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: row.original.organizations.map((organization) => {
|
|
297
|
+
const logo = assetUrl(organization.logo, baseUrl);
|
|
298
|
+
return {
|
|
299
|
+
label: organization.name,
|
|
300
|
+
value: organization.id,
|
|
301
|
+
icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(organization.name)),
|
|
302
|
+
};
|
|
303
|
+
}), variant: "icon" })),
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
accessorKey: "projects",
|
|
307
|
+
header: m.admin_column_projects,
|
|
308
|
+
cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: row.original.projects.map((project) => {
|
|
309
|
+
const logo = assetUrl(project.logo, baseUrl);
|
|
310
|
+
return {
|
|
311
|
+
label: project.name,
|
|
312
|
+
value: project.id,
|
|
313
|
+
icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
|
|
314
|
+
};
|
|
315
|
+
}), variant: "icon" })),
|
|
316
|
+
},
|
|
283
317
|
{
|
|
284
318
|
accessorKey: "emailVerified",
|
|
285
319
|
header: m.admin_column_verified,
|
|
@@ -24,13 +24,26 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
24
24
|
readonly name: import("effect/Schema").NonEmptyString;
|
|
25
25
|
readonly slug: import("effect/Schema").NonEmptyString;
|
|
26
26
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
27
|
+
readonly parentId: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
27
28
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
28
29
|
readonly id: import("effect/Schema").String;
|
|
29
30
|
readonly name: import("effect/Schema").String;
|
|
30
31
|
readonly slug: import("effect/Schema").String;
|
|
31
32
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
32
33
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
34
|
+
readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
35
|
+
readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
33
36
|
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
37
|
+
readonly memberPreviews: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
38
|
+
readonly id: import("effect/Schema").String;
|
|
39
|
+
readonly name: import("effect/Schema").String;
|
|
40
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
41
|
+
}>>>;
|
|
42
|
+
readonly projects: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
43
|
+
readonly id: import("effect/Schema").String;
|
|
44
|
+
readonly name: import("effect/Schema").String;
|
|
45
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
46
|
+
}>>>;
|
|
34
47
|
readonly createdAt: import("effect/Schema").Date;
|
|
35
48
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"dashboardStats", "GET", "/api/auth/admin/dashboard-stats", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
36
49
|
readonly days: import("effect/Schema").optional<import("effect/Schema").Union<readonly [import("effect/Schema").Literal<"7">, import("effect/Schema").Literal<"14">, import("effect/Schema").Literal<"30">, import("effect/Schema").Literal<"90">]>>;
|
|
@@ -100,7 +113,19 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
100
113
|
readonly slug: import("effect/Schema").String;
|
|
101
114
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
102
115
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
116
|
+
readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
117
|
+
readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
103
118
|
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
119
|
+
readonly memberPreviews: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
120
|
+
readonly id: import("effect/Schema").String;
|
|
121
|
+
readonly name: import("effect/Schema").String;
|
|
122
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
123
|
+
}>>>;
|
|
124
|
+
readonly projects: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
125
|
+
readonly id: import("effect/Schema").String;
|
|
126
|
+
readonly name: import("effect/Schema").String;
|
|
127
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
128
|
+
}>>>;
|
|
104
129
|
readonly createdAt: import("effect/Schema").Date;
|
|
105
130
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never> | import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"disableApiKeyRateLimit", "POST", "/api/auth/admin/api-keys/:id/disable-rate-limit", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<import("effect/Schema").Struct<{
|
|
106
131
|
readonly id: import("effect/Schema").String;
|
|
@@ -196,7 +221,19 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
196
221
|
readonly slug: string;
|
|
197
222
|
readonly logo?: string | null | undefined;
|
|
198
223
|
readonly metadata?: string | null | undefined;
|
|
224
|
+
readonly userId?: string | null | undefined;
|
|
225
|
+
readonly parentId?: string | null | undefined;
|
|
199
226
|
readonly memberCount?: number | undefined;
|
|
227
|
+
readonly memberPreviews?: readonly import("effect/Schema").Struct.ReadonlySide<{
|
|
228
|
+
readonly id: import("effect/Schema").String;
|
|
229
|
+
readonly name: import("effect/Schema").String;
|
|
230
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
231
|
+
}, "Type">[] | undefined;
|
|
232
|
+
readonly projects?: readonly import("effect/Schema").Struct.ReadonlySide<{
|
|
233
|
+
readonly id: import("effect/Schema").String;
|
|
234
|
+
readonly name: import("effect/Schema").String;
|
|
235
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
236
|
+
}, "Type">[] | undefined;
|
|
200
237
|
readonly createdAt: Date;
|
|
201
238
|
}>>;
|
|
202
239
|
readonly meta: import("effect/Schema").Struct<{
|
|
@@ -227,6 +264,16 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
227
264
|
readonly banned: import("effect/Schema").NullOr<import("effect/Schema").Boolean>;
|
|
228
265
|
readonly banReason: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
229
266
|
readonly banExpires: import("effect/Schema").NullOr<import("effect/Schema").Date>;
|
|
267
|
+
readonly organizations: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
268
|
+
readonly id: import("effect/Schema").String;
|
|
269
|
+
readonly name: import("effect/Schema").String;
|
|
270
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
271
|
+
}>>;
|
|
272
|
+
readonly projects: import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
273
|
+
readonly id: import("effect/Schema").String;
|
|
274
|
+
readonly name: import("effect/Schema").String;
|
|
275
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
276
|
+
}>>;
|
|
230
277
|
}, "Type">>>;
|
|
231
278
|
readonly meta: import("effect/Schema").Struct<{
|
|
232
279
|
readonly page: import("effect/Schema").Int;
|
|
@@ -307,13 +354,26 @@ export declare const authClientApi: (baseUrl?: string | undefined) => AtomHttpAp
|
|
|
307
354
|
readonly name: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
|
|
308
355
|
readonly slug: import("effect/Schema").optional<import("effect/Schema").NonEmptyString>;
|
|
309
356
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").String>;
|
|
357
|
+
readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
310
358
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").Struct<{
|
|
311
359
|
readonly id: import("effect/Schema").String;
|
|
312
360
|
readonly name: import("effect/Schema").String;
|
|
313
361
|
readonly slug: import("effect/Schema").String;
|
|
314
362
|
readonly logo: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
315
363
|
readonly metadata: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
364
|
+
readonly userId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
365
|
+
readonly parentId: import("effect/Schema").optional<import("effect/Schema").NullOr<import("effect/Schema").String>>;
|
|
316
366
|
readonly memberCount: import("effect/Schema").optional<import("effect/Schema").Number>;
|
|
367
|
+
readonly memberPreviews: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
368
|
+
readonly id: import("effect/Schema").String;
|
|
369
|
+
readonly name: import("effect/Schema").String;
|
|
370
|
+
readonly image: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
371
|
+
}>>>;
|
|
372
|
+
readonly projects: import("effect/Schema").optional<import("effect/Schema").$Array<import("effect/Schema").Struct<{
|
|
373
|
+
readonly id: import("effect/Schema").String;
|
|
374
|
+
readonly name: import("effect/Schema").String;
|
|
375
|
+
readonly logo: import("effect/Schema").NullOr<import("effect/Schema").String>;
|
|
376
|
+
}>>>;
|
|
317
377
|
readonly createdAt: import("effect/Schema").Date;
|
|
318
378
|
}>>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<typeof import("effect/unstable/httpapi/HttpApiError").Unauthorized | typeof import("effect/unstable/httpapi/HttpApiError").Forbidden | typeof import("effect/unstable/httpapi/HttpApiError").NotFound | typeof import("effect/unstable/httpapi/HttpApiError").InternalServerError>, never, never>, false> | import("effect/unstable/httpapi/HttpApiGroup").HttpApiGroup<"auth", import("effect/unstable/httpapi/HttpApiEndpoint").HttpApiEndpoint<"getSession", "GET", "/api/auth/get-session", import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").StringTree<never>, import("effect/unstable/httpapi/HttpApiEndpoint").Json<import("effect/Schema").NullOr<import("effect/Schema").Struct<{
|
|
319
379
|
readonly session: import("effect/Schema").Struct<{
|
|
@@ -10,13 +10,29 @@ declare const additionalFields: {
|
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
|
+
declare const organizationSchema: {
|
|
14
|
+
readonly organization: {
|
|
15
|
+
readonly additionalFields: {
|
|
16
|
+
readonly userId: {
|
|
17
|
+
readonly type: "string";
|
|
18
|
+
readonly required: false;
|
|
19
|
+
};
|
|
20
|
+
readonly parentId: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
readonly required: false;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
13
27
|
type AuthUiClientPlugins = [
|
|
14
28
|
ReturnType<typeof inferAdditionalFields<never, typeof additionalFields>>,
|
|
15
29
|
ReturnType<typeof adminClient<{}>>,
|
|
16
30
|
ReturnType<typeof anonymousClient>,
|
|
17
31
|
ReturnType<typeof emailOTPClient>,
|
|
18
32
|
ReturnType<typeof lastLoginMethodClient>,
|
|
19
|
-
ReturnType<typeof organizationClient<{
|
|
33
|
+
ReturnType<typeof organizationClient<{
|
|
34
|
+
schema: typeof organizationSchema;
|
|
35
|
+
}>>,
|
|
20
36
|
ReturnType<typeof twoFactorClient>,
|
|
21
37
|
ReturnType<typeof apiKeyClient>,
|
|
22
38
|
ReturnType<typeof genericOAuthClient>
|