@nexys/user-management-web 0.0.26

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.
Files changed (77) hide show
  1. package/README.md +61 -0
  2. package/components.json +21 -0
  3. package/package.json +66 -0
  4. package/src/components/audit/audit-log-table.test.tsx +91 -0
  5. package/src/components/audit/audit-log-table.tsx +226 -0
  6. package/src/components/auth/accept-invitation-card.tsx +100 -0
  7. package/src/components/auth/forgot-password-form.tsx +92 -0
  8. package/src/components/auth/reset-password-form.tsx +143 -0
  9. package/src/components/auth/sign-in-form.test.tsx +140 -0
  10. package/src/components/auth/sign-in-form.tsx +509 -0
  11. package/src/components/auth/sign-up-form.tsx +123 -0
  12. package/src/components/layout/app-shell.tsx +189 -0
  13. package/src/components/layout/auth-shell.tsx +28 -0
  14. package/src/components/layout/theme-toggle.tsx +55 -0
  15. package/src/components/layout/user-menu.tsx +84 -0
  16. package/src/components/primitives/empty-state.tsx +40 -0
  17. package/src/components/primitives/page-header.tsx +27 -0
  18. package/src/components/primitives/spinner.tsx +28 -0
  19. package/src/components/profile/api-tokens-card.tsx +235 -0
  20. package/src/components/profile/change-password-form.tsx +158 -0
  21. package/src/components/profile/passkeys-card.tsx +180 -0
  22. package/src/components/profile/profile-card.tsx +33 -0
  23. package/src/components/profile/two-factor-card.tsx +226 -0
  24. package/src/components/projects/project-consents.tsx +572 -0
  25. package/src/components/projects/project-create-dialog.tsx +209 -0
  26. package/src/components/projects/project-detail-tabs.tsx +63 -0
  27. package/src/components/projects/project-email-templates.tsx +282 -0
  28. package/src/components/projects/project-notices.tsx +458 -0
  29. package/src/components/projects/project-settings.tsx +1133 -0
  30. package/src/components/projects/project-tenants.tsx +107 -0
  31. package/src/components/projects/projects-table.test.tsx +95 -0
  32. package/src/components/projects/projects-table.tsx +240 -0
  33. package/src/components/roles/role-badge.tsx +91 -0
  34. package/src/components/roles/role-select.tsx +76 -0
  35. package/src/components/tenants/tenant-create-dialog.tsx +163 -0
  36. package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
  37. package/src/components/tenants/tenant-members.tsx +578 -0
  38. package/src/components/tenants/tenant-roles.test.tsx +91 -0
  39. package/src/components/tenants/tenant-roles.tsx +414 -0
  40. package/src/components/tenants/tenant-settings.tsx +385 -0
  41. package/src/components/tenants/tenants-table.test.tsx +71 -0
  42. package/src/components/tenants/tenants-table.tsx +245 -0
  43. package/src/components/ui/alert.tsx +52 -0
  44. package/src/components/ui/avatar.tsx +46 -0
  45. package/src/components/ui/badge.tsx +32 -0
  46. package/src/components/ui/button.tsx +64 -0
  47. package/src/components/ui/card.tsx +65 -0
  48. package/src/components/ui/dialog.tsx +99 -0
  49. package/src/components/ui/dropdown-menu.tsx +97 -0
  50. package/src/components/ui/field.tsx +44 -0
  51. package/src/components/ui/input.tsx +23 -0
  52. package/src/components/ui/label.tsx +19 -0
  53. package/src/components/ui/select.tsx +87 -0
  54. package/src/components/ui/separator.tsx +22 -0
  55. package/src/components/ui/skeleton.tsx +13 -0
  56. package/src/components/ui/switch.tsx +29 -0
  57. package/src/components/ui/table.tsx +87 -0
  58. package/src/components/ui/tabs.tsx +51 -0
  59. package/src/components/ui/textarea.tsx +22 -0
  60. package/src/components/ui/tooltip.tsx +27 -0
  61. package/src/components/users/user-create-dialog.tsx +267 -0
  62. package/src/components/users/user-delete-dialog.tsx +88 -0
  63. package/src/components/users/user-detail.tsx +843 -0
  64. package/src/components/users/users-table.test.tsx +97 -0
  65. package/src/components/users/users-table.tsx +382 -0
  66. package/src/context/auth-context.tsx +124 -0
  67. package/src/context/theme-context.test.tsx +78 -0
  68. package/src/context/theme-context.tsx +110 -0
  69. package/src/hooks/use-call.ts +64 -0
  70. package/src/index.ts +159 -0
  71. package/src/lib/error-message.ts +16 -0
  72. package/src/lib/utils.test.ts +61 -0
  73. package/src/lib/utils.ts +79 -0
  74. package/src/lib/webauthn.ts +36 -0
  75. package/src/styles.css +107 -0
  76. package/src/test-setup.ts +5 -0
  77. package/tailwind.preset.cjs +15 -0
@@ -0,0 +1,414 @@
1
+ import {
2
+ type RoleRow,
3
+ } from "@nexys/user-management-client";
4
+ import { AlertCircle, Pencil, Plus, Shield, Trash2 } from "lucide-react";
5
+ import { useState, type FormEvent } from "react";
6
+
7
+ import { useUmClient } from "../../context/auth-context.js";
8
+ import { useCall } from "../../hooks/use-call.js";
9
+ import { errorMessage } from "../../lib/error-message.js";
10
+ import { formatRelative } from "../../lib/utils.js";
11
+ import { EmptyState } from "../primitives/empty-state.js";
12
+ import { Alert, AlertDescription } from "../ui/alert.js";
13
+ import { Badge } from "../ui/badge.js";
14
+ import { Button } from "../ui/button.js";
15
+ import {
16
+ Card,
17
+ CardContent,
18
+ CardDescription,
19
+ CardHeader,
20
+ CardTitle,
21
+ } from "../ui/card.js";
22
+ import {
23
+ Dialog,
24
+ DialogClose,
25
+ DialogContent,
26
+ DialogDescription,
27
+ DialogFooter,
28
+ DialogHeader,
29
+ DialogTitle,
30
+ } from "../ui/dialog.js";
31
+ import { Field } from "../ui/field.js";
32
+ import { Input } from "../ui/input.js";
33
+ import { Skeleton } from "../ui/skeleton.js";
34
+ import {
35
+ Table,
36
+ TableBody,
37
+ TableCell,
38
+ TableHead,
39
+ TableHeader,
40
+ TableRow,
41
+ } from "../ui/table.js";
42
+
43
+ export interface TenantRolesProps {
44
+ organizationId: string;
45
+ canManage?: boolean;
46
+ }
47
+
48
+ /** "invoices:read, reports:*" → ["invoices:read", "reports:*"] */
49
+ const parsePermissions = (raw: string): string[] =>
50
+ raw
51
+ .split(/[\s,]+/)
52
+ .map((p) => p.trim())
53
+ .filter(Boolean);
54
+
55
+ const PermissionBadges = ({ permissions }: { permissions: string[] }) =>
56
+ permissions.length === 0 ? (
57
+ <span className="text-sm text-muted-foreground">{"—"}</span>
58
+ ) : (
59
+ <div className="flex max-w-md flex-wrap gap-1">
60
+ {permissions.map((p) => (
61
+ <Badge key={p} variant="secondary" className="font-mono text-xs">
62
+ {p}
63
+ </Badge>
64
+ ))}
65
+ </div>
66
+ );
67
+
68
+ export const TenantRoles = ({
69
+ organizationId,
70
+ canManage = false,
71
+ }: TenantRolesProps) => {
72
+ const client = useUmClient();
73
+ const { data, error, loading, refresh } = useCall("listTenantRoles", {
74
+ orgId: organizationId,
75
+ });
76
+ const [busy, setBusy] = useState<string | null>(null);
77
+ const [actionError, setActionError] = useState<string | null>(null);
78
+ const [editing, setEditing] = useState<RoleRow | null>(null);
79
+
80
+ const removeRole = async (role: RoleRow) => {
81
+ setBusy(`del-${role.id}`);
82
+ setActionError(null);
83
+ const res = await client.deleteTenantRole({
84
+ orgId: organizationId,
85
+ roleId: role.id,
86
+ });
87
+ setBusy(null);
88
+ if (res.ok) {
89
+ await refresh();
90
+ } else {
91
+ setActionError(errorMessage(res.error, "Failed to delete role."));
92
+ }
93
+ };
94
+
95
+ const roles = data?.roles ?? [];
96
+
97
+ return (
98
+ <Card>
99
+ <CardHeader className="space-y-0">
100
+ <div className="flex items-center justify-between gap-3">
101
+ <div>
102
+ <CardTitle className="flex items-center gap-2">
103
+ <Shield className="size-4 text-muted-foreground" />
104
+ Roles
105
+ </CardTitle>
106
+ <CardDescription>
107
+ {roles.length} custom role{roles.length === 1 ? "" : "s"} defined
108
+ for this tenant. Assign them to members from the Members tab.
109
+ </CardDescription>
110
+ </div>
111
+ </div>
112
+ </CardHeader>
113
+ <CardContent className="grid gap-5">
114
+ {error ? (
115
+ <Alert variant="destructive">
116
+ <AlertCircle />
117
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
118
+ </Alert>
119
+ ) : null}
120
+ {actionError ? (
121
+ <Alert variant="destructive">
122
+ <AlertCircle />
123
+ <AlertDescription>{actionError}</AlertDescription>
124
+ </Alert>
125
+ ) : null}
126
+
127
+ {canManage ? (
128
+ <AddRoleRow organizationId={organizationId} onCreated={refresh} />
129
+ ) : null}
130
+
131
+ <div className="overflow-hidden rounded-lg border">
132
+ <Table>
133
+ <TableHeader>
134
+ <TableRow>
135
+ <TableHead>Name</TableHead>
136
+ <TableHead>Description</TableHead>
137
+ <TableHead>Permissions</TableHead>
138
+ <TableHead>Created</TableHead>
139
+ {canManage && (
140
+ <TableHead className="text-right">Actions</TableHead>
141
+ )}
142
+ </TableRow>
143
+ </TableHeader>
144
+ <TableBody>
145
+ {loading ? (
146
+ Array.from({ length: 3 }).map((_, i) => (
147
+ <TableRow key={`sk-${i}`}>
148
+ <TableCell>
149
+ <Skeleton className="h-5 w-28" />
150
+ </TableCell>
151
+ <TableCell>
152
+ <Skeleton className="h-5 w-40" />
153
+ </TableCell>
154
+ <TableCell>
155
+ <Skeleton className="h-5 w-32" />
156
+ </TableCell>
157
+ <TableCell>
158
+ <Skeleton className="h-5 w-24" />
159
+ </TableCell>
160
+ {canManage && (
161
+ <TableCell className="text-right">
162
+ <Skeleton className="ml-auto h-8 w-8 rounded" />
163
+ </TableCell>
164
+ )}
165
+ </TableRow>
166
+ ))
167
+ ) : roles.length === 0 ? (
168
+ <TableRow>
169
+ <TableCell colSpan={canManage ? 5 : 4} className="p-0">
170
+ <EmptyState
171
+ icon={Shield}
172
+ title="No custom roles"
173
+ description="Create roles to define fine-grained permissions."
174
+ className="border-0 rounded-none bg-transparent"
175
+ />
176
+ </TableCell>
177
+ </TableRow>
178
+ ) : (
179
+ roles.map((role) => (
180
+ <TableRow key={role.id}>
181
+ <TableCell className="font-medium">{role.name}</TableCell>
182
+ <TableCell className="text-sm text-muted-foreground">
183
+ {role.description ?? "—"}
184
+ </TableCell>
185
+ <TableCell>
186
+ <PermissionBadges permissions={role.permissions ?? []} />
187
+ </TableCell>
188
+ <TableCell
189
+ title={role.createdAt}
190
+ className="text-sm text-muted-foreground"
191
+ >
192
+ {formatRelative(role.createdAt)}
193
+ </TableCell>
194
+ {canManage && (
195
+ <TableCell className="text-right">
196
+ <Button
197
+ variant="ghost"
198
+ size="icon"
199
+ onClick={() => setEditing(role)}
200
+ aria-label="Edit role"
201
+ >
202
+ <Pencil />
203
+ </Button>
204
+ <Button
205
+ variant="ghost"
206
+ size="icon"
207
+ onClick={() => removeRole(role)}
208
+ loading={busy === `del-${role.id}`}
209
+ aria-label="Delete role"
210
+ >
211
+ <Trash2 className="text-destructive" />
212
+ </Button>
213
+ </TableCell>
214
+ )}
215
+ </TableRow>
216
+ ))
217
+ )}
218
+ </TableBody>
219
+ </Table>
220
+ </div>
221
+ </CardContent>
222
+
223
+ {editing ? (
224
+ <EditRoleDialog
225
+ organizationId={organizationId}
226
+ role={editing}
227
+ onClose={() => setEditing(null)}
228
+ onSaved={async () => {
229
+ setEditing(null);
230
+ await refresh();
231
+ }}
232
+ />
233
+ ) : null}
234
+ </Card>
235
+ );
236
+ };
237
+
238
+ const AddRoleRow = ({
239
+ organizationId,
240
+ onCreated,
241
+ }: {
242
+ organizationId: string;
243
+ onCreated: () => void;
244
+ }) => {
245
+ const client = useUmClient();
246
+ const [name, setName] = useState("");
247
+ const [description, setDescription] = useState("");
248
+ const [permissions, setPermissions] = useState("");
249
+ const [loading, setLoading] = useState(false);
250
+ const [error, setError] = useState<string | null>(null);
251
+
252
+ const submit = async (e: FormEvent) => {
253
+ e.preventDefault();
254
+ setLoading(true);
255
+ setError(null);
256
+ const res = await client.createTenantRole({
257
+ orgId: organizationId,
258
+ name: name.trim(),
259
+ description: description.trim() || undefined,
260
+ permissions: parsePermissions(permissions),
261
+ });
262
+ setLoading(false);
263
+ if (res.ok) {
264
+ setName("");
265
+ setDescription("");
266
+ setPermissions("");
267
+ onCreated();
268
+ } else {
269
+ setError(errorMessage(res.error, "Couldn't create role."));
270
+ }
271
+ };
272
+
273
+ return (
274
+ <form
275
+ onSubmit={submit}
276
+ className="grid items-end gap-3 rounded-lg border border-dashed bg-muted/30 p-4 sm:grid-cols-[1fr_1fr_1fr_auto]"
277
+ >
278
+ <Field label="Role name" htmlFor="role-name">
279
+ <Input
280
+ id="role-name"
281
+ required
282
+ value={name}
283
+ onChange={(e) => setName(e.target.value)}
284
+ placeholder="e.g. billing-admin"
285
+ />
286
+ </Field>
287
+ <Field label="Description (optional)" htmlFor="role-desc">
288
+ <Input
289
+ id="role-desc"
290
+ value={description}
291
+ onChange={(e) => setDescription(e.target.value)}
292
+ placeholder="Can manage billing"
293
+ />
294
+ </Field>
295
+ <Field label="Permissions (comma-separated)" htmlFor="role-perms">
296
+ <Input
297
+ id="role-perms"
298
+ value={permissions}
299
+ onChange={(e) => setPermissions(e.target.value)}
300
+ placeholder="invoices:read, invoices:write"
301
+ className="font-mono"
302
+ />
303
+ </Field>
304
+ <Button type="submit" loading={loading} disabled={!name.trim()}>
305
+ <Plus />
306
+ Add role
307
+ </Button>
308
+ {error ? (
309
+ <div className="sm:col-span-4">
310
+ <Alert variant="destructive">
311
+ <AlertCircle />
312
+ <AlertDescription>{error}</AlertDescription>
313
+ </Alert>
314
+ </div>
315
+ ) : null}
316
+ </form>
317
+ );
318
+ };
319
+
320
+ const EditRoleDialog = ({
321
+ organizationId,
322
+ role,
323
+ onClose,
324
+ onSaved,
325
+ }: {
326
+ organizationId: string;
327
+ role: RoleRow;
328
+ onClose: () => void;
329
+ onSaved: () => void;
330
+ }) => {
331
+ const client = useUmClient();
332
+ const [name, setName] = useState(role.name);
333
+ const [description, setDescription] = useState(role.description ?? "");
334
+ const [permissions, setPermissions] = useState(
335
+ (role.permissions ?? []).join(", ")
336
+ );
337
+ const [saving, setSaving] = useState(false);
338
+ const [error, setError] = useState<string | null>(null);
339
+
340
+ const submit = async (e: FormEvent) => {
341
+ e.preventDefault();
342
+ setSaving(true);
343
+ setError(null);
344
+ const res = await client.updateTenantRole({
345
+ orgId: organizationId,
346
+ roleId: role.id,
347
+ name: name.trim(),
348
+ description: description.trim(),
349
+ permissions: parsePermissions(permissions),
350
+ });
351
+ setSaving(false);
352
+ if (res.ok) {
353
+ onSaved();
354
+ } else {
355
+ setError(errorMessage(res.error, "Couldn't update role."));
356
+ }
357
+ };
358
+
359
+ return (
360
+ <Dialog open onOpenChange={(open) => !open && onClose()}>
361
+ <DialogContent>
362
+ <form onSubmit={submit} className="grid gap-4">
363
+ <DialogHeader>
364
+ <DialogTitle>Edit role</DialogTitle>
365
+ <DialogDescription>
366
+ Rename <strong>{role.name}</strong> or change the permissions it
367
+ grants. Changes apply to every member holding this role.
368
+ </DialogDescription>
369
+ </DialogHeader>
370
+ {error ? (
371
+ <Alert variant="destructive">
372
+ <AlertCircle />
373
+ <AlertDescription>{error}</AlertDescription>
374
+ </Alert>
375
+ ) : null}
376
+ <Field label="Role name" htmlFor="edit-role-name">
377
+ <Input
378
+ id="edit-role-name"
379
+ required
380
+ value={name}
381
+ onChange={(e) => setName(e.target.value)}
382
+ />
383
+ </Field>
384
+ <Field label="Description" htmlFor="edit-role-desc">
385
+ <Input
386
+ id="edit-role-desc"
387
+ value={description}
388
+ onChange={(e) => setDescription(e.target.value)}
389
+ />
390
+ </Field>
391
+ <Field label="Permissions (comma-separated)" htmlFor="edit-role-perms">
392
+ <Input
393
+ id="edit-role-perms"
394
+ value={permissions}
395
+ onChange={(e) => setPermissions(e.target.value)}
396
+ placeholder="invoices:read, invoices:write"
397
+ className="font-mono"
398
+ />
399
+ </Field>
400
+ <DialogFooter>
401
+ <DialogClose asChild>
402
+ <Button type="button" variant="outline">
403
+ Cancel
404
+ </Button>
405
+ </DialogClose>
406
+ <Button type="submit" loading={saving} disabled={!name.trim()}>
407
+ Save role
408
+ </Button>
409
+ </DialogFooter>
410
+ </form>
411
+ </DialogContent>
412
+ </Dialog>
413
+ );
414
+ };