@krak-stack/auth 0.1.52 → 0.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- 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 +82 -1
- package/dist/components/admin-organization-form.js +110 -69
- package/dist/components/admin-organizations.js +107 -7
- package/dist/components/admin-users.js +45 -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/index.d.ts +2 -2
- package/dist/components/organization-switcher.d.ts +15 -2
- package/dist/components/organization-switcher.js +250 -200
- package/dist/components/user-button.js +197 -178
- package/dist/index.d.ts +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,26 +1,49 @@
|
|
|
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";
|
|
13
16
|
const defaultMessages = {
|
|
14
17
|
en: {
|
|
15
18
|
admin_column_created: "Created",
|
|
19
|
+
admin_column_id: "ID",
|
|
16
20
|
admin_column_members: "Members",
|
|
17
21
|
admin_column_organization: "Organization",
|
|
22
|
+
admin_column_projects: "Projects",
|
|
23
|
+
organization_action_delete: "Delete organization",
|
|
24
|
+
organization_action_edit: "Edit organization",
|
|
25
|
+
organization_delete_cancel: "Cancel",
|
|
26
|
+
organization_delete_confirm: "Delete",
|
|
27
|
+
organization_delete_description: "Are you sure you want to delete {name}? This action cannot be undone.",
|
|
28
|
+
organization_delete_error: "Unable to delete organization.",
|
|
29
|
+
organization_delete_title: "Delete organization",
|
|
30
|
+
organization_deleted_toast: "Organization deleted.",
|
|
18
31
|
organization_fetch_error: "Unable to load organizations.",
|
|
19
32
|
},
|
|
20
33
|
fr: {
|
|
21
34
|
admin_column_created: "Créé",
|
|
35
|
+
admin_column_id: "ID",
|
|
22
36
|
admin_column_members: "Membres",
|
|
23
37
|
admin_column_organization: "Organisation",
|
|
38
|
+
admin_column_projects: "Projets",
|
|
39
|
+
organization_action_delete: "Supprimer l'organisation",
|
|
40
|
+
organization_action_edit: "Modifier l'organisation",
|
|
41
|
+
organization_delete_cancel: "Annuler",
|
|
42
|
+
organization_delete_confirm: "Supprimer",
|
|
43
|
+
organization_delete_description: "Êtes-vous sûr de vouloir supprimer {name} ? Cette action est irréversible.",
|
|
44
|
+
organization_delete_error: "Impossible de supprimer l'organisation.",
|
|
45
|
+
organization_delete_title: "Supprimer l'organisation",
|
|
46
|
+
organization_deleted_toast: "Organisation supprimée.",
|
|
24
47
|
organization_fetch_error: "Impossible de charger les organisations.",
|
|
25
48
|
},
|
|
26
49
|
};
|
|
@@ -66,6 +89,8 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
66
89
|
const baseUrl = auth?.baseUrl;
|
|
67
90
|
const projectId = auth?.projectId;
|
|
68
91
|
const [refreshKey, setRefreshKey] = useState(0);
|
|
92
|
+
const [editingOrganization, setEditingOrganization] = useState(null);
|
|
93
|
+
const [deletingOrganization, setDeletingOrganization] = useState(null);
|
|
69
94
|
const [localSearch, setLocalSearch] = useState({
|
|
70
95
|
globalFilter: "",
|
|
71
96
|
});
|
|
@@ -76,6 +101,7 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
76
101
|
reloadKey: reloadKey + refreshKey,
|
|
77
102
|
search: tableSearch,
|
|
78
103
|
}));
|
|
104
|
+
const deleteOrganization = useAtomSet(authClientApi(baseUrl).mutation("admin", "deleteOrganization"), { mode: "promise" });
|
|
79
105
|
const organizations = AsyncResult.match(result, {
|
|
80
106
|
onInitial: () => [],
|
|
81
107
|
onFailure: () => [],
|
|
@@ -96,19 +122,47 @@ export function AdminOrganizationsTable({ from, reloadKey = 0, search, }) {
|
|
|
96
122
|
onFailure: () => false,
|
|
97
123
|
onSuccess: () => false,
|
|
98
124
|
});
|
|
99
|
-
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, features: {
|
|
125
|
+
return (_jsxs("div", { className: "flex flex-col gap-4", children: [error ? _jsx(ErrorMessage, { text: error }) : null, _jsx(DataTable, { columns: organizationColumns(m, locale, baseUrl), data: organizations, defaultColumnVisibility: { id: false }, features: {
|
|
100
126
|
export: { baseName: "organizations" },
|
|
101
127
|
gallery: false,
|
|
102
128
|
pagination: { mode: "server", rowCount: total },
|
|
129
|
+
rowActions: {
|
|
130
|
+
items: [
|
|
131
|
+
{
|
|
132
|
+
name: m.organization_action_edit,
|
|
133
|
+
icon: _jsx(Pencil, { className: "size-4" }),
|
|
134
|
+
onClick: setEditingOrganization,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: m.organization_action_delete,
|
|
138
|
+
icon: _jsx(Trash2, { className: "size-4" }),
|
|
139
|
+
variant: "destructive",
|
|
140
|
+
onClick: setDeletingOrganization,
|
|
141
|
+
visible: (organization) => !organization.userId,
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
103
145
|
}, ...(from ? { routeFrom: from } : {}), ...(!search
|
|
104
146
|
? {
|
|
105
147
|
search: tableSearch,
|
|
106
148
|
onSearchChange: setLocalSearch,
|
|
107
149
|
searchState: "local",
|
|
108
150
|
}
|
|
109
|
-
: {}), onRefresh: () => setRefreshKey((current) => current + 1), state: { loading: isLoading } })
|
|
151
|
+
: {}), 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 () => {
|
|
152
|
+
await deleteOrganization({
|
|
153
|
+
params: { id: deletingOrganization.id },
|
|
154
|
+
});
|
|
155
|
+
toast.success(m.organization_deleted_toast);
|
|
156
|
+
setDeletingOrganization(null);
|
|
157
|
+
setRefreshKey((current) => current + 1);
|
|
158
|
+
} })) : null] }));
|
|
110
159
|
}
|
|
111
160
|
const organizationColumns = (m, locale, baseUrl) => [
|
|
161
|
+
{
|
|
162
|
+
accessorKey: "id",
|
|
163
|
+
header: m.admin_column_id,
|
|
164
|
+
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground font-mono text-xs", children: row.original.id })),
|
|
165
|
+
},
|
|
112
166
|
{
|
|
113
167
|
accessorKey: "name",
|
|
114
168
|
header: m.admin_column_organization,
|
|
@@ -120,7 +174,19 @@ const organizationColumns = (m, locale, baseUrl) => [
|
|
|
120
174
|
{
|
|
121
175
|
accessorKey: "memberCount",
|
|
122
176
|
header: m.admin_column_members,
|
|
123
|
-
cell: ({ row }) => (_jsx(
|
|
177
|
+
cell: ({ row }) => (_jsx(OrganizationMembers, { baseUrl: baseUrl, members: row.original.memberPreviews ?? [], total: row.original.memberCount ?? 0 })),
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
accessorKey: "projects",
|
|
181
|
+
header: m.admin_column_projects,
|
|
182
|
+
cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: (row.original.projects ?? []).map((project) => {
|
|
183
|
+
const logo = assetUrl(project.logo, baseUrl);
|
|
184
|
+
return {
|
|
185
|
+
label: project.name,
|
|
186
|
+
value: project.id,
|
|
187
|
+
icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
|
|
188
|
+
};
|
|
189
|
+
}), variant: "icon" })),
|
|
124
190
|
},
|
|
125
191
|
{
|
|
126
192
|
accessorKey: "createdAt",
|
|
@@ -128,3 +194,37 @@ const organizationColumns = (m, locale, baseUrl) => [
|
|
|
128
194
|
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground text-sm", children: new Date(row.original.createdAt).toLocaleDateString() })),
|
|
129
195
|
},
|
|
130
196
|
];
|
|
197
|
+
const initials = (name) => name
|
|
198
|
+
.split(/\s+/)
|
|
199
|
+
.slice(0, 2)
|
|
200
|
+
.map((part) => part[0])
|
|
201
|
+
.join("")
|
|
202
|
+
.toUpperCase();
|
|
203
|
+
function OrganizationMembers({ baseUrl, members, total, }) {
|
|
204
|
+
return (_jsx(DataTableListSummary, { emptyLabel: "0", items: members.map((member) => {
|
|
205
|
+
const image = assetUrl(member.image, baseUrl);
|
|
206
|
+
return {
|
|
207
|
+
label: member.name,
|
|
208
|
+
value: member.id,
|
|
209
|
+
icon: image ? (_jsx("img", { alt: "", className: "size-full object-cover", src: image })) : (initials(member.name)),
|
|
210
|
+
};
|
|
211
|
+
}), totalCount: total, variant: "icon" }));
|
|
212
|
+
}
|
|
213
|
+
function DeleteOrganizationDialog({ labels: m, organization, onClose, onDelete, }) {
|
|
214
|
+
const [error, setError] = useState("");
|
|
215
|
+
const [isPending, setIsPending] = useState(false);
|
|
216
|
+
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) => {
|
|
217
|
+
event.preventDefault();
|
|
218
|
+
setError("");
|
|
219
|
+
setIsPending(true);
|
|
220
|
+
try {
|
|
221
|
+
await onDelete();
|
|
222
|
+
}
|
|
223
|
+
catch (cause) {
|
|
224
|
+
setError(cause instanceof Error
|
|
225
|
+
? cause.message
|
|
226
|
+
: m.organization_delete_error);
|
|
227
|
+
setIsPending(false);
|
|
228
|
+
}
|
|
229
|
+
}, children: m.organization_delete_confirm })] })] }) }));
|
|
230
|
+
}
|
|
@@ -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";
|
|
@@ -22,7 +22,10 @@ const defaultMessages = {
|
|
|
22
22
|
admin_ban_description: "Are you sure you want to ban {name} ({email})? They will not be able to sign in.",
|
|
23
23
|
admin_ban_title: "Ban user",
|
|
24
24
|
admin_column_created: "Created",
|
|
25
|
+
admin_column_id: "ID",
|
|
25
26
|
admin_column_last_signed_in: "Last signed in",
|
|
27
|
+
admin_column_organizations: "Organizations",
|
|
28
|
+
admin_column_projects: "Projects",
|
|
26
29
|
admin_column_role: "Role",
|
|
27
30
|
admin_column_status: "Status",
|
|
28
31
|
admin_column_unverified: "Unverified",
|
|
@@ -49,7 +52,10 @@ const defaultMessages = {
|
|
|
49
52
|
admin_ban_description: "Êtes-vous sûr de vouloir bannir {name} ({email}) ? Il ne pourra plus se connecter.",
|
|
50
53
|
admin_ban_title: "Bannir l'utilisateur",
|
|
51
54
|
admin_column_created: "Créé",
|
|
55
|
+
admin_column_id: "ID",
|
|
52
56
|
admin_column_last_signed_in: "Dernière connexion",
|
|
57
|
+
admin_column_organizations: "Organisations",
|
|
58
|
+
admin_column_projects: "Projets",
|
|
53
59
|
admin_column_role: "Rôle",
|
|
54
60
|
admin_column_status: "Statut",
|
|
55
61
|
admin_column_unverified: "Non vérifié",
|
|
@@ -72,6 +78,12 @@ const defaultMessages = {
|
|
|
72
78
|
const labels = (locale) => ({
|
|
73
79
|
...defaultMessages[locale],
|
|
74
80
|
});
|
|
81
|
+
const initials = (name) => name
|
|
82
|
+
.split(/\s+/)
|
|
83
|
+
.slice(0, 2)
|
|
84
|
+
.map((part) => part[0])
|
|
85
|
+
.join("")
|
|
86
|
+
.toUpperCase();
|
|
75
87
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
76
88
|
const adminUsersQuery = (search, projectId) => {
|
|
77
89
|
const query = {
|
|
@@ -171,7 +183,7 @@ export function AdminUsersTable({ from, reloadKey = 0, search, }) {
|
|
|
171
183
|
await navigate({ to: "/" });
|
|
172
184
|
await router.invalidate();
|
|
173
185
|
};
|
|
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: {
|
|
186
|
+
return (_jsxs(_Fragment, { children: [error ? _jsx(ErrorMessage, { text: error }) : null, impersonateError ? _jsx(ErrorMessage, { text: impersonateError }) : null, _jsx(DataTable, { columns: userColumns(m, baseUrl), data: users, defaultColumnVisibility: { id: false }, features: {
|
|
175
187
|
export: { baseName: "users" },
|
|
176
188
|
gallery: false,
|
|
177
189
|
pagination: { mode: "server", rowCount: total },
|
|
@@ -271,7 +283,12 @@ export function useAdminUsersTotal(search) {
|
|
|
271
283
|
onSuccess: ({ value }) => value.meta.total,
|
|
272
284
|
});
|
|
273
285
|
}
|
|
274
|
-
const userColumns = (m) => [
|
|
286
|
+
const userColumns = (m, baseUrl) => [
|
|
287
|
+
{
|
|
288
|
+
accessorKey: "id",
|
|
289
|
+
header: m.admin_column_id,
|
|
290
|
+
cell: ({ row }) => (_jsx("span", { className: "text-muted-foreground font-mono text-xs", children: row.original.id })),
|
|
291
|
+
},
|
|
275
292
|
{
|
|
276
293
|
accessorKey: "email",
|
|
277
294
|
header: m.admin_column_user,
|
|
@@ -280,6 +297,30 @@ const userColumns = (m) => [
|
|
|
280
297
|
return (_jsx(AppBrand, { to: null, label: row.original.email, subtitle: row.original.name, icon: UserIcon, className: "min-w-48", ...(image ? { imageSrc: image } : {}) }));
|
|
281
298
|
},
|
|
282
299
|
},
|
|
300
|
+
{
|
|
301
|
+
accessorKey: "organizations",
|
|
302
|
+
header: m.admin_column_organizations,
|
|
303
|
+
cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: row.original.organizations.map((organization) => {
|
|
304
|
+
const logo = assetUrl(organization.logo, baseUrl);
|
|
305
|
+
return {
|
|
306
|
+
label: organization.name,
|
|
307
|
+
value: organization.id,
|
|
308
|
+
icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(organization.name)),
|
|
309
|
+
};
|
|
310
|
+
}), variant: "icon" })),
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
accessorKey: "projects",
|
|
314
|
+
header: m.admin_column_projects,
|
|
315
|
+
cell: ({ row }) => (_jsx(DataTableListSummary, { emptyLabel: "-", items: row.original.projects.map((project) => {
|
|
316
|
+
const logo = assetUrl(project.logo, baseUrl);
|
|
317
|
+
return {
|
|
318
|
+
label: project.name,
|
|
319
|
+
value: project.id,
|
|
320
|
+
icon: logo ? (_jsx("img", { alt: "", className: "size-full object-cover", src: logo })) : (initials(project.name)),
|
|
321
|
+
};
|
|
322
|
+
}), variant: "icon" })),
|
|
323
|
+
},
|
|
283
324
|
{
|
|
284
325
|
accessorKey: "emailVerified",
|
|
285
326
|
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<{
|