@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.
- package/README.md +61 -0
- package/components.json +21 -0
- package/package.json +66 -0
- package/src/components/audit/audit-log-table.test.tsx +91 -0
- package/src/components/audit/audit-log-table.tsx +226 -0
- package/src/components/auth/accept-invitation-card.tsx +100 -0
- package/src/components/auth/forgot-password-form.tsx +92 -0
- package/src/components/auth/reset-password-form.tsx +143 -0
- package/src/components/auth/sign-in-form.test.tsx +140 -0
- package/src/components/auth/sign-in-form.tsx +509 -0
- package/src/components/auth/sign-up-form.tsx +123 -0
- package/src/components/layout/app-shell.tsx +189 -0
- package/src/components/layout/auth-shell.tsx +28 -0
- package/src/components/layout/theme-toggle.tsx +55 -0
- package/src/components/layout/user-menu.tsx +84 -0
- package/src/components/primitives/empty-state.tsx +40 -0
- package/src/components/primitives/page-header.tsx +27 -0
- package/src/components/primitives/spinner.tsx +28 -0
- package/src/components/profile/api-tokens-card.tsx +235 -0
- package/src/components/profile/change-password-form.tsx +158 -0
- package/src/components/profile/passkeys-card.tsx +180 -0
- package/src/components/profile/profile-card.tsx +33 -0
- package/src/components/profile/two-factor-card.tsx +226 -0
- package/src/components/projects/project-consents.tsx +572 -0
- package/src/components/projects/project-create-dialog.tsx +209 -0
- package/src/components/projects/project-detail-tabs.tsx +63 -0
- package/src/components/projects/project-email-templates.tsx +282 -0
- package/src/components/projects/project-notices.tsx +458 -0
- package/src/components/projects/project-settings.tsx +1133 -0
- package/src/components/projects/project-tenants.tsx +107 -0
- package/src/components/projects/projects-table.test.tsx +95 -0
- package/src/components/projects/projects-table.tsx +240 -0
- package/src/components/roles/role-badge.tsx +91 -0
- package/src/components/roles/role-select.tsx +76 -0
- package/src/components/tenants/tenant-create-dialog.tsx +163 -0
- package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
- package/src/components/tenants/tenant-members.tsx +578 -0
- package/src/components/tenants/tenant-roles.test.tsx +91 -0
- package/src/components/tenants/tenant-roles.tsx +414 -0
- package/src/components/tenants/tenant-settings.tsx +385 -0
- package/src/components/tenants/tenants-table.test.tsx +71 -0
- package/src/components/tenants/tenants-table.tsx +245 -0
- package/src/components/ui/alert.tsx +52 -0
- package/src/components/ui/avatar.tsx +46 -0
- package/src/components/ui/badge.tsx +32 -0
- package/src/components/ui/button.tsx +64 -0
- package/src/components/ui/card.tsx +65 -0
- package/src/components/ui/dialog.tsx +99 -0
- package/src/components/ui/dropdown-menu.tsx +97 -0
- package/src/components/ui/field.tsx +44 -0
- package/src/components/ui/input.tsx +23 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/select.tsx +87 -0
- package/src/components/ui/separator.tsx +22 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/switch.tsx +29 -0
- package/src/components/ui/table.tsx +87 -0
- package/src/components/ui/tabs.tsx +51 -0
- package/src/components/ui/textarea.tsx +22 -0
- package/src/components/ui/tooltip.tsx +27 -0
- package/src/components/users/user-create-dialog.tsx +267 -0
- package/src/components/users/user-delete-dialog.tsx +88 -0
- package/src/components/users/user-detail.tsx +843 -0
- package/src/components/users/users-table.test.tsx +97 -0
- package/src/components/users/users-table.tsx +382 -0
- package/src/context/auth-context.tsx +124 -0
- package/src/context/theme-context.test.tsx +78 -0
- package/src/context/theme-context.tsx +110 -0
- package/src/hooks/use-call.ts +64 -0
- package/src/index.ts +159 -0
- package/src/lib/error-message.ts +16 -0
- package/src/lib/utils.test.ts +61 -0
- package/src/lib/utils.ts +79 -0
- package/src/lib/webauthn.ts +36 -0
- package/src/styles.css +107 -0
- package/src/test-setup.ts +5 -0
- package/tailwind.preset.cjs +15 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { AlertCircle, Building2, RefreshCcw } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
import { useCall } from "../../hooks/use-call.js";
|
|
4
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
5
|
+
import { formatRelative } from "../../lib/utils.js";
|
|
6
|
+
import { EmptyState } from "../primitives/empty-state.js";
|
|
7
|
+
import { Alert, AlertDescription } from "../ui/alert.js";
|
|
8
|
+
import { Badge } from "../ui/badge.js";
|
|
9
|
+
import { Button } from "../ui/button.js";
|
|
10
|
+
import { Skeleton } from "../ui/skeleton.js";
|
|
11
|
+
import {
|
|
12
|
+
Table,
|
|
13
|
+
TableBody,
|
|
14
|
+
TableCell,
|
|
15
|
+
TableHead,
|
|
16
|
+
TableHeader,
|
|
17
|
+
TableRow,
|
|
18
|
+
} from "../ui/table.js";
|
|
19
|
+
|
|
20
|
+
export interface ProjectTenantsProps {
|
|
21
|
+
projectId: string;
|
|
22
|
+
/** Navigate to a tenant's detail page. */
|
|
23
|
+
onSelectTenant?: (id: string) => void;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const ProjectTenants = ({ projectId, onSelectTenant }: ProjectTenantsProps) => {
|
|
27
|
+
const { data, error, loading, refresh } = useCall("listProjectTenants", { projectId });
|
|
28
|
+
const tenants = data?.tenants ?? [];
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div className="grid gap-3">
|
|
32
|
+
<div className="flex items-center justify-end">
|
|
33
|
+
<Button variant="outline" size="sm" onClick={refresh}>
|
|
34
|
+
<RefreshCcw />
|
|
35
|
+
Refresh
|
|
36
|
+
</Button>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
{error ? (
|
|
40
|
+
<Alert variant="destructive">
|
|
41
|
+
<AlertCircle />
|
|
42
|
+
<AlertDescription>{errorMessage(error)}</AlertDescription>
|
|
43
|
+
</Alert>
|
|
44
|
+
) : null}
|
|
45
|
+
|
|
46
|
+
<div className="overflow-hidden rounded-xl border bg-card">
|
|
47
|
+
<Table>
|
|
48
|
+
<TableHeader>
|
|
49
|
+
<TableRow>
|
|
50
|
+
<TableHead>Tenant</TableHead>
|
|
51
|
+
<TableHead>Slug</TableHead>
|
|
52
|
+
<TableHead>Members</TableHead>
|
|
53
|
+
<TableHead>Created</TableHead>
|
|
54
|
+
</TableRow>
|
|
55
|
+
</TableHeader>
|
|
56
|
+
<TableBody>
|
|
57
|
+
{loading ? (
|
|
58
|
+
Array.from({ length: 3 }).map((_, i) => (
|
|
59
|
+
<TableRow key={`sk-${i}`}>
|
|
60
|
+
<TableCell><Skeleton className="h-4 w-40" /></TableCell>
|
|
61
|
+
<TableCell><Skeleton className="h-4 w-24" /></TableCell>
|
|
62
|
+
<TableCell><Skeleton className="h-4 w-10" /></TableCell>
|
|
63
|
+
<TableCell><Skeleton className="h-4 w-20" /></TableCell>
|
|
64
|
+
</TableRow>
|
|
65
|
+
))
|
|
66
|
+
) : tenants.length === 0 ? (
|
|
67
|
+
<TableRow>
|
|
68
|
+
<TableCell colSpan={4} className="p-0">
|
|
69
|
+
<EmptyState
|
|
70
|
+
icon={Building2}
|
|
71
|
+
title="No tenants yet"
|
|
72
|
+
description="No tenant has been created inside this product."
|
|
73
|
+
className="border-0 rounded-none bg-transparent"
|
|
74
|
+
/>
|
|
75
|
+
</TableCell>
|
|
76
|
+
</TableRow>
|
|
77
|
+
) : (
|
|
78
|
+
tenants.map((t) => (
|
|
79
|
+
<TableRow
|
|
80
|
+
key={t.id}
|
|
81
|
+
className={onSelectTenant ? "cursor-pointer" : undefined}
|
|
82
|
+
onClick={onSelectTenant ? () => onSelectTenant(t.id) : undefined}
|
|
83
|
+
>
|
|
84
|
+
<TableCell>
|
|
85
|
+
<div className="flex items-center gap-2.5">
|
|
86
|
+
<div className="flex size-8 items-center justify-center rounded-md bg-muted text-xs font-semibold uppercase">
|
|
87
|
+
{t.name.slice(0, 2)}
|
|
88
|
+
</div>
|
|
89
|
+
<span className="font-medium">{t.name}</span>
|
|
90
|
+
</div>
|
|
91
|
+
</TableCell>
|
|
92
|
+
<TableCell className="font-mono text-xs">{t.slug}</TableCell>
|
|
93
|
+
<TableCell>
|
|
94
|
+
<Badge variant="muted">{t.memberCount}</Badge>
|
|
95
|
+
</TableCell>
|
|
96
|
+
<TableCell title={t.createdAt} className="text-sm text-muted-foreground">
|
|
97
|
+
{formatRelative(t.createdAt)}
|
|
98
|
+
</TableCell>
|
|
99
|
+
</TableRow>
|
|
100
|
+
))
|
|
101
|
+
)}
|
|
102
|
+
</TableBody>
|
|
103
|
+
</Table>
|
|
104
|
+
</div>
|
|
105
|
+
</div>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
3
|
+
|
|
4
|
+
import { render, screen, waitFor } from "@testing-library/react";
|
|
5
|
+
|
|
6
|
+
import { mockRpc, reply } from "@nexys/user-management-client/testing";
|
|
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 rpc = mockRpc((p) => {
|
|
47
|
+
if (p === "me") {
|
|
48
|
+
return reply({ code: "unauth" }, 401);
|
|
49
|
+
}
|
|
50
|
+
if (p === "listProjects") {
|
|
51
|
+
return reply({ projects: PROJECTS });
|
|
52
|
+
}
|
|
53
|
+
return reply({ error: "not_found" }, 404);
|
|
54
|
+
});
|
|
55
|
+
const client = rpc.client;
|
|
56
|
+
|
|
57
|
+
render(
|
|
58
|
+
<AuthProvider client={client} refreshIntervalMs={0}>
|
|
59
|
+
<ProjectsTable />
|
|
60
|
+
</AuthProvider>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
await waitFor(() => {
|
|
64
|
+
expect(screen.getByText("Digis")).toBeTruthy();
|
|
65
|
+
});
|
|
66
|
+
expect(screen.getByText("Internal Tools")).toBeTruthy();
|
|
67
|
+
expect(screen.getByText("multi")).toBeTruthy();
|
|
68
|
+
expect(screen.getByText("single")).toBeTruthy();
|
|
69
|
+
expect(screen.getByText("open")).toBeTruthy();
|
|
70
|
+
expect(screen.getByText("closed")).toBeTruthy();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("shows the empty state when no projects exist", async () => {
|
|
74
|
+
const rpc = mockRpc((p) => {
|
|
75
|
+
if (p === "me") {
|
|
76
|
+
return reply({ code: "unauth" }, 401);
|
|
77
|
+
}
|
|
78
|
+
if (p === "listProjects") {
|
|
79
|
+
return reply({ projects: [] });
|
|
80
|
+
}
|
|
81
|
+
return reply({ error: "not_found" }, 404);
|
|
82
|
+
});
|
|
83
|
+
const client = rpc.client;
|
|
84
|
+
|
|
85
|
+
render(
|
|
86
|
+
<AuthProvider client={client} refreshIntervalMs={0}>
|
|
87
|
+
<ProjectsTable />
|
|
88
|
+
</AuthProvider>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
await waitFor(() => {
|
|
92
|
+
expect(screen.getByText("No products yet")).toBeTruthy();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { 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
|
+
);
|