@nexys/user-management-web 0.3.1

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