@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
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# `@nexys/user-management-web`
|
|
2
|
+
|
|
3
|
+
Modern React + Tailwind v4 + shadcn (new-york / stone) UI kit for the
|
|
4
|
+
`user-management-rs` service. Depends on `@nexys/user-management-client`
|
|
5
|
+
via the workspace protocol — both packages live in this repo.
|
|
6
|
+
|
|
7
|
+
## Surface (six core domains)
|
|
8
|
+
|
|
9
|
+
- **Auth**: `<SignInForm />`, `<SignUpForm />`, `<ForgotPasswordForm />`
|
|
10
|
+
- **Profile**: `<ProfileCard />`, `<ChangePasswordForm />`
|
|
11
|
+
- **Users (admin)**: `<UsersTable />` — search, status flips, role select, token revoke
|
|
12
|
+
- **Tenants**: `<TenantsTable />`, `<TenantCreateDialog />`, `<TenantMembers />` (invite + role)
|
|
13
|
+
- **Roles**: `<UserRoleBadge />`, `<TenantRoleBadge />`, `<StatusBadge />`, `<UserRoleSelect />`, `<TenantRoleSelect />`
|
|
14
|
+
- **Layout**: `<AppShell />` (sidebar + topbar), `<AuthShell />` (centred), `<UserMenu />`
|
|
15
|
+
|
|
16
|
+
Plus the shadcn primitives the kit composes from (button, input, card,
|
|
17
|
+
dialog, select, dropdown-menu, tabs, alert, badge, avatar, table,
|
|
18
|
+
skeleton, switch, tooltip, separator, label, field).
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import {
|
|
24
|
+
AppShell,
|
|
25
|
+
AuthProvider,
|
|
26
|
+
UmClient,
|
|
27
|
+
UserMenu,
|
|
28
|
+
UsersTable,
|
|
29
|
+
} from "@nexys/user-management-web";
|
|
30
|
+
import "@nexys/user-management-web/styles.css";
|
|
31
|
+
|
|
32
|
+
const client = new UmClient({ baseUrl: import.meta.env.VITE_API_URL });
|
|
33
|
+
|
|
34
|
+
export const App = () => (
|
|
35
|
+
<AuthProvider client={client}>
|
|
36
|
+
<AppShell
|
|
37
|
+
brand="Acme"
|
|
38
|
+
sidebarFooter={<UserMenu />}
|
|
39
|
+
sections={[
|
|
40
|
+
{ items: [{ key: "profile", label: "Profile", href: "/profile" }] },
|
|
41
|
+
{ title: "Admin", items: [{ key: "users", label: "Users", href: "/admin/users" }] },
|
|
42
|
+
]}
|
|
43
|
+
>
|
|
44
|
+
<UsersTable />
|
|
45
|
+
</AppShell>
|
|
46
|
+
</AuthProvider>
|
|
47
|
+
);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Tailwind v4
|
|
51
|
+
|
|
52
|
+
Design tokens ship in `src/styles.css` (`@theme` block). Import the
|
|
53
|
+
stylesheet, then either include the package source in your build's
|
|
54
|
+
`@source` glob or use the exported preset (`./tailwind-preset`).
|
|
55
|
+
|
|
56
|
+
## Tests
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
bun test # bun + happy-dom (preloaded via bunfig.toml)
|
|
60
|
+
bun run typecheck
|
|
61
|
+
```
|
package/components.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://ui.shadcn.com/schema.json",
|
|
3
|
+
"style": "new-york",
|
|
4
|
+
"rsc": false,
|
|
5
|
+
"tsx": true,
|
|
6
|
+
"tailwind": {
|
|
7
|
+
"config": "",
|
|
8
|
+
"css": "src/styles.css",
|
|
9
|
+
"baseColor": "stone",
|
|
10
|
+
"cssVariables": true,
|
|
11
|
+
"prefix": ""
|
|
12
|
+
},
|
|
13
|
+
"aliases": {
|
|
14
|
+
"components": "@/components",
|
|
15
|
+
"utils": "@/lib/utils",
|
|
16
|
+
"ui": "@/components/ui",
|
|
17
|
+
"lib": "@/lib",
|
|
18
|
+
"hooks": "@/hooks"
|
|
19
|
+
},
|
|
20
|
+
"iconLibrary": "lucide"
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexys/user-management-web",
|
|
3
|
+
"version": "0.0.26",
|
|
4
|
+
"description": "Modern, slick React + Tailwind + shadcn UI kit for the Nexys user-management service. Built on @nexys/user-management-client.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"sideEffects": [
|
|
8
|
+
"**/*.css"
|
|
9
|
+
],
|
|
10
|
+
"main": "./src/index.ts",
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./src/index.ts",
|
|
15
|
+
"default": "./src/index.ts"
|
|
16
|
+
},
|
|
17
|
+
"./styles.css": "./src/styles.css",
|
|
18
|
+
"./tailwind-preset": "./tailwind.preset.cjs"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"tailwind.preset.cjs",
|
|
23
|
+
"components.json",
|
|
24
|
+
"README.md"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"test": "bun test",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": ">=18",
|
|
32
|
+
"react-dom": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@hookform/resolvers": "^3.10.0",
|
|
36
|
+
"@nexys/user-management-client": "^0.0.26",
|
|
37
|
+
"@radix-ui/react-avatar": "^1.1.4",
|
|
38
|
+
"@radix-ui/react-dialog": "^1.1.14",
|
|
39
|
+
"@radix-ui/react-dropdown-menu": "^2.1.7",
|
|
40
|
+
"@radix-ui/react-label": "^2.1.2",
|
|
41
|
+
"@radix-ui/react-select": "^2.1.6",
|
|
42
|
+
"@radix-ui/react-separator": "^1.1.2",
|
|
43
|
+
"@radix-ui/react-slot": "^1.2.0",
|
|
44
|
+
"@radix-ui/react-switch": "^1.1.3",
|
|
45
|
+
"@radix-ui/react-tabs": "^1.1.3",
|
|
46
|
+
"@radix-ui/react-tooltip": "^1.2.0",
|
|
47
|
+
"class-variance-authority": "^0.7.1",
|
|
48
|
+
"clsx": "^2.1.1",
|
|
49
|
+
"lucide-react": "^0.487.0",
|
|
50
|
+
"qrcode.react": "^4.2.0",
|
|
51
|
+
"react-hook-form": "^7.54.2",
|
|
52
|
+
"tailwind-merge": "^3.2.0",
|
|
53
|
+
"zod": "^3.24.1"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@happy-dom/global-registrator": "^15.11.6",
|
|
57
|
+
"@testing-library/react": "^16.1.0",
|
|
58
|
+
"@types/bun": "^1.2.2",
|
|
59
|
+
"@types/react": "^18.3.5",
|
|
60
|
+
"@types/react-dom": "^18.3.0",
|
|
61
|
+
"react": "^18.3.1",
|
|
62
|
+
"react-dom": "^18.3.1",
|
|
63
|
+
"tailwindcss": "^4.1.3",
|
|
64
|
+
"typescript": "^5.2.2"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 { AuditLogTable } from "./audit-log-table.js";
|
|
10
|
+
|
|
11
|
+
const ROWS = [
|
|
12
|
+
{
|
|
13
|
+
id: "a1",
|
|
14
|
+
action: "auth.sign_in",
|
|
15
|
+
actorId: "u1",
|
|
16
|
+
actorEmail: "johan@example.com",
|
|
17
|
+
actorType: "user",
|
|
18
|
+
resourceType: "user",
|
|
19
|
+
resourceId: "u1",
|
|
20
|
+
organizationId: null,
|
|
21
|
+
ipAddress: "203.0.113.7",
|
|
22
|
+
userAgent: "curl",
|
|
23
|
+
metadata: null,
|
|
24
|
+
success: true,
|
|
25
|
+
createdAt: "2026-08-01T10:00:00Z",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "a2",
|
|
29
|
+
action: "auth.sign_in",
|
|
30
|
+
actorId: null,
|
|
31
|
+
actorEmail: "intruder@example.com",
|
|
32
|
+
actorType: "user",
|
|
33
|
+
resourceType: null,
|
|
34
|
+
resourceId: null,
|
|
35
|
+
organizationId: null,
|
|
36
|
+
ipAddress: "198.51.100.9",
|
|
37
|
+
userAgent: "curl",
|
|
38
|
+
metadata: null,
|
|
39
|
+
success: false,
|
|
40
|
+
createdAt: "2026-08-01T09:00:00Z",
|
|
41
|
+
},
|
|
42
|
+
];
|
|
43
|
+
|
|
44
|
+
afterEach(() => {
|
|
45
|
+
document.body.innerHTML = "";
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const clientFor = (rows: unknown[], total: number) => {
|
|
49
|
+
const rpc = mockRpc((p) => {
|
|
50
|
+
if (p === "me") {
|
|
51
|
+
return reply({ code: "unauth" }, 401);
|
|
52
|
+
}
|
|
53
|
+
if (p === "adminListAuditLogs") {
|
|
54
|
+
return reply({ total, rows });
|
|
55
|
+
}
|
|
56
|
+
return reply({ error: "not_found" }, 404);
|
|
57
|
+
});
|
|
58
|
+
return rpc.client;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
describe("<AuditLogTable />", () => {
|
|
62
|
+
test("renders log rows with actor, ip and result", async () => {
|
|
63
|
+
render(
|
|
64
|
+
<AuthProvider client={clientFor(ROWS, 2)} refreshIntervalMs={0}>
|
|
65
|
+
<AuditLogTable />
|
|
66
|
+
</AuthProvider>
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
await waitFor(() => {
|
|
70
|
+
expect(screen.getByText("johan@example.com")).toBeTruthy();
|
|
71
|
+
});
|
|
72
|
+
expect(screen.getAllByText("auth.sign_in")).toHaveLength(2);
|
|
73
|
+
expect(screen.getByText("203.0.113.7")).toBeTruthy();
|
|
74
|
+
expect(screen.getByText("ok")).toBeTruthy();
|
|
75
|
+
expect(screen.getByText("failed")).toBeTruthy();
|
|
76
|
+
expect(screen.getByText("1–2 of 2")).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test("shows the empty state when there are no entries", async () => {
|
|
80
|
+
render(
|
|
81
|
+
<AuthProvider client={clientFor([], 0)} refreshIntervalMs={0}>
|
|
82
|
+
<AuditLogTable />
|
|
83
|
+
</AuthProvider>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
await waitFor(() => {
|
|
87
|
+
expect(screen.getByText("No log entries yet")).toBeTruthy();
|
|
88
|
+
});
|
|
89
|
+
expect(screen.getByText("0 entries")).toBeTruthy();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlertCircle,
|
|
3
|
+
ChevronLeft,
|
|
4
|
+
ChevronRight,
|
|
5
|
+
RefreshCcw,
|
|
6
|
+
ScrollText,
|
|
7
|
+
Search,
|
|
8
|
+
} from "lucide-react";
|
|
9
|
+
import { useState } from "react";
|
|
10
|
+
|
|
11
|
+
import { useCall } from "../../hooks/use-call.js";
|
|
12
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
13
|
+
import { formatRelative } from "../../lib/utils.js";
|
|
14
|
+
import { EmptyState } from "../primitives/empty-state.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 { Input } from "../ui/input.js";
|
|
19
|
+
import { Skeleton } from "../ui/skeleton.js";
|
|
20
|
+
import {
|
|
21
|
+
Table,
|
|
22
|
+
TableBody,
|
|
23
|
+
TableCell,
|
|
24
|
+
TableHead,
|
|
25
|
+
TableHeader,
|
|
26
|
+
TableRow,
|
|
27
|
+
} from "../ui/table.js";
|
|
28
|
+
|
|
29
|
+
const PAGE_SIZE = 50;
|
|
30
|
+
|
|
31
|
+
/** What sign-in rows carry in `metadata` (see the server's auth routes). */
|
|
32
|
+
interface AuthMetadata {
|
|
33
|
+
method?: string;
|
|
34
|
+
secondFactor?: string;
|
|
35
|
+
provider?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const METHOD_LABELS: Record<string, string> = {
|
|
39
|
+
password: "Password",
|
|
40
|
+
passkey: "Passkey",
|
|
41
|
+
social: "Social",
|
|
42
|
+
magic_link: "Magic link",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* How the account authenticated, for rows that record it — sign-ins
|
|
47
|
+
* carry `{ method, secondFactor?, provider? }`. Returns null for the
|
|
48
|
+
* many actions that aren't authentications, so the cell stays quiet
|
|
49
|
+
* rather than showing a dash for every admin action.
|
|
50
|
+
*/
|
|
51
|
+
const authMethod = (metadata: unknown): string | null => {
|
|
52
|
+
if (typeof metadata !== "object" || metadata === null) return null;
|
|
53
|
+
const m = metadata as AuthMetadata;
|
|
54
|
+
if (typeof m.method !== "string") return null;
|
|
55
|
+
|
|
56
|
+
const base = METHOD_LABELS[m.method] ?? m.method;
|
|
57
|
+
if (m.method === "social" && m.provider) {
|
|
58
|
+
return `${base} · ${m.provider}`;
|
|
59
|
+
}
|
|
60
|
+
if (m.secondFactor) {
|
|
61
|
+
// The second factor is the interesting part of a 2FA sign-in.
|
|
62
|
+
const factor = m.secondFactor === "backup_code" ? "backup code" : m.secondFactor;
|
|
63
|
+
return `${base} + ${factor}`;
|
|
64
|
+
}
|
|
65
|
+
return base;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* System-wide access log (superadmin). Server-side filtering by action
|
|
70
|
+
* prefix (e.g. `auth.`, `user.`, `tenant.`) plus offset pagination.
|
|
71
|
+
*/
|
|
72
|
+
export const AuditLogTable = () => {
|
|
73
|
+
// The input is applied on Enter/blur via `filter` so typing doesn't
|
|
74
|
+
// refetch on every keystroke.
|
|
75
|
+
const [query, setQuery] = useState("");
|
|
76
|
+
const [filter, setFilter] = useState("");
|
|
77
|
+
const [offset, setOffset] = useState(0);
|
|
78
|
+
const { data, error, loading, refresh } = useCall("adminListAuditLogs", {
|
|
79
|
+
actionPrefix: filter || undefined,
|
|
80
|
+
limit: PAGE_SIZE,
|
|
81
|
+
offset,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const rows = data?.rows ?? [];
|
|
85
|
+
const total = data?.total ?? 0;
|
|
86
|
+
const applyFilter = () => {
|
|
87
|
+
setOffset(0);
|
|
88
|
+
setFilter(query.trim());
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<div className="grid gap-3">
|
|
93
|
+
<div className="flex flex-wrap items-center justify-between gap-2">
|
|
94
|
+
<div className="relative min-w-[12rem] max-w-sm flex-1">
|
|
95
|
+
<Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
|
|
96
|
+
<Input
|
|
97
|
+
value={query}
|
|
98
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
99
|
+
onBlur={applyFilter}
|
|
100
|
+
onKeyDown={(e) => {
|
|
101
|
+
if (e.key === "Enter") applyFilter();
|
|
102
|
+
}}
|
|
103
|
+
placeholder="Filter by action prefix (auth., user., …)"
|
|
104
|
+
className="pl-9"
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
<Button variant="outline" size="sm" onClick={refresh}>
|
|
108
|
+
<RefreshCcw />
|
|
109
|
+
Refresh
|
|
110
|
+
</Button>
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
{error ? (
|
|
114
|
+
<Alert variant="destructive">
|
|
115
|
+
<AlertCircle />
|
|
116
|
+
<AlertDescription>{errorMessage(error)}</AlertDescription>
|
|
117
|
+
</Alert>
|
|
118
|
+
) : null}
|
|
119
|
+
|
|
120
|
+
<div className="overflow-hidden rounded-xl border bg-card">
|
|
121
|
+
<Table>
|
|
122
|
+
<TableHeader>
|
|
123
|
+
<TableRow>
|
|
124
|
+
<TableHead>When</TableHead>
|
|
125
|
+
<TableHead>Action</TableHead>
|
|
126
|
+
<TableHead>Method</TableHead>
|
|
127
|
+
<TableHead>Actor</TableHead>
|
|
128
|
+
<TableHead>Resource</TableHead>
|
|
129
|
+
<TableHead>IP</TableHead>
|
|
130
|
+
<TableHead>Result</TableHead>
|
|
131
|
+
</TableRow>
|
|
132
|
+
</TableHeader>
|
|
133
|
+
<TableBody>
|
|
134
|
+
{loading ? (
|
|
135
|
+
Array.from({ length: 6 }).map((_, i) => (
|
|
136
|
+
<TableRow key={`sk-${i}`}>
|
|
137
|
+
<TableCell><Skeleton className="h-4 w-20" /></TableCell>
|
|
138
|
+
<TableCell><Skeleton className="h-4 w-32" /></TableCell>
|
|
139
|
+
<TableCell><Skeleton className="h-4 w-24" /></TableCell>
|
|
140
|
+
<TableCell><Skeleton className="h-4 w-40" /></TableCell>
|
|
141
|
+
<TableCell><Skeleton className="h-4 w-28" /></TableCell>
|
|
142
|
+
<TableCell><Skeleton className="h-4 w-24" /></TableCell>
|
|
143
|
+
<TableCell><Skeleton className="h-4 w-12" /></TableCell>
|
|
144
|
+
</TableRow>
|
|
145
|
+
))
|
|
146
|
+
) : rows.length === 0 ? (
|
|
147
|
+
<TableRow>
|
|
148
|
+
<TableCell colSpan={7} className="p-0">
|
|
149
|
+
<EmptyState
|
|
150
|
+
icon={ScrollText}
|
|
151
|
+
title={filter ? "No matching entries" : "No log entries yet"}
|
|
152
|
+
description={
|
|
153
|
+
filter
|
|
154
|
+
? "Try a different action prefix."
|
|
155
|
+
: "Authentication and admin activity will appear here."
|
|
156
|
+
}
|
|
157
|
+
className="border-0 rounded-none bg-transparent"
|
|
158
|
+
/>
|
|
159
|
+
</TableCell>
|
|
160
|
+
</TableRow>
|
|
161
|
+
) : (
|
|
162
|
+
rows.map((r) => (
|
|
163
|
+
<TableRow key={r.id}>
|
|
164
|
+
<TableCell
|
|
165
|
+
title={r.createdAt}
|
|
166
|
+
className="whitespace-nowrap text-sm text-muted-foreground"
|
|
167
|
+
>
|
|
168
|
+
{formatRelative(r.createdAt)}
|
|
169
|
+
</TableCell>
|
|
170
|
+
<TableCell className="font-mono text-xs">{r.action}</TableCell>
|
|
171
|
+
<TableCell className="whitespace-nowrap text-xs text-muted-foreground">
|
|
172
|
+
{authMethod(r.metadata) ?? ""}
|
|
173
|
+
</TableCell>
|
|
174
|
+
<TableCell className="max-w-[14rem] truncate text-sm">
|
|
175
|
+
{r.actorEmail ?? r.actorId ?? "—"}
|
|
176
|
+
</TableCell>
|
|
177
|
+
<TableCell className="max-w-[12rem] truncate font-mono text-xs text-muted-foreground">
|
|
178
|
+
{r.resourceType
|
|
179
|
+
? `${r.resourceType}${r.resourceId ? `:${r.resourceId}` : ""}`
|
|
180
|
+
: "—"}
|
|
181
|
+
</TableCell>
|
|
182
|
+
<TableCell className="whitespace-nowrap font-mono text-xs text-muted-foreground">
|
|
183
|
+
{r.ipAddress ?? "—"}
|
|
184
|
+
</TableCell>
|
|
185
|
+
<TableCell>
|
|
186
|
+
<Badge variant={r.success ? "muted" : "destructive"}>
|
|
187
|
+
{r.success ? "ok" : "failed"}
|
|
188
|
+
</Badge>
|
|
189
|
+
</TableCell>
|
|
190
|
+
</TableRow>
|
|
191
|
+
))
|
|
192
|
+
)}
|
|
193
|
+
</TableBody>
|
|
194
|
+
</Table>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div className="flex items-center justify-between gap-2">
|
|
198
|
+
<p className="text-xs text-muted-foreground">
|
|
199
|
+
{total > 0
|
|
200
|
+
? `${offset + 1}–${Math.min(offset + PAGE_SIZE, total)} of ${total}`
|
|
201
|
+
: "0 entries"}
|
|
202
|
+
</p>
|
|
203
|
+
<div className="flex items-center gap-2">
|
|
204
|
+
<Button
|
|
205
|
+
variant="outline"
|
|
206
|
+
size="sm"
|
|
207
|
+
disabled={offset === 0 || loading}
|
|
208
|
+
onClick={() => setOffset(Math.max(0, offset - PAGE_SIZE))}
|
|
209
|
+
>
|
|
210
|
+
<ChevronLeft />
|
|
211
|
+
Newer
|
|
212
|
+
</Button>
|
|
213
|
+
<Button
|
|
214
|
+
variant="outline"
|
|
215
|
+
size="sm"
|
|
216
|
+
disabled={offset + PAGE_SIZE >= total || loading}
|
|
217
|
+
onClick={() => setOffset(offset + PAGE_SIZE)}
|
|
218
|
+
>
|
|
219
|
+
Older
|
|
220
|
+
<ChevronRight />
|
|
221
|
+
</Button>
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
);
|
|
226
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AlertCircle, Building2, Check } from "lucide-react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
|
|
4
|
+
import { useUmClient } from "../../context/auth-context.js";
|
|
5
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
6
|
+
import { Alert, AlertDescription } from "../ui/alert.js";
|
|
7
|
+
import { Button } from "../ui/button.js";
|
|
8
|
+
import {
|
|
9
|
+
Card,
|
|
10
|
+
CardContent,
|
|
11
|
+
CardDescription,
|
|
12
|
+
CardHeader,
|
|
13
|
+
CardTitle,
|
|
14
|
+
} from "../ui/card.js";
|
|
15
|
+
|
|
16
|
+
export interface AcceptInvitationCardProps {
|
|
17
|
+
invitationId: string;
|
|
18
|
+
/** Called after the invitation is accepted and the tenant activated. */
|
|
19
|
+
onAccepted?: (organizationId: string) => void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Accepts a tenant invitation from an emailed link. Requires the
|
|
24
|
+
* viewer to be signed in with the invited email — the server enforces
|
|
25
|
+
* the match. On success the new tenant is made active.
|
|
26
|
+
*/
|
|
27
|
+
export const AcceptInvitationCard = ({
|
|
28
|
+
invitationId,
|
|
29
|
+
onAccepted,
|
|
30
|
+
}: AcceptInvitationCardProps) => {
|
|
31
|
+
const client = useUmClient();
|
|
32
|
+
const [loading, setLoading] = useState(false);
|
|
33
|
+
const [error, setError] = useState<string | null>(null);
|
|
34
|
+
const [accepted, setAccepted] = useState(false);
|
|
35
|
+
|
|
36
|
+
const accept = async () => {
|
|
37
|
+
setLoading(true);
|
|
38
|
+
setError(null);
|
|
39
|
+
const res = await client.acceptInvitation({ invitationId });
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
setLoading(false);
|
|
42
|
+
setError(
|
|
43
|
+
errorMessage(
|
|
44
|
+
res.error,
|
|
45
|
+
"This invitation is invalid, expired, or was sent to a different email address."
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
// Make the new tenant active right away so the user lands in it.
|
|
51
|
+
await client.setActiveTenant({
|
|
52
|
+
organizationId: res.data.organizationId,
|
|
53
|
+
});
|
|
54
|
+
setLoading(false);
|
|
55
|
+
setAccepted(true);
|
|
56
|
+
onAccepted?.(res.data.organizationId);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (accepted) {
|
|
60
|
+
return (
|
|
61
|
+
<Card className="w-full max-w-md">
|
|
62
|
+
<CardHeader className="space-y-1.5">
|
|
63
|
+
<CardTitle className="flex items-center gap-2 text-2xl">
|
|
64
|
+
<Check className="size-5 text-green-600" />
|
|
65
|
+
You're in
|
|
66
|
+
</CardTitle>
|
|
67
|
+
<CardDescription>
|
|
68
|
+
The invitation was accepted and the tenant is now active.
|
|
69
|
+
</CardDescription>
|
|
70
|
+
</CardHeader>
|
|
71
|
+
</Card>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Card className="w-full max-w-md">
|
|
77
|
+
<CardHeader className="space-y-1.5">
|
|
78
|
+
<CardTitle className="flex items-center gap-2 text-2xl">
|
|
79
|
+
<Building2 className="size-5 text-muted-foreground" />
|
|
80
|
+
Tenant invitation
|
|
81
|
+
</CardTitle>
|
|
82
|
+
<CardDescription>
|
|
83
|
+
You've been invited to join a tenant. Accepting adds this account as
|
|
84
|
+
a member.
|
|
85
|
+
</CardDescription>
|
|
86
|
+
</CardHeader>
|
|
87
|
+
<CardContent className="grid gap-4">
|
|
88
|
+
{error ? (
|
|
89
|
+
<Alert variant="destructive">
|
|
90
|
+
<AlertCircle />
|
|
91
|
+
<AlertDescription>{error}</AlertDescription>
|
|
92
|
+
</Alert>
|
|
93
|
+
) : null}
|
|
94
|
+
<Button onClick={accept} loading={loading} className="w-full">
|
|
95
|
+
Accept invitation
|
|
96
|
+
</Button>
|
|
97
|
+
</CardContent>
|
|
98
|
+
</Card>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { AlertCircle, MailCheck } from "lucide-react";
|
|
2
|
+
import { useState, type FormEvent, type ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import { useUmClient } from "../../context/auth-context.js";
|
|
5
|
+
import { errorMessage } from "../../lib/error-message.js";
|
|
6
|
+
import { Alert, AlertDescription } from "../ui/alert.js";
|
|
7
|
+
import { Button } from "../ui/button.js";
|
|
8
|
+
import {
|
|
9
|
+
Card,
|
|
10
|
+
CardContent,
|
|
11
|
+
CardDescription,
|
|
12
|
+
CardHeader,
|
|
13
|
+
CardTitle,
|
|
14
|
+
} from "../ui/card.js";
|
|
15
|
+
import { Field } from "../ui/field.js";
|
|
16
|
+
import { Input } from "../ui/input.js";
|
|
17
|
+
|
|
18
|
+
export interface ForgotPasswordFormProps {
|
|
19
|
+
onSent?: (email: string) => void;
|
|
20
|
+
signInSlot?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const ForgotPasswordForm = ({ onSent, signInSlot }: ForgotPasswordFormProps) => {
|
|
24
|
+
const client = useUmClient();
|
|
25
|
+
const [email, setEmail] = useState("");
|
|
26
|
+
const [loading, setLoading] = useState(false);
|
|
27
|
+
const [sent, setSent] = useState(false);
|
|
28
|
+
const [error, setError] = useState<string | null>(null);
|
|
29
|
+
|
|
30
|
+
const submit = async (e: FormEvent) => {
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
setLoading(true);
|
|
33
|
+
setError(null);
|
|
34
|
+
const trimmed = email.trim();
|
|
35
|
+
const res = await client.requestPasswordReset({ email: trimmed });
|
|
36
|
+
setLoading(false);
|
|
37
|
+
if (res.ok) {
|
|
38
|
+
setSent(true);
|
|
39
|
+
onSent?.(trimmed);
|
|
40
|
+
} else {
|
|
41
|
+
setError(errorMessage(res.error, "Could not send reset email."));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Card className="w-full max-w-md">
|
|
47
|
+
<CardHeader className="space-y-1.5">
|
|
48
|
+
<CardTitle className="text-2xl">Reset your password</CardTitle>
|
|
49
|
+
<CardDescription>
|
|
50
|
+
Enter your email and we'll send you a link to choose a new password.
|
|
51
|
+
</CardDescription>
|
|
52
|
+
</CardHeader>
|
|
53
|
+
<CardContent>
|
|
54
|
+
{sent ? (
|
|
55
|
+
<Alert variant="success">
|
|
56
|
+
<MailCheck />
|
|
57
|
+
<AlertDescription>
|
|
58
|
+
If an account exists for <strong>{email}</strong>, we've just sent it a
|
|
59
|
+
reset link. Check your inbox.
|
|
60
|
+
</AlertDescription>
|
|
61
|
+
</Alert>
|
|
62
|
+
) : (
|
|
63
|
+
<form onSubmit={submit} className="grid gap-4" noValidate>
|
|
64
|
+
<Field label="Email" htmlFor="email" required>
|
|
65
|
+
<Input
|
|
66
|
+
id="email"
|
|
67
|
+
type="email"
|
|
68
|
+
required
|
|
69
|
+
autoComplete="email"
|
|
70
|
+
value={email}
|
|
71
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
72
|
+
placeholder="you@example.com"
|
|
73
|
+
/>
|
|
74
|
+
</Field>
|
|
75
|
+
{error ? (
|
|
76
|
+
<Alert variant="destructive">
|
|
77
|
+
<AlertCircle />
|
|
78
|
+
<AlertDescription>{error}</AlertDescription>
|
|
79
|
+
</Alert>
|
|
80
|
+
) : null}
|
|
81
|
+
<Button type="submit" className="w-full" loading={loading}>
|
|
82
|
+
Send reset link
|
|
83
|
+
</Button>
|
|
84
|
+
{signInSlot ? (
|
|
85
|
+
<p className="text-center text-sm text-muted-foreground">{signInSlot}</p>
|
|
86
|
+
) : null}
|
|
87
|
+
</form>
|
|
88
|
+
)}
|
|
89
|
+
</CardContent>
|
|
90
|
+
</Card>
|
|
91
|
+
);
|
|
92
|
+
};
|