@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,461 @@
1
+ import {
2
+ createNotification,
3
+ deleteNotification,
4
+ listNotifications,
5
+ updateNotification,
6
+ type NotificationRow,
7
+ type NotificationSurface,
8
+ } from "@nexys/user-management-client";
9
+ import { AlertCircle, Trash2 } from "lucide-react";
10
+ import { useState, type FormEvent } from "react";
11
+
12
+ import { useUmClient } from "../../context/auth-context.js";
13
+ import { useCall } from "../../hooks/use-call.js";
14
+ import { errorMessage } from "../../lib/error-message.js";
15
+ import { Alert, AlertDescription } from "../ui/alert.js";
16
+ import { Badge } from "../ui/badge.js";
17
+ import { Button } from "../ui/button.js";
18
+ import {
19
+ Card,
20
+ CardContent,
21
+ CardDescription,
22
+ CardHeader,
23
+ CardTitle,
24
+ } from "../ui/card.js";
25
+ import {
26
+ Dialog,
27
+ DialogContent,
28
+ DialogDescription,
29
+ DialogFooter,
30
+ DialogHeader,
31
+ DialogTitle,
32
+ DialogTrigger,
33
+ } from "../ui/dialog.js";
34
+ import { Field } from "../ui/field.js";
35
+ import { Input } from "../ui/input.js";
36
+ import { Label } from "../ui/label.js";
37
+ import {
38
+ Select,
39
+ SelectContent,
40
+ SelectItem,
41
+ SelectTrigger,
42
+ SelectValue,
43
+ } from "../ui/select.js";
44
+ import { Skeleton } from "../ui/skeleton.js";
45
+ import { Switch } from "../ui/switch.js";
46
+ import { Textarea } from "../ui/textarea.js";
47
+
48
+ export interface ProjectNoticesProps {
49
+ projectId: string;
50
+ canManage?: boolean;
51
+ }
52
+
53
+ const SURFACES: { value: NotificationSurface; label: string }[] = [
54
+ { value: "any", label: "Everywhere" },
55
+ { value: "login", label: "Login screen" },
56
+ { value: "signup", label: "Sign-up screen" },
57
+ { value: "app", label: "Inside the app" },
58
+ ];
59
+
60
+ const SEVERITIES = ["info", "warning", "critical"] as const;
61
+
62
+ /** `datetime-local` wants `YYYY-MM-DDTHH:mm` in local time. */
63
+ const toLocalInput = (iso: string | null): string => {
64
+ if (!iso) return "";
65
+ const d = new Date(iso);
66
+ const pad = (n: number) => String(n).padStart(2, "0");
67
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}T${pad(
68
+ d.getHours()
69
+ )}:${pad(d.getMinutes())}`;
70
+ };
71
+
72
+ /** Back to RFC 3339 for the API; "" means "no bound". */
73
+ const toIso = (local: string): string =>
74
+ local.trim() === "" ? "" : new Date(local).toISOString();
75
+
76
+ /** Why a notice isn't showing right now — the thing you want to see at a glance. */
77
+ const liveState = (n: NotificationRow): { label: string; live: boolean } => {
78
+ if (!n.enabled) return { label: "disabled", live: false };
79
+ const now = Date.now();
80
+ if (n.startsAt && new Date(n.startsAt).getTime() > now) {
81
+ return { label: "scheduled", live: false };
82
+ }
83
+ if (n.endsAt && new Date(n.endsAt).getTime() <= now) {
84
+ return { label: "expired", live: false };
85
+ }
86
+ return { label: "live", live: true };
87
+ };
88
+
89
+ export const ProjectNotices = ({
90
+ projectId,
91
+ canManage = false,
92
+ }: ProjectNoticesProps) => {
93
+ const { data, loading, error, refresh } = useCall(listNotifications, {
94
+ projectId,
95
+ });
96
+ const notices = data?.notifications ?? [];
97
+
98
+ if (error) {
99
+ return (
100
+ <Alert variant="destructive">
101
+ <AlertCircle />
102
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
103
+ </Alert>
104
+ );
105
+ }
106
+
107
+ return (
108
+ <Card>
109
+ <CardHeader>
110
+ <CardTitle>Notices</CardTitle>
111
+ <CardDescription>
112
+ Messages shown to this product's users. A notice appears while it is
113
+ enabled and inside its date window; dismissals are remembered per
114
+ user.
115
+ </CardDescription>
116
+ </CardHeader>
117
+ <CardContent className="grid gap-4">
118
+ {loading ? (
119
+ <Skeleton className="h-20 w-full" />
120
+ ) : notices.length === 0 ? (
121
+ <p className="text-muted-foreground text-sm">
122
+ No notices yet.
123
+ </p>
124
+ ) : (
125
+ <div className="grid gap-2">
126
+ {notices.map((n) => (
127
+ <NoticeRow
128
+ key={n.id}
129
+ projectId={projectId}
130
+ notice={n}
131
+ canManage={canManage}
132
+ onChanged={refresh}
133
+ />
134
+ ))}
135
+ </div>
136
+ )}
137
+ {canManage ? (
138
+ <NoticeDialog projectId={projectId} onSaved={refresh} />
139
+ ) : null}
140
+ </CardContent>
141
+ </Card>
142
+ );
143
+ };
144
+
145
+ const NoticeRow = ({
146
+ projectId,
147
+ notice,
148
+ canManage,
149
+ onChanged,
150
+ }: {
151
+ projectId: string;
152
+ notice: NotificationRow;
153
+ canManage: boolean;
154
+ onChanged: () => void;
155
+ }) => {
156
+ const client = useUmClient();
157
+ const [busy, setBusy] = useState(false);
158
+ const state = liveState(notice);
159
+
160
+ const toggleEnabled = async () => {
161
+ setBusy(true);
162
+ await client.call(updateNotification, {
163
+ projectId,
164
+ notificationId: notice.id,
165
+ enabled: !notice.enabled,
166
+ });
167
+ setBusy(false);
168
+ onChanged();
169
+ };
170
+
171
+ const remove = async () => {
172
+ setBusy(true);
173
+ await client.call(deleteNotification, {
174
+ projectId,
175
+ notificationId: notice.id,
176
+ });
177
+ setBusy(false);
178
+ onChanged();
179
+ };
180
+
181
+ const window = [
182
+ notice.startsAt ? `from ${new Date(notice.startsAt).toLocaleString()}` : null,
183
+ notice.endsAt ? `until ${new Date(notice.endsAt).toLocaleString()}` : null,
184
+ ]
185
+ .filter(Boolean)
186
+ .join(" ");
187
+
188
+ return (
189
+ <div className="flex items-start justify-between gap-3 rounded-lg border bg-card p-3">
190
+ <div className="min-w-0 grid gap-1">
191
+ <div className="flex flex-wrap items-center gap-2">
192
+ <span className="text-sm font-medium">{notice.title}</span>
193
+ <Badge variant={state.live ? "default" : "muted"}>{state.label}</Badge>
194
+ <Badge variant="muted">
195
+ {SURFACES.find((s) => s.value === notice.surface)?.label ??
196
+ notice.surface}
197
+ </Badge>
198
+ {notice.severity !== "info" ? (
199
+ <Badge variant="muted">{notice.severity}</Badge>
200
+ ) : null}
201
+ {!notice.dismissible ? (
202
+ <Badge variant="muted">not dismissible</Badge>
203
+ ) : null}
204
+ </div>
205
+ <p className="text-muted-foreground truncate text-xs">{notice.body}</p>
206
+ {window ? (
207
+ <p className="text-muted-foreground text-xs">{window}</p>
208
+ ) : null}
209
+ </div>
210
+ {canManage ? (
211
+ <div className="flex shrink-0 items-center gap-2">
212
+ <NoticeDialog
213
+ projectId={projectId}
214
+ notice={notice}
215
+ onSaved={onChanged}
216
+ />
217
+ <Switch
218
+ checked={notice.enabled}
219
+ onCheckedChange={() => void toggleEnabled()}
220
+ disabled={busy}
221
+ aria-label="Enabled"
222
+ />
223
+ <Button
224
+ variant="ghost"
225
+ size="icon"
226
+ className="size-8"
227
+ onClick={() => void remove()}
228
+ disabled={busy}
229
+ aria-label="Delete notice"
230
+ >
231
+ <Trash2 className="size-4" />
232
+ </Button>
233
+ </div>
234
+ ) : null}
235
+ </div>
236
+ );
237
+ };
238
+
239
+ /** Create when `notice` is absent, edit when present. */
240
+ const NoticeDialog = ({
241
+ projectId,
242
+ notice,
243
+ onSaved,
244
+ }: {
245
+ projectId: string;
246
+ notice?: NotificationRow;
247
+ onSaved: () => void;
248
+ }) => {
249
+ const client = useUmClient();
250
+ const editing = notice !== undefined;
251
+ const [open, setOpen] = useState(false);
252
+ const [title, setTitle] = useState(notice?.title ?? "");
253
+ const [body, setBody] = useState(notice?.body ?? "");
254
+ const [surface, setSurface] = useState<NotificationSurface>(
255
+ notice?.surface ?? "any"
256
+ );
257
+ const [severity, setSeverity] = useState<(typeof SEVERITIES)[number]>(
258
+ notice?.severity ?? "info"
259
+ );
260
+ const [startsAt, setStartsAt] = useState(toLocalInput(notice?.startsAt ?? null));
261
+ const [endsAt, setEndsAt] = useState(toLocalInput(notice?.endsAt ?? null));
262
+ const [dismissible, setDismissible] = useState(notice?.dismissible ?? true);
263
+ const [loading, setLoading] = useState(false);
264
+ const [error, setError] = useState<string | null>(null);
265
+
266
+ const windowValid =
267
+ !startsAt || !endsAt || new Date(endsAt) > new Date(startsAt);
268
+
269
+ const reset = () => {
270
+ setTitle(notice?.title ?? "");
271
+ setBody(notice?.body ?? "");
272
+ setSurface(notice?.surface ?? "any");
273
+ setSeverity(notice?.severity ?? "info");
274
+ setStartsAt(toLocalInput(notice?.startsAt ?? null));
275
+ setEndsAt(toLocalInput(notice?.endsAt ?? null));
276
+ setDismissible(notice?.dismissible ?? true);
277
+ setError(null);
278
+ setLoading(false);
279
+ };
280
+
281
+ const submit = async (e: FormEvent) => {
282
+ e.preventDefault();
283
+ setLoading(true);
284
+ setError(null);
285
+ const shared = {
286
+ title: title.trim(),
287
+ body,
288
+ surface,
289
+ severity: severity as "info" | "warning" | "critical",
290
+ dismissible,
291
+ };
292
+ const res = editing
293
+ ? await client.call(updateNotification, {
294
+ projectId,
295
+ notificationId: notice.id,
296
+ ...shared,
297
+ // "" clears a bound server-side; omitting would keep it.
298
+ startsAt: toIso(startsAt),
299
+ endsAt: toIso(endsAt),
300
+ })
301
+ : await client.call(createNotification, {
302
+ projectId,
303
+ ...shared,
304
+ startsAt: toIso(startsAt) || null,
305
+ endsAt: toIso(endsAt) || null,
306
+ });
307
+ setLoading(false);
308
+ if (res.ok) {
309
+ onSaved();
310
+ setOpen(false);
311
+ if (!editing) reset();
312
+ } else {
313
+ setError(errorMessage(res.error, "Couldn't save this notice."));
314
+ }
315
+ };
316
+
317
+ return (
318
+ <Dialog
319
+ open={open}
320
+ onOpenChange={(o) => {
321
+ setOpen(o);
322
+ if (!o) reset();
323
+ }}
324
+ >
325
+ <DialogTrigger asChild>
326
+ {editing ? (
327
+ <Button variant="ghost" size="sm">
328
+ Edit
329
+ </Button>
330
+ ) : (
331
+ <Button variant="outline" size="sm">
332
+ New notice
333
+ </Button>
334
+ )}
335
+ </DialogTrigger>
336
+ <DialogContent className="max-w-xl">
337
+ <DialogHeader>
338
+ <DialogTitle>{editing ? "Edit notice" : "New notice"}</DialogTitle>
339
+ <DialogDescription>
340
+ Leave a date empty for no bound on that side.
341
+ </DialogDescription>
342
+ </DialogHeader>
343
+ <form onSubmit={submit} className="grid gap-4" noValidate>
344
+ <Field label="Title" htmlFor="notice-title" required>
345
+ <Input
346
+ id="notice-title"
347
+ value={title}
348
+ onChange={(e) => setTitle(e.target.value)}
349
+ />
350
+ </Field>
351
+ <Field label="Message" htmlFor="notice-body" required>
352
+ <Textarea
353
+ id="notice-body"
354
+ value={body}
355
+ onChange={(e) => setBody(e.target.value)}
356
+ rows={4}
357
+ />
358
+ </Field>
359
+ <div className="grid gap-4 sm:grid-cols-2">
360
+ <Field label="Where" htmlFor="notice-surface">
361
+ <Select
362
+ value={surface}
363
+ onValueChange={(v) => setSurface(v as NotificationSurface)}
364
+ >
365
+ <SelectTrigger id="notice-surface">
366
+ <SelectValue />
367
+ </SelectTrigger>
368
+ <SelectContent>
369
+ {SURFACES.map((s) => (
370
+ <SelectItem key={s.value} value={s.value}>
371
+ {s.label}
372
+ </SelectItem>
373
+ ))}
374
+ </SelectContent>
375
+ </Select>
376
+ </Field>
377
+ <Field label="Severity" htmlFor="notice-severity">
378
+ <Select
379
+ value={severity}
380
+ onValueChange={(v) =>
381
+ setSeverity(v as (typeof SEVERITIES)[number])
382
+ }
383
+ >
384
+ <SelectTrigger id="notice-severity">
385
+ <SelectValue />
386
+ </SelectTrigger>
387
+ <SelectContent>
388
+ {SEVERITIES.map((s) => (
389
+ <SelectItem key={s} value={s} className="capitalize">
390
+ {s}
391
+ </SelectItem>
392
+ ))}
393
+ </SelectContent>
394
+ </Select>
395
+ </Field>
396
+ </div>
397
+ <div className="grid gap-4 sm:grid-cols-2">
398
+ <Field label="Starts" htmlFor="notice-starts">
399
+ <Input
400
+ id="notice-starts"
401
+ type="datetime-local"
402
+ value={startsAt}
403
+ onChange={(e) => setStartsAt(e.target.value)}
404
+ />
405
+ </Field>
406
+ <Field label="Ends" htmlFor="notice-ends">
407
+ <Input
408
+ id="notice-ends"
409
+ type="datetime-local"
410
+ value={endsAt}
411
+ onChange={(e) => setEndsAt(e.target.value)}
412
+ aria-invalid={!windowValid}
413
+ />
414
+ </Field>
415
+ </div>
416
+ {!windowValid ? (
417
+ <p className="text-destructive text-xs">
418
+ The end must come after the start.
419
+ </p>
420
+ ) : null}
421
+ <div className="flex items-center justify-between gap-4">
422
+ <div className="grid gap-0.5">
423
+ <Label htmlFor="notice-dismissible">Dismissible</Label>
424
+ <p className="text-muted-foreground text-xs">
425
+ Off keeps it visible for everyone while it's in window.
426
+ </p>
427
+ </div>
428
+ <Switch
429
+ id="notice-dismissible"
430
+ checked={dismissible}
431
+ onCheckedChange={setDismissible}
432
+ />
433
+ </div>
434
+ {error ? (
435
+ <Alert variant="destructive">
436
+ <AlertCircle />
437
+ <AlertDescription>{error}</AlertDescription>
438
+ </Alert>
439
+ ) : null}
440
+ <DialogFooter>
441
+ <Button
442
+ type="button"
443
+ variant="ghost"
444
+ onClick={() => setOpen(false)}
445
+ disabled={loading}
446
+ >
447
+ Cancel
448
+ </Button>
449
+ <Button
450
+ type="submit"
451
+ loading={loading}
452
+ disabled={!title.trim() || !body.trim() || !windowValid}
453
+ >
454
+ {editing ? "Save" : "Create"}
455
+ </Button>
456
+ </DialogFooter>
457
+ </form>
458
+ </DialogContent>
459
+ </Dialog>
460
+ );
461
+ };