@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,29 @@
1
+ import * as SwitchPrimitive from "@radix-ui/react-switch";
2
+ import * as React from "react";
3
+
4
+ import { cn } from "../../lib/utils.js";
5
+
6
+ export const Switch = React.forwardRef<
7
+ React.ElementRef<typeof SwitchPrimitive.Root>,
8
+ React.ComponentPropsWithoutRef<typeof SwitchPrimitive.Root>
9
+ >(({ className, ...props }, ref) => (
10
+ <SwitchPrimitive.Root
11
+ ref={ref}
12
+ className={cn(
13
+ "peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent",
14
+ "transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-2",
15
+ "disabled:cursor-not-allowed disabled:opacity-50",
16
+ "data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",
17
+ className
18
+ )}
19
+ {...props}
20
+ >
21
+ <SwitchPrimitive.Thumb
22
+ className={cn(
23
+ "pointer-events-none block size-4 rounded-full bg-background shadow ring-0 transition-transform",
24
+ "data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0.5"
25
+ )}
26
+ />
27
+ </SwitchPrimitive.Root>
28
+ ));
29
+ Switch.displayName = "Switch";
@@ -0,0 +1,87 @@
1
+ import * as React from "react";
2
+
3
+ import { cn } from "../../lib/utils.js";
4
+
5
+ export const Table = React.forwardRef<
6
+ HTMLTableElement,
7
+ React.HTMLAttributes<HTMLTableElement>
8
+ >(({ className, ...props }, ref) => (
9
+ <div className="relative w-full overflow-auto">
10
+ <table
11
+ ref={ref}
12
+ className={cn("w-full caption-bottom text-sm", className)}
13
+ {...props}
14
+ />
15
+ </div>
16
+ ));
17
+ Table.displayName = "Table";
18
+
19
+ export const TableHeader = React.forwardRef<
20
+ HTMLTableSectionElement,
21
+ React.HTMLAttributes<HTMLTableSectionElement>
22
+ >(({ className, ...props }, ref) => (
23
+ <thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
24
+ ));
25
+ TableHeader.displayName = "TableHeader";
26
+
27
+ export const TableBody = React.forwardRef<
28
+ HTMLTableSectionElement,
29
+ React.HTMLAttributes<HTMLTableSectionElement>
30
+ >(({ className, ...props }, ref) => (
31
+ <tbody
32
+ ref={ref}
33
+ className={cn("[&_tr:last-child]:border-0", className)}
34
+ {...props}
35
+ />
36
+ ));
37
+ TableBody.displayName = "TableBody";
38
+
39
+ export const TableRow = React.forwardRef<
40
+ HTMLTableRowElement,
41
+ React.HTMLAttributes<HTMLTableRowElement>
42
+ >(({ className, ...props }, ref) => (
43
+ <tr
44
+ ref={ref}
45
+ className={cn(
46
+ "border-b transition-colors hover:bg-muted/40 data-[state=selected]:bg-muted",
47
+ className
48
+ )}
49
+ {...props}
50
+ />
51
+ ));
52
+ TableRow.displayName = "TableRow";
53
+
54
+ export const TableHead = React.forwardRef<
55
+ HTMLTableCellElement,
56
+ React.ThHTMLAttributes<HTMLTableCellElement>
57
+ >(({ className, ...props }, ref) => (
58
+ <th
59
+ ref={ref}
60
+ className={cn(
61
+ "h-10 px-3 text-left align-middle text-xs font-medium uppercase tracking-wide text-muted-foreground",
62
+ className
63
+ )}
64
+ {...props}
65
+ />
66
+ ));
67
+ TableHead.displayName = "TableHead";
68
+
69
+ export const TableCell = React.forwardRef<
70
+ HTMLTableCellElement,
71
+ React.TdHTMLAttributes<HTMLTableCellElement>
72
+ >(({ className, ...props }, ref) => (
73
+ <td
74
+ ref={ref}
75
+ className={cn("px-3 py-3 align-middle", className)}
76
+ {...props}
77
+ />
78
+ ));
79
+ TableCell.displayName = "TableCell";
80
+
81
+ export const TableEmpty = ({ children }: { children: React.ReactNode }) => (
82
+ <tr>
83
+ <td colSpan={999} className="py-12 text-center text-sm text-muted-foreground">
84
+ {children}
85
+ </td>
86
+ </tr>
87
+ );
@@ -0,0 +1,51 @@
1
+ import * as TabsPrimitive from "@radix-ui/react-tabs";
2
+ import * as React from "react";
3
+
4
+ import { cn } from "../../lib/utils.js";
5
+
6
+ export const Tabs = TabsPrimitive.Root;
7
+
8
+ export const TabsList = React.forwardRef<
9
+ React.ElementRef<typeof TabsPrimitive.List>,
10
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
11
+ >(({ className, ...props }, ref) => (
12
+ <TabsPrimitive.List
13
+ ref={ref}
14
+ className={cn(
15
+ "inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground",
16
+ className
17
+ )}
18
+ {...props}
19
+ />
20
+ ));
21
+ TabsList.displayName = "TabsList";
22
+
23
+ export const TabsTrigger = React.forwardRef<
24
+ React.ElementRef<typeof TabsPrimitive.Trigger>,
25
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
26
+ >(({ className, ...props }, ref) => (
27
+ <TabsPrimitive.Trigger
28
+ ref={ref}
29
+ className={cn(
30
+ "inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium",
31
+ "transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40",
32
+ "disabled:pointer-events-none disabled:opacity-50",
33
+ "data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow",
34
+ className
35
+ )}
36
+ {...props}
37
+ />
38
+ ));
39
+ TabsTrigger.displayName = "TabsTrigger";
40
+
41
+ export const TabsContent = React.forwardRef<
42
+ React.ElementRef<typeof TabsPrimitive.Content>,
43
+ React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
44
+ >(({ className, ...props }, ref) => (
45
+ <TabsPrimitive.Content
46
+ ref={ref}
47
+ className={cn("mt-4 focus-visible:outline-none", className)}
48
+ {...props}
49
+ />
50
+ ));
51
+ TabsContent.displayName = "TabsContent";
@@ -0,0 +1,22 @@
1
+ import * as React from "react";
2
+
3
+ import { cn } from "../../lib/utils.js";
4
+
5
+ export const Textarea = React.forwardRef<
6
+ HTMLTextAreaElement,
7
+ React.ComponentProps<"textarea">
8
+ >(({ className, ...props }, ref) => (
9
+ <textarea
10
+ ref={ref}
11
+ className={cn(
12
+ "flex min-h-24 w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm transition-colors",
13
+ "placeholder:text-muted-foreground",
14
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:ring-offset-2 focus-visible:ring-offset-background",
15
+ "disabled:cursor-not-allowed disabled:opacity-50",
16
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20",
17
+ className
18
+ )}
19
+ {...props}
20
+ />
21
+ ));
22
+ Textarea.displayName = "Textarea";
@@ -0,0 +1,27 @@
1
+ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
2
+ import * as React from "react";
3
+
4
+ import { cn } from "../../lib/utils.js";
5
+
6
+ export const TooltipProvider = TooltipPrimitive.Provider;
7
+ export const Tooltip = TooltipPrimitive.Root;
8
+ export const TooltipTrigger = TooltipPrimitive.Trigger;
9
+
10
+ export const TooltipContent = React.forwardRef<
11
+ React.ElementRef<typeof TooltipPrimitive.Content>,
12
+ React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
13
+ >(({ className, sideOffset = 4, ...props }, ref) => (
14
+ <TooltipPrimitive.Portal>
15
+ <TooltipPrimitive.Content
16
+ ref={ref}
17
+ sideOffset={sideOffset}
18
+ className={cn(
19
+ "z-50 overflow-hidden rounded-md bg-primary px-2.5 py-1.5 text-xs text-primary-foreground shadow",
20
+ "data-[state=delayed-open]:animate-in data-[state=closed]:animate-out",
21
+ className
22
+ )}
23
+ {...props}
24
+ />
25
+ </TooltipPrimitive.Portal>
26
+ ));
27
+ TooltipContent.displayName = "TooltipContent";
@@ -0,0 +1,267 @@
1
+ import { type UserRole } from "@nexys/user-management-client";
2
+ import { AlertCircle, UserPlus } from "lucide-react";
3
+ import { useState, type FormEvent, type ReactNode } from "react";
4
+
5
+ import { useUmClient } from "../../context/auth-context.js";
6
+ import { errorMessage } from "../../lib/error-message.js";
7
+ import { UserRoleSelect } from "../roles/role-select.js";
8
+ import { Alert, AlertDescription } from "../ui/alert.js";
9
+ import { Button } from "../ui/button.js";
10
+ import {
11
+ Dialog,
12
+ DialogContent,
13
+ DialogDescription,
14
+ DialogFooter,
15
+ DialogHeader,
16
+ DialogTitle,
17
+ DialogTrigger,
18
+ } from "../ui/dialog.js";
19
+ import { Field } from "../ui/field.js";
20
+ import { Input } from "../ui/input.js";
21
+ import {
22
+ Select,
23
+ SelectContent,
24
+ SelectItem,
25
+ SelectTrigger,
26
+ SelectValue,
27
+ } from "../ui/select.js";
28
+
29
+ const SOCIAL_PROVIDERS = ["google", "microsoft", "github", "discord", "facebook"];
30
+
31
+ const providerLabel: Record<string, string> = {
32
+ google: "Google",
33
+ microsoft: "Microsoft",
34
+ github: "GitHub",
35
+ discord: "Discord",
36
+ facebook: "Facebook",
37
+ };
38
+
39
+ /** Providers with a public handle an admin is likely to know. */
40
+ const handleLabel: Record<string, string> = {
41
+ github: "GitHub username",
42
+ discord: "Discord username",
43
+ };
44
+
45
+ export interface UserCreateDialogProps {
46
+ /** Override the trigger button. */
47
+ trigger?: ReactNode;
48
+ onCreated?: (user: { id: string; email: string }) => void;
49
+ }
50
+
51
+ /** Superadmin-only direct user creation. */
52
+ export const UserCreateDialog = ({ trigger, onCreated }: UserCreateDialogProps) => {
53
+ const client = useUmClient();
54
+ const [open, setOpen] = useState(false);
55
+ const [firstName, setFirstName] = useState("");
56
+ const [lastName, setLastName] = useState("");
57
+ const [email, setEmail] = useState("");
58
+ // "password" or a social provider id — mirrors the server's
59
+ // password-XOR-provider contract on create-user.
60
+ const [signInMethod, setSignInMethod] = useState("password");
61
+ const [password, setPassword] = useState("");
62
+ // Optional pre-link key for a social sign-in method; the server
63
+ // falls back to the email when this is blank.
64
+ const [providerAccountId, setProviderAccountId] = useState("");
65
+ const [role, setRole] = useState<UserRole>("user");
66
+ const [loading, setLoading] = useState(false);
67
+ const [error, setError] = useState<string | null>(null);
68
+
69
+ const usesPassword = signInMethod === "password";
70
+
71
+ const reset = () => {
72
+ setFirstName("");
73
+ setLastName("");
74
+ setEmail("");
75
+ setSignInMethod("password");
76
+ setPassword("");
77
+ setProviderAccountId("");
78
+ setRole("user");
79
+ setError(null);
80
+ setLoading(false);
81
+ };
82
+
83
+ const submit = async (e: FormEvent) => {
84
+ e.preventDefault();
85
+ setLoading(true);
86
+ setError(null);
87
+ const res = await client.adminCreateUser({
88
+ firstName: firstName.trim(),
89
+ lastName: lastName.trim() || undefined,
90
+ email: email.trim(),
91
+ ...(usesPassword
92
+ ? { password }
93
+ : {
94
+ provider: signInMethod,
95
+ ...(providerAccountId.trim() ? { providerAccountId: providerAccountId.trim() } : {}),
96
+ }),
97
+ role,
98
+ });
99
+ setLoading(false);
100
+ if (res.ok) {
101
+ onCreated?.(res.data.user);
102
+ reset();
103
+ setOpen(false);
104
+ } else {
105
+ setError(errorMessage(res.error, "Couldn't create user."));
106
+ }
107
+ };
108
+
109
+ return (
110
+ <Dialog
111
+ open={open}
112
+ onOpenChange={(o) => {
113
+ setOpen(o);
114
+ if (!o) reset();
115
+ }}
116
+ >
117
+ <DialogTrigger asChild>
118
+ {trigger ?? (
119
+ <Button>
120
+ <UserPlus />
121
+ New user
122
+ </Button>
123
+ )}
124
+ </DialogTrigger>
125
+ <DialogContent>
126
+ <DialogHeader>
127
+ <DialogTitle>Create a new user</DialogTitle>
128
+ <DialogDescription>
129
+ {usesPassword
130
+ ? "The account is created active and email-verified. Share the " +
131
+ "password securely — the user can change it from their profile."
132
+ : "The account is created active and email-verified, with no " +
133
+ "password — the user signs in with " +
134
+ `${providerLabel[signInMethod]}.`}
135
+ </DialogDescription>
136
+ </DialogHeader>
137
+ <form onSubmit={submit} className="grid gap-4" noValidate>
138
+ <div className="grid gap-4 sm:grid-cols-2">
139
+ <Field label="First name" htmlFor="new-user-first-name" required>
140
+ <Input
141
+ id="new-user-first-name"
142
+ autoFocus
143
+ required
144
+ value={firstName}
145
+ onChange={(e) => setFirstName(e.target.value)}
146
+ placeholder="Ada"
147
+ />
148
+ </Field>
149
+ <Field label="Last name" htmlFor="new-user-last-name">
150
+ <Input
151
+ id="new-user-last-name"
152
+ value={lastName}
153
+ onChange={(e) => setLastName(e.target.value)}
154
+ placeholder="Lovelace"
155
+ />
156
+ </Field>
157
+ </div>
158
+ <Field label="Email" htmlFor="new-user-email" required>
159
+ <Input
160
+ id="new-user-email"
161
+ type="email"
162
+ required
163
+ value={email}
164
+ onChange={(e) => setEmail(e.target.value)}
165
+ placeholder="ada@example.com"
166
+ />
167
+ </Field>
168
+ <Field
169
+ label="Sign-in method"
170
+ htmlFor="new-user-sign-in-method"
171
+ description={
172
+ usesPassword
173
+ ? undefined
174
+ : `No password — their first ${providerLabel[signInMethod]} ` +
175
+ "sign-in lands on this account."
176
+ }
177
+ >
178
+ <Select value={signInMethod} onValueChange={setSignInMethod}>
179
+ <SelectTrigger id="new-user-sign-in-method">
180
+ <SelectValue />
181
+ </SelectTrigger>
182
+ <SelectContent>
183
+ <SelectItem value="password">Password</SelectItem>
184
+ {SOCIAL_PROVIDERS.map((p) => (
185
+ <SelectItem key={p} value={p}>
186
+ {providerLabel[p]}
187
+ </SelectItem>
188
+ ))}
189
+ </SelectContent>
190
+ </Select>
191
+ </Field>
192
+ {!usesPassword ? (
193
+ <Field
194
+ label={handleLabel[signInMethod] ?? `${providerLabel[signInMethod]} account id`}
195
+ htmlFor="new-user-provider-account"
196
+ description={
197
+ handleLabel[signInMethod]
198
+ ? "Their handle on " +
199
+ `${providerLabel[signInMethod]}. Leave blank to match on the email ` +
200
+ "above instead — that only works if the provider reports it as one " +
201
+ "of their verified addresses."
202
+ : "Optional. Leave blank to match on the email above, which the " +
203
+ "provider must report as verified."
204
+ }
205
+ >
206
+ <Input
207
+ id="new-user-provider-account"
208
+ value={providerAccountId}
209
+ onChange={(e) => setProviderAccountId(e.target.value)}
210
+ placeholder={handleLabel[signInMethod] ? "octocat" : ""}
211
+ autoComplete="off"
212
+ />
213
+ </Field>
214
+ ) : null}
215
+ {usesPassword ? (
216
+ <Field
217
+ label="Password"
218
+ htmlFor="new-user-password"
219
+ description="At least 8 characters."
220
+ required
221
+ >
222
+ <Input
223
+ id="new-user-password"
224
+ type="password"
225
+ required
226
+ minLength={8}
227
+ value={password}
228
+ onChange={(e) => setPassword(e.target.value)}
229
+ autoComplete="new-password"
230
+ />
231
+ </Field>
232
+ ) : null}
233
+ <Field label="Role" htmlFor="new-user-role">
234
+ <UserRoleSelect value={role} onChange={setRole} />
235
+ </Field>
236
+ {error ? (
237
+ <Alert variant="destructive">
238
+ <AlertCircle />
239
+ <AlertDescription>{error}</AlertDescription>
240
+ </Alert>
241
+ ) : null}
242
+ <DialogFooter>
243
+ <Button
244
+ type="button"
245
+ variant="ghost"
246
+ onClick={() => setOpen(false)}
247
+ disabled={loading}
248
+ >
249
+ Cancel
250
+ </Button>
251
+ <Button
252
+ type="submit"
253
+ loading={loading}
254
+ disabled={
255
+ !firstName.trim() ||
256
+ !email.trim() ||
257
+ (usesPassword && password.length < 8)
258
+ }
259
+ >
260
+ Create user
261
+ </Button>
262
+ </DialogFooter>
263
+ </form>
264
+ </DialogContent>
265
+ </Dialog>
266
+ );
267
+ };
@@ -0,0 +1,88 @@
1
+ import { type AdminUserRow } from "@nexys/user-management-client";
2
+ import { AlertCircle, Trash2 } from "lucide-react";
3
+ import { useState } from "react";
4
+
5
+ import { useUmClient } from "../../context/auth-context.js";
6
+ import { errorMessage } from "../../lib/error-message.js";
7
+ import { Alert, AlertDescription } from "../ui/alert.js";
8
+ import { Button } from "../ui/button.js";
9
+ import {
10
+ Dialog,
11
+ DialogContent,
12
+ DialogDescription,
13
+ DialogFooter,
14
+ DialogHeader,
15
+ DialogTitle,
16
+ } from "../ui/dialog.js";
17
+
18
+ export interface UserDeleteDialogProps {
19
+ /** The user to delete; null hides the dialog. */
20
+ user: AdminUserRow | null;
21
+ onOpenChange: (open: boolean) => void;
22
+ onDeleted?: () => void;
23
+ }
24
+
25
+ /**
26
+ * Confirm-then-delete (soft delete — the server sets `deletedAt` and
27
+ * revokes the user's sessions; the row stays for audit).
28
+ */
29
+ export const UserDeleteDialog = ({ user, onOpenChange, onDeleted }: UserDeleteDialogProps) => {
30
+ const client = useUmClient();
31
+ const [loading, setLoading] = useState(false);
32
+ const [error, setError] = useState<string | null>(null);
33
+
34
+ const confirm = async () => {
35
+ if (!user) return;
36
+ setLoading(true);
37
+ setError(null);
38
+ const res = await client.adminRemoveUser({ userId: user.id });
39
+ setLoading(false);
40
+ if (res.ok) {
41
+ onDeleted?.();
42
+ onOpenChange(false);
43
+ } else {
44
+ setError(errorMessage(res.error, "Couldn't delete user."));
45
+ }
46
+ };
47
+
48
+ return (
49
+ <Dialog
50
+ open={user !== null}
51
+ onOpenChange={(o) => {
52
+ if (!o) setError(null);
53
+ onOpenChange(o);
54
+ }}
55
+ >
56
+ <DialogContent>
57
+ <DialogHeader>
58
+ <DialogTitle>Delete {user?.name || user?.email}?</DialogTitle>
59
+ <DialogDescription>
60
+ The account is deactivated and all of its sessions are revoked.
61
+ The user can no longer sign in. This keeps the record for audit
62
+ purposes (soft delete).
63
+ </DialogDescription>
64
+ </DialogHeader>
65
+ {error ? (
66
+ <Alert variant="destructive">
67
+ <AlertCircle />
68
+ <AlertDescription>{error}</AlertDescription>
69
+ </Alert>
70
+ ) : null}
71
+ <DialogFooter>
72
+ <Button
73
+ type="button"
74
+ variant="ghost"
75
+ onClick={() => onOpenChange(false)}
76
+ disabled={loading}
77
+ >
78
+ Cancel
79
+ </Button>
80
+ <Button type="button" variant="destructive" onClick={() => void confirm()} loading={loading}>
81
+ <Trash2 />
82
+ Delete user
83
+ </Button>
84
+ </DialogFooter>
85
+ </DialogContent>
86
+ </Dialog>
87
+ );
88
+ };