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