@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,108 @@
1
+ import { listProjectTenants } from "@nexys/user-management-client";
2
+ import { AlertCircle, Building2, RefreshCcw } from "lucide-react";
3
+
4
+ import { useCall } from "../../hooks/use-call.js";
5
+ import { errorMessage } from "../../lib/error-message.js";
6
+ import { formatRelative } from "../../lib/utils.js";
7
+ import { EmptyState } from "../primitives/empty-state.js";
8
+ import { Alert, AlertDescription } from "../ui/alert.js";
9
+ import { Badge } from "../ui/badge.js";
10
+ import { Button } from "../ui/button.js";
11
+ import { Skeleton } from "../ui/skeleton.js";
12
+ import {
13
+ Table,
14
+ TableBody,
15
+ TableCell,
16
+ TableHead,
17
+ TableHeader,
18
+ TableRow,
19
+ } from "../ui/table.js";
20
+
21
+ export interface ProjectTenantsProps {
22
+ projectId: string;
23
+ /** Navigate to a tenant's detail page. */
24
+ onSelectTenant?: (id: string) => void;
25
+ }
26
+
27
+ export const ProjectTenants = ({ projectId, onSelectTenant }: ProjectTenantsProps) => {
28
+ const { data, error, loading, refresh } = useCall(listProjectTenants, { projectId });
29
+ const tenants = data?.tenants ?? [];
30
+
31
+ return (
32
+ <div className="grid gap-3">
33
+ <div className="flex items-center justify-end">
34
+ <Button variant="outline" size="sm" onClick={refresh}>
35
+ <RefreshCcw />
36
+ Refresh
37
+ </Button>
38
+ </div>
39
+
40
+ {error ? (
41
+ <Alert variant="destructive">
42
+ <AlertCircle />
43
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
44
+ </Alert>
45
+ ) : null}
46
+
47
+ <div className="overflow-hidden rounded-xl border bg-card">
48
+ <Table>
49
+ <TableHeader>
50
+ <TableRow>
51
+ <TableHead>Tenant</TableHead>
52
+ <TableHead>Slug</TableHead>
53
+ <TableHead>Members</TableHead>
54
+ <TableHead>Created</TableHead>
55
+ </TableRow>
56
+ </TableHeader>
57
+ <TableBody>
58
+ {loading ? (
59
+ Array.from({ length: 3 }).map((_, i) => (
60
+ <TableRow key={`sk-${i}`}>
61
+ <TableCell><Skeleton className="h-4 w-40" /></TableCell>
62
+ <TableCell><Skeleton className="h-4 w-24" /></TableCell>
63
+ <TableCell><Skeleton className="h-4 w-10" /></TableCell>
64
+ <TableCell><Skeleton className="h-4 w-20" /></TableCell>
65
+ </TableRow>
66
+ ))
67
+ ) : tenants.length === 0 ? (
68
+ <TableRow>
69
+ <TableCell colSpan={4} className="p-0">
70
+ <EmptyState
71
+ icon={Building2}
72
+ title="No tenants yet"
73
+ description="No tenant has been created inside this product."
74
+ className="border-0 rounded-none bg-transparent"
75
+ />
76
+ </TableCell>
77
+ </TableRow>
78
+ ) : (
79
+ tenants.map((t) => (
80
+ <TableRow
81
+ key={t.id}
82
+ className={onSelectTenant ? "cursor-pointer" : undefined}
83
+ onClick={onSelectTenant ? () => onSelectTenant(t.id) : undefined}
84
+ >
85
+ <TableCell>
86
+ <div className="flex items-center gap-2.5">
87
+ <div className="flex size-8 items-center justify-center rounded-md bg-muted text-xs font-semibold uppercase">
88
+ {t.name.slice(0, 2)}
89
+ </div>
90
+ <span className="font-medium">{t.name}</span>
91
+ </div>
92
+ </TableCell>
93
+ <TableCell className="font-mono text-xs">{t.slug}</TableCell>
94
+ <TableCell>
95
+ <Badge variant="muted">{t.memberCount}</Badge>
96
+ </TableCell>
97
+ <TableCell title={t.createdAt} className="text-sm text-muted-foreground">
98
+ {formatRelative(t.createdAt)}
99
+ </TableCell>
100
+ </TableRow>
101
+ ))
102
+ )}
103
+ </TableBody>
104
+ </Table>
105
+ </div>
106
+ </div>
107
+ );
108
+ };
@@ -0,0 +1,109 @@
1
+ /// <reference lib="dom" />
2
+ import { afterEach, describe, expect, mock, test } from "bun:test";
3
+
4
+ import { render, screen, waitFor } from "@testing-library/react";
5
+
6
+ import { createClient } from "@nexys/user-management-client";
7
+
8
+ import { AuthProvider } from "../../context/auth-context.js";
9
+ import { ProjectsTable } from "./projects-table.js";
10
+
11
+ const PROJECTS = [
12
+ {
13
+ id: "p1",
14
+ name: "Digis",
15
+ slug: "digis",
16
+ ownerUserId: "u1",
17
+ tenancyMode: "multi",
18
+ allowTenantCreation: true,
19
+ allowSignup: true,
20
+ metadata: null,
21
+ tenantCount: 3,
22
+ createdAt: "2026-01-01T00:00:00Z",
23
+ updatedAt: "2026-01-01T00:00:00Z",
24
+ },
25
+ {
26
+ id: "p2",
27
+ name: "Internal Tools",
28
+ slug: "internal-tools",
29
+ ownerUserId: "u1",
30
+ tenancyMode: "single",
31
+ allowTenantCreation: false,
32
+ allowSignup: false,
33
+ metadata: null,
34
+ tenantCount: 1,
35
+ createdAt: "2026-02-01T00:00:00Z",
36
+ updatedAt: "2026-02-01T00:00:00Z",
37
+ },
38
+ ];
39
+
40
+ afterEach(() => {
41
+ document.body.innerHTML = "";
42
+ });
43
+
44
+ describe("<ProjectsTable />", () => {
45
+ test("renders projects with tenancy and sign-up state", async () => {
46
+ const fetcher = mock(async (input: RequestInfo | URL) => {
47
+ const url = input.toString();
48
+ if (url.endsWith("/api/me")) {
49
+ return new Response(JSON.stringify({ code: "unauth" }), { status: 401 });
50
+ }
51
+ if (url.endsWith("/api/projects")) {
52
+ return new Response(JSON.stringify({ projects: PROJECTS }), {
53
+ status: 200,
54
+ headers: { "content-type": "application/json" },
55
+ });
56
+ }
57
+ return new Response("nope", { status: 404 });
58
+ });
59
+ const client = createClient({
60
+ baseUrl: "https://auth.example.com",
61
+ fetch: fetcher as unknown as typeof fetch,
62
+ });
63
+
64
+ render(
65
+ <AuthProvider client={client} refreshIntervalMs={0}>
66
+ <ProjectsTable />
67
+ </AuthProvider>
68
+ );
69
+
70
+ await waitFor(() => {
71
+ expect(screen.getByText("Digis")).toBeTruthy();
72
+ });
73
+ expect(screen.getByText("Internal Tools")).toBeTruthy();
74
+ expect(screen.getByText("multi")).toBeTruthy();
75
+ expect(screen.getByText("single")).toBeTruthy();
76
+ expect(screen.getByText("open")).toBeTruthy();
77
+ expect(screen.getByText("closed")).toBeTruthy();
78
+ });
79
+
80
+ test("shows the empty state when no projects exist", async () => {
81
+ const fetcher = mock(async (input: RequestInfo | URL) => {
82
+ const url = input.toString();
83
+ if (url.endsWith("/api/me")) {
84
+ return new Response(JSON.stringify({ code: "unauth" }), { status: 401 });
85
+ }
86
+ if (url.endsWith("/api/projects")) {
87
+ return new Response(JSON.stringify({ projects: [] }), {
88
+ status: 200,
89
+ headers: { "content-type": "application/json" },
90
+ });
91
+ }
92
+ return new Response("nope", { status: 404 });
93
+ });
94
+ const client = createClient({
95
+ baseUrl: "https://auth.example.com",
96
+ fetch: fetcher as unknown as typeof fetch,
97
+ });
98
+
99
+ render(
100
+ <AuthProvider client={client} refreshIntervalMs={0}>
101
+ <ProjectsTable />
102
+ </AuthProvider>
103
+ );
104
+
105
+ await waitFor(() => {
106
+ expect(screen.getByText("No products yet")).toBeTruthy();
107
+ });
108
+ });
109
+ });
@@ -0,0 +1,240 @@
1
+ import { listProjects, type ProjectRow } from "@nexys/user-management-client";
2
+ import {
3
+ AlertCircle,
4
+ ArrowUpDown,
5
+ Boxes,
6
+ ListFilter,
7
+ RefreshCcw,
8
+ Search,
9
+ } from "lucide-react";
10
+ import { useMemo, useState } from "react";
11
+
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 { Input } from "../ui/input.js";
20
+ import {
21
+ Select,
22
+ SelectContent,
23
+ SelectItem,
24
+ SelectTrigger,
25
+ SelectValue,
26
+ } from "../ui/select.js";
27
+ import { Skeleton } from "../ui/skeleton.js";
28
+ import {
29
+ Table,
30
+ TableBody,
31
+ TableCell,
32
+ TableHead,
33
+ TableHeader,
34
+ TableRow,
35
+ } from "../ui/table.js";
36
+ import { ProjectCreateDialog } from "./project-create-dialog.js";
37
+
38
+ const SORT_OPTIONS: {
39
+ value: string;
40
+ label: string;
41
+ compare: (a: ProjectRow, b: ProjectRow) => number;
42
+ }[] = [
43
+ {
44
+ value: "name-asc",
45
+ label: "Name A–Z",
46
+ compare: (a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: "base" }),
47
+ },
48
+ {
49
+ value: "name-desc",
50
+ label: "Name Z–A",
51
+ compare: (a, b) => b.name.localeCompare(a.name, undefined, { sensitivity: "base" }),
52
+ },
53
+ { value: "created-desc", label: "Newest first", compare: (a, b) => b.createdAt.localeCompare(a.createdAt) },
54
+ { value: "created-asc", label: "Oldest first", compare: (a, b) => a.createdAt.localeCompare(b.createdAt) },
55
+ { value: "tenants-desc", label: "Most tenants", compare: (a, b) => (b.tenantCount ?? 0) - (a.tenantCount ?? 0) },
56
+ ];
57
+
58
+ const SIGNUP_OPTIONS: { value: string; label: string }[] = [
59
+ { value: "all", label: "All sign-up" },
60
+ { value: "open", label: "Sign-up open" },
61
+ { value: "closed", label: "Sign-up closed" },
62
+ ];
63
+
64
+ export const ProjectsTable = ({
65
+ allowCreate = true,
66
+ onSelect,
67
+ }: {
68
+ allowCreate?: boolean;
69
+ onSelect?: (id: string) => void;
70
+ }) => {
71
+ const [query, setQuery] = useState("");
72
+ const [sort, setSort] = useState("name-asc");
73
+ const [signupFilter, setSignupFilter] = useState("all");
74
+ const { data, error, loading, refresh } = useCall(listProjects);
75
+
76
+ const filtered = useMemo(() => {
77
+ let list = data?.projects ?? [];
78
+ if (signupFilter !== "all") {
79
+ list = list.filter((p) => p.allowSignup === (signupFilter === "open"));
80
+ }
81
+ const q = query.trim().toLowerCase();
82
+ if (q) {
83
+ list = list.filter(
84
+ (p) =>
85
+ p.name.toLowerCase().includes(q) ||
86
+ p.slug.toLowerCase().includes(q) ||
87
+ p.id.toLowerCase().includes(q)
88
+ );
89
+ }
90
+ const compare = (SORT_OPTIONS.find((o) => o.value === sort) ?? SORT_OPTIONS[0]!)
91
+ .compare;
92
+ return [...list].sort(compare);
93
+ }, [data, query, signupFilter, sort]);
94
+
95
+ const filterActive = signupFilter !== "all";
96
+
97
+ return (
98
+ <div className="grid gap-3">
99
+ <div className="flex flex-wrap items-center justify-between gap-2">
100
+ <div className="relative min-w-[14rem] max-w-sm flex-1">
101
+ <Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
102
+ <Input
103
+ value={query}
104
+ onChange={(e) => setQuery(e.target.value)}
105
+ placeholder="Search products…"
106
+ className="pl-9"
107
+ />
108
+ </div>
109
+ <div className="flex flex-wrap items-center gap-2">
110
+ <Select value={signupFilter} onValueChange={setSignupFilter}>
111
+ <SelectTrigger
112
+ className="h-8 w-[10rem]"
113
+ aria-label="Filter by sign-up"
114
+ >
115
+ <ListFilter className="size-3.5 text-muted-foreground" />
116
+ <SelectValue />
117
+ </SelectTrigger>
118
+ <SelectContent>
119
+ {SIGNUP_OPTIONS.map((o) => (
120
+ <SelectItem key={o.value} value={o.value}>
121
+ {o.label}
122
+ </SelectItem>
123
+ ))}
124
+ </SelectContent>
125
+ </Select>
126
+ <Select value={sort} onValueChange={setSort}>
127
+ <SelectTrigger className="h-8 w-[9.5rem]" aria-label="Sort by">
128
+ <ArrowUpDown className="size-3.5 text-muted-foreground" />
129
+ <SelectValue />
130
+ </SelectTrigger>
131
+ <SelectContent>
132
+ {SORT_OPTIONS.map((o) => (
133
+ <SelectItem key={o.value} value={o.value}>
134
+ {o.label}
135
+ </SelectItem>
136
+ ))}
137
+ </SelectContent>
138
+ </Select>
139
+ <Button variant="outline" size="sm" onClick={refresh}>
140
+ <RefreshCcw />
141
+ Refresh
142
+ </Button>
143
+ {allowCreate ? <ProjectCreateDialog onCreated={refresh} /> : null}
144
+ </div>
145
+ </div>
146
+
147
+ {error ? (
148
+ <Alert variant="destructive">
149
+ <AlertCircle />
150
+ <AlertDescription>{errorMessage(error)}</AlertDescription>
151
+ </Alert>
152
+ ) : null}
153
+
154
+ <div className="overflow-hidden rounded-xl border bg-card">
155
+ <Table>
156
+ <TableHeader>
157
+ <TableRow>
158
+ <TableHead>Product</TableHead>
159
+ <TableHead>Slug</TableHead>
160
+ <TableHead>Tenancy</TableHead>
161
+ <TableHead>Sign-up</TableHead>
162
+ <TableHead>Tenants</TableHead>
163
+ <TableHead>Created</TableHead>
164
+ </TableRow>
165
+ </TableHeader>
166
+ <TableBody>
167
+ {loading ? (
168
+ Array.from({ length: 4 }).map((_, i) => (
169
+ <TableRow key={`sk-${i}`}>
170
+ <TableCell><Skeleton className="h-4 w-40" /></TableCell>
171
+ <TableCell><Skeleton className="h-4 w-24" /></TableCell>
172
+ <TableCell><Skeleton className="h-4 w-16" /></TableCell>
173
+ <TableCell><Skeleton className="h-4 w-12" /></TableCell>
174
+ <TableCell><Skeleton className="h-4 w-10" /></TableCell>
175
+ <TableCell><Skeleton className="h-4 w-20" /></TableCell>
176
+ </TableRow>
177
+ ))
178
+ ) : filtered.length === 0 ? (
179
+ <TableRow>
180
+ <TableCell colSpan={6} className="p-0">
181
+ <EmptyState
182
+ icon={Boxes}
183
+ title={
184
+ query || filterActive ? "No products match" : "No products yet"
185
+ }
186
+ description={
187
+ query || filterActive
188
+ ? "Try a different search or filter."
189
+ : "Create the first product to get started."
190
+ }
191
+ className="border-0 rounded-none bg-transparent"
192
+ action={
193
+ !query && !filterActive && allowCreate ? (
194
+ <ProjectCreateDialog onCreated={refresh} />
195
+ ) : undefined
196
+ }
197
+ />
198
+ </TableCell>
199
+ </TableRow>
200
+ ) : (
201
+ filtered.map((p) => (
202
+ <TableRow
203
+ key={p.id}
204
+ className={onSelect ? "cursor-pointer" : undefined}
205
+ onClick={onSelect ? () => onSelect(p.id) : undefined}
206
+ >
207
+ <TableCell>
208
+ <div className="flex items-center gap-2.5">
209
+ <div className="flex size-8 items-center justify-center rounded-md bg-muted text-xs font-semibold uppercase">
210
+ {p.name.slice(0, 2)}
211
+ </div>
212
+ <span className="font-medium">{p.name}</span>
213
+ </div>
214
+ </TableCell>
215
+ <TableCell className="font-mono text-xs">{p.slug}</TableCell>
216
+ <TableCell>
217
+ <Badge variant="muted" className="capitalize">
218
+ {p.tenancyMode}
219
+ </Badge>
220
+ </TableCell>
221
+ <TableCell>
222
+ <Badge variant={p.allowSignup ? "default" : "muted"}>
223
+ {p.allowSignup ? "open" : "closed"}
224
+ </Badge>
225
+ </TableCell>
226
+ <TableCell>
227
+ <Badge variant="muted">{p.tenantCount ?? 0}</Badge>
228
+ </TableCell>
229
+ <TableCell title={p.createdAt} className="text-sm text-muted-foreground">
230
+ {formatRelative(p.createdAt)}
231
+ </TableCell>
232
+ </TableRow>
233
+ ))
234
+ )}
235
+ </TableBody>
236
+ </Table>
237
+ </div>
238
+ </div>
239
+ );
240
+ };
@@ -0,0 +1,91 @@
1
+ import type { TenantRole, UserRole, UserStatus } from "@nexys/user-management-client";
2
+ import {
3
+ Crown,
4
+ ShieldCheck,
5
+ ShieldHalf,
6
+ User,
7
+ UserCog,
8
+ type LucideIcon,
9
+ } from "lucide-react";
10
+
11
+ import { cn } from "../../lib/utils.js";
12
+ import { Badge, badgeVariants } from "../ui/badge.js";
13
+
14
+ type Variant = NonNullable<Parameters<typeof Badge>[0]["variant"]>;
15
+
16
+ const userRoleMeta: Record<string, { label: string; variant: Variant; icon: LucideIcon }> = {
17
+ superadmin: { label: "Superadmin", variant: "destructive", icon: ShieldCheck },
18
+ useradmin: { label: "User admin", variant: "warning", icon: UserCog },
19
+ user: { label: "User", variant: "secondary", icon: User },
20
+ };
21
+
22
+ const tenantRoleMeta: Record<string, { label: string; variant: Variant; icon: LucideIcon }> = {
23
+ owner: { label: "Owner", variant: "default", icon: Crown },
24
+ admin: { label: "Admin", variant: "warning", icon: ShieldHalf },
25
+ member: { label: "Member", variant: "muted", icon: User },
26
+ };
27
+
28
+ const statusMeta: Record<string, { variant: Variant }> = {
29
+ active: { variant: "success" },
30
+ pending: { variant: "warning" },
31
+ inactive: { variant: "muted" },
32
+ };
33
+
34
+ export const UserRoleBadge = ({
35
+ role,
36
+ className,
37
+ }: {
38
+ role: UserRole;
39
+ className?: string;
40
+ }) => {
41
+ const meta = userRoleMeta[role] ?? {
42
+ label: role,
43
+ variant: "outline" as Variant,
44
+ icon: User,
45
+ };
46
+ const Icon = meta.icon;
47
+ return (
48
+ <Badge variant={meta.variant} className={cn("capitalize", className)}>
49
+ <Icon className="size-3" aria-hidden />
50
+ {meta.label}
51
+ </Badge>
52
+ );
53
+ };
54
+
55
+ export const TenantRoleBadge = ({
56
+ role,
57
+ className,
58
+ }: {
59
+ role: TenantRole;
60
+ className?: string;
61
+ }) => {
62
+ const meta = tenantRoleMeta[role] ?? {
63
+ label: role,
64
+ variant: "outline" as Variant,
65
+ icon: User,
66
+ };
67
+ const Icon = meta.icon;
68
+ return (
69
+ <Badge variant={meta.variant} className={cn("capitalize", className)}>
70
+ <Icon className="size-3" aria-hidden />
71
+ {meta.label}
72
+ </Badge>
73
+ );
74
+ };
75
+
76
+ export const StatusBadge = ({
77
+ status,
78
+ className,
79
+ }: {
80
+ status: UserStatus;
81
+ className?: string;
82
+ }) => {
83
+ const variant = statusMeta[status]?.variant ?? "outline";
84
+ return (
85
+ <Badge variant={variant} className={cn("capitalize", className)}>
86
+ {status}
87
+ </Badge>
88
+ );
89
+ };
90
+
91
+ void badgeVariants; // re-export marker for tree-shaking analysers
@@ -0,0 +1,76 @@
1
+ import type { TenantRole, UserRole } from "@nexys/user-management-client";
2
+
3
+ import {
4
+ Select,
5
+ SelectContent,
6
+ SelectItem,
7
+ SelectTrigger,
8
+ SelectValue,
9
+ } from "../ui/select.js";
10
+
11
+ export interface UserRoleSelectProps {
12
+ value: UserRole;
13
+ onChange: (next: UserRole) => void;
14
+ disabled?: boolean;
15
+ /** Restrict assignable roles — defaults to user/useradmin/superadmin. */
16
+ options?: ReadonlyArray<UserRole>;
17
+ }
18
+
19
+ const DEFAULT_USER_ROLES: ReadonlyArray<UserRole> = ["user", "useradmin", "superadmin"];
20
+
21
+ export const UserRoleSelect = ({
22
+ value,
23
+ onChange,
24
+ disabled,
25
+ options = DEFAULT_USER_ROLES,
26
+ }: UserRoleSelectProps) => (
27
+ <Select
28
+ value={value}
29
+ onValueChange={(v) => onChange(v as UserRole)}
30
+ disabled={disabled}
31
+ >
32
+ <SelectTrigger className="h-8 w-[10.5rem]">
33
+ <SelectValue />
34
+ </SelectTrigger>
35
+ <SelectContent>
36
+ {options.map((r) => (
37
+ <SelectItem key={r} value={r} className="capitalize">
38
+ {r}
39
+ </SelectItem>
40
+ ))}
41
+ </SelectContent>
42
+ </Select>
43
+ );
44
+
45
+ export interface TenantRoleSelectProps {
46
+ value: TenantRole;
47
+ onChange: (next: TenantRole) => void;
48
+ disabled?: boolean;
49
+ options?: ReadonlyArray<TenantRole>;
50
+ }
51
+
52
+ const DEFAULT_TENANT_ROLES: ReadonlyArray<TenantRole> = ["member", "admin", "owner"];
53
+
54
+ export const TenantRoleSelect = ({
55
+ value,
56
+ onChange,
57
+ disabled,
58
+ options = DEFAULT_TENANT_ROLES,
59
+ }: TenantRoleSelectProps) => (
60
+ <Select
61
+ value={value}
62
+ onValueChange={(v) => onChange(v as TenantRole)}
63
+ disabled={disabled}
64
+ >
65
+ <SelectTrigger className="h-8 w-[10.5rem]">
66
+ <SelectValue />
67
+ </SelectTrigger>
68
+ <SelectContent>
69
+ {options.map((r) => (
70
+ <SelectItem key={r} value={r} className="capitalize">
71
+ {r}
72
+ </SelectItem>
73
+ ))}
74
+ </SelectContent>
75
+ </Select>
76
+ );