@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.
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useAtomSet } from "@effect/atom-react";
3
- import { Schema } from "effect";
4
- import { Loader2 } from "lucide-react";
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 { ErrorMessage, useAppForm } from "@/components/ui/form";
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 isFile = (value) => value instanceof File;
56
- const valuesToPayload = (value, logo) => Schema.decodeUnknownSync(AdminCreateOrganizationPayload)({
57
- name: value.name.trim(),
58
- slug: slugify(value.slug || value.name),
59
- logo: logo ?? undefined,
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 createOrganization = useAtomSet(authClientApi(baseUrl).mutation("admin", "createOrganization"), { mode: "promise" });
66
- const updateOrganization = useAtomSet(authClientApi(baseUrl).mutation("admin", "updateOrganization"), { mode: "promise" });
67
- const uploadLogo = useAtomSet(authClientApi(baseUrl).mutation("authExtra", "uploadUserImage"), { mode: "promise" });
68
- const [error, setError] = useState("");
69
- const isEditing = Boolean(organization);
70
- const form = useAppForm({
71
- defaultValues: {
72
- name: organization?.name ?? "",
73
- slug: organization?.slug ?? "",
74
- logo: assetUrl(organization?.logo, baseUrl),
75
- },
76
- onSubmit: async ({ value }) => {
77
- setError("");
78
- try {
79
- const logoFile = isFile(value.logo) ? value.logo : null;
80
- const logo = logoFile
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
- 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
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: isEditing
151
+ : m.organization_create_title }), _jsx(DialogDescription, { children: organization
112
152
  ? text(m.admin_organization_edit_description, {
113
- name: organization?.name ?? "",
153
+ name: organization.name,
114
154
  })
115
- : m.organization_create_description })] }), _jsx(form.AppForm, { children: _jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
116
- event.preventDefault();
117
- event.stopPropagation();
118
- form.handleSubmit();
119
- }, 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: {
120
- width: 96,
121
- height: 96,
122
- suggestedWidth: 512,
123
- suggestedHeight: 512,
124
- } })) }), _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] })) })] }) })] }) }));
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 { DataTable } from "@/components/ui/data-table";
8
- import { ErrorMessage } from "@/components/ui/form";
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("span", { className: "text-muted-foreground text-sm tabular-nums", children: (row.original.memberCount ?? 0).toLocaleString() })),
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<{
@@ -17,6 +17,10 @@ declare const organizationSchema: {
17
17
  readonly type: "string";
18
18
  readonly required: false;
19
19
  };
20
+ readonly parentId: {
21
+ readonly type: "string";
22
+ readonly required: false;
23
+ };
20
24
  };
21
25
  };
22
26
  };
@@ -17,6 +17,10 @@ const organizationSchema = {
17
17
  type: "string",
18
18
  required: false,
19
19
  },
20
+ parentId: {
21
+ type: "string",
22
+ required: false,
23
+ },
20
24
  },
21
25
  },
22
26
  };