@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.
- package/README.md +61 -0
- package/components.json +21 -0
- package/package.json +66 -0
- package/src/components/audit/audit-log-table.test.tsx +98 -0
- package/src/components/audit/audit-log-table.tsx +227 -0
- package/src/components/auth/accept-invitation-card.tsx +104 -0
- package/src/components/auth/forgot-password-form.tsx +93 -0
- package/src/components/auth/reset-password-form.tsx +144 -0
- package/src/components/auth/sign-in-form.test.tsx +164 -0
- package/src/components/auth/sign-in-form.tsx +504 -0
- package/src/components/auth/sign-up-form.tsx +124 -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 +238 -0
- package/src/components/profile/change-password-form.tsx +159 -0
- package/src/components/profile/passkeys-card.tsx +186 -0
- package/src/components/profile/profile-card.tsx +107 -0
- package/src/components/profile/refresh-tokens-list.tsx +176 -0
- package/src/components/profile/two-factor-card.tsx +230 -0
- package/src/components/projects/project-consents.tsx +577 -0
- package/src/components/projects/project-create-dialog.tsx +193 -0
- package/src/components/projects/project-detail-tabs.tsx +64 -0
- package/src/components/projects/project-email-templates.tsx +285 -0
- package/src/components/projects/project-notices.tsx +461 -0
- package/src/components/projects/project-settings.tsx +1059 -0
- package/src/components/projects/project-tenants.tsx +108 -0
- package/src/components/projects/projects-table.test.tsx +109 -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 +164 -0
- package/src/components/tenants/tenant-detail-tabs.tsx +51 -0
- package/src/components/tenants/tenant-members.tsx +587 -0
- package/src/components/tenants/tenant-roles.test.tsx +107 -0
- package/src/components/tenants/tenant-roles.tsx +418 -0
- package/src/components/tenants/tenant-settings.tsx +392 -0
- package/src/components/tenants/tenants-table.test.tsx +81 -0
- package/src/components/tenants/tenants-table.tsx +247 -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 +229 -0
- package/src/components/users/user-delete-dialog.tsx +88 -0
- package/src/components/users/user-detail.tsx +818 -0
- package/src/components/users/users-table.test.tsx +107 -0
- package/src/components/users/users-table.tsx +386 -0
- package/src/context/auth-context.tsx +127 -0
- package/src/context/theme-context.test.tsx +78 -0
- package/src/context/theme-context.tsx +110 -0
- package/src/hooks/use-call.ts +60 -0
- package/src/index.ts +160 -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,189 @@
|
|
|
1
|
+
import { Menu, X } from "lucide-react";
|
|
2
|
+
import type { LucideIcon } from "lucide-react";
|
|
3
|
+
import { useState, type ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
import { cn } from "../../lib/utils.js";
|
|
6
|
+
|
|
7
|
+
export interface NavItem {
|
|
8
|
+
key: string;
|
|
9
|
+
label: ReactNode;
|
|
10
|
+
icon?: LucideIcon;
|
|
11
|
+
href?: string;
|
|
12
|
+
active?: boolean;
|
|
13
|
+
badge?: ReactNode;
|
|
14
|
+
onClick?: () => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface NavSection {
|
|
18
|
+
title?: ReactNode;
|
|
19
|
+
items: NavItem[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AppShellProps {
|
|
23
|
+
brand?: ReactNode;
|
|
24
|
+
sections: NavSection[];
|
|
25
|
+
/** Render at the bottom of the sidebar — typically <UserMenu />. */
|
|
26
|
+
sidebarFooter?: ReactNode;
|
|
27
|
+
/** Optional topbar on the right (search, notifications, etc). */
|
|
28
|
+
topbar?: ReactNode;
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
className?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const NavLink = ({
|
|
34
|
+
item,
|
|
35
|
+
onNavigate,
|
|
36
|
+
}: {
|
|
37
|
+
item: NavItem;
|
|
38
|
+
/** Fires after the item's own handler — closes the mobile drawer. */
|
|
39
|
+
onNavigate?: () => void;
|
|
40
|
+
}) => {
|
|
41
|
+
const Icon = item.icon;
|
|
42
|
+
const inner = (
|
|
43
|
+
<>
|
|
44
|
+
{Icon ? <Icon className="size-4 shrink-0" aria-hidden /> : null}
|
|
45
|
+
<span className="flex-1 truncate">{item.label}</span>
|
|
46
|
+
{item.badge ? <span className="ml-auto">{item.badge}</span> : null}
|
|
47
|
+
</>
|
|
48
|
+
);
|
|
49
|
+
const className = cn(
|
|
50
|
+
"group flex items-center gap-2.5 rounded-md px-2.5 py-2 text-sm font-medium transition-colors",
|
|
51
|
+
"text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
52
|
+
item.active && "bg-accent text-foreground"
|
|
53
|
+
);
|
|
54
|
+
if (item.href) {
|
|
55
|
+
return (
|
|
56
|
+
<a
|
|
57
|
+
href={item.href}
|
|
58
|
+
className={className}
|
|
59
|
+
aria-current={item.active ? "page" : undefined}
|
|
60
|
+
onClick={onNavigate}
|
|
61
|
+
>
|
|
62
|
+
{inner}
|
|
63
|
+
</a>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return (
|
|
67
|
+
<button
|
|
68
|
+
type="button"
|
|
69
|
+
onClick={() => {
|
|
70
|
+
item.onClick?.();
|
|
71
|
+
onNavigate?.();
|
|
72
|
+
}}
|
|
73
|
+
className={cn(className, "w-full text-left")}
|
|
74
|
+
aria-current={item.active ? "page" : undefined}
|
|
75
|
+
>
|
|
76
|
+
{inner}
|
|
77
|
+
</button>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const SidebarNav = ({
|
|
82
|
+
sections,
|
|
83
|
+
onNavigate,
|
|
84
|
+
}: {
|
|
85
|
+
sections: NavSection[];
|
|
86
|
+
onNavigate?: () => void;
|
|
87
|
+
}) => (
|
|
88
|
+
<nav className="flex-1 overflow-y-auto px-2 py-4">
|
|
89
|
+
{sections.map((section, i) => (
|
|
90
|
+
<div key={i} className={cn(i > 0 && "mt-6")}>
|
|
91
|
+
{section.title ? (
|
|
92
|
+
<p className="px-2.5 pb-1.5 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
93
|
+
{section.title}
|
|
94
|
+
</p>
|
|
95
|
+
) : null}
|
|
96
|
+
<ul className="grid gap-0.5">
|
|
97
|
+
{section.items.map((item) => (
|
|
98
|
+
<li key={item.key}>
|
|
99
|
+
<NavLink item={item} onNavigate={onNavigate} />
|
|
100
|
+
</li>
|
|
101
|
+
))}
|
|
102
|
+
</ul>
|
|
103
|
+
</div>
|
|
104
|
+
))}
|
|
105
|
+
</nav>
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export const AppShell = ({
|
|
109
|
+
brand,
|
|
110
|
+
sections,
|
|
111
|
+
sidebarFooter,
|
|
112
|
+
topbar,
|
|
113
|
+
children,
|
|
114
|
+
className,
|
|
115
|
+
}: AppShellProps) => {
|
|
116
|
+
// Mobile slide-over drawer — the sidebar is hidden below `md`.
|
|
117
|
+
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
118
|
+
const closeDrawer = () => setDrawerOpen(false);
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<div className={cn("min-h-screen bg-background", className)}>
|
|
122
|
+
<div className="mx-auto grid min-h-screen w-full max-w-[1440px] grid-cols-1 md:grid-cols-[260px_1fr]">
|
|
123
|
+
<aside className="sticky top-0 hidden h-screen flex-col border-r bg-card/50 backdrop-blur md:flex">
|
|
124
|
+
{brand ? (
|
|
125
|
+
<div className="flex h-14 items-center border-b px-4 text-sm font-semibold tracking-tight">
|
|
126
|
+
{brand}
|
|
127
|
+
</div>
|
|
128
|
+
) : null}
|
|
129
|
+
<SidebarNav sections={sections} />
|
|
130
|
+
{sidebarFooter ? (
|
|
131
|
+
<div className="border-t p-2">{sidebarFooter}</div>
|
|
132
|
+
) : null}
|
|
133
|
+
</aside>
|
|
134
|
+
|
|
135
|
+
{/* Mobile drawer + backdrop. Rendered only while open. */}
|
|
136
|
+
{drawerOpen ? (
|
|
137
|
+
<div className="fixed inset-0 z-50 md:hidden" role="dialog" aria-modal="true">
|
|
138
|
+
<div
|
|
139
|
+
className="absolute inset-0 bg-black/40 backdrop-blur-sm"
|
|
140
|
+
onClick={closeDrawer}
|
|
141
|
+
aria-hidden
|
|
142
|
+
/>
|
|
143
|
+
<div className="absolute inset-y-0 left-0 flex w-72 max-w-[85vw] flex-col border-r bg-card shadow-xl">
|
|
144
|
+
<div className="flex h-14 items-center justify-between border-b px-4 text-sm font-semibold tracking-tight">
|
|
145
|
+
<span className="truncate">{brand}</span>
|
|
146
|
+
<button
|
|
147
|
+
type="button"
|
|
148
|
+
onClick={closeDrawer}
|
|
149
|
+
aria-label="Close navigation"
|
|
150
|
+
className="rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
151
|
+
>
|
|
152
|
+
<X className="size-5" />
|
|
153
|
+
</button>
|
|
154
|
+
</div>
|
|
155
|
+
<SidebarNav sections={sections} onNavigate={closeDrawer} />
|
|
156
|
+
{sidebarFooter ? (
|
|
157
|
+
<div className="border-t p-2">{sidebarFooter}</div>
|
|
158
|
+
) : null}
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
) : null}
|
|
162
|
+
|
|
163
|
+
<main className="flex min-h-screen min-w-0 flex-col">
|
|
164
|
+
{/* Mobile header: hamburger + brand. Hidden from `md` up. */}
|
|
165
|
+
<header className="sticky top-0 z-40 flex h-14 items-center gap-3 border-b bg-background/80 px-4 backdrop-blur md:hidden">
|
|
166
|
+
<button
|
|
167
|
+
type="button"
|
|
168
|
+
onClick={() => setDrawerOpen(true)}
|
|
169
|
+
aria-label="Open navigation"
|
|
170
|
+
className="rounded-md p-1.5 text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
171
|
+
>
|
|
172
|
+
<Menu className="size-5" />
|
|
173
|
+
</button>
|
|
174
|
+
<div className="min-w-0 flex-1 truncate text-sm font-semibold tracking-tight">
|
|
175
|
+
{brand}
|
|
176
|
+
</div>
|
|
177
|
+
{topbar}
|
|
178
|
+
</header>
|
|
179
|
+
{topbar ? (
|
|
180
|
+
<header className="sticky top-0 z-30 hidden h-14 items-center justify-end gap-3 border-b bg-background/80 px-6 backdrop-blur md:flex">
|
|
181
|
+
{topbar}
|
|
182
|
+
</header>
|
|
183
|
+
) : null}
|
|
184
|
+
<div className="min-w-0 flex-1 px-4 py-6 sm:px-6">{children}</div>
|
|
185
|
+
</main>
|
|
186
|
+
</div>
|
|
187
|
+
</div>
|
|
188
|
+
);
|
|
189
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
|
|
5
|
+
export interface AuthShellProps {
|
|
6
|
+
brand?: ReactNode;
|
|
7
|
+
footer?: ReactNode;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Centered, slick auth shell. Drops a subtle dotted background so a
|
|
14
|
+
* raw <SignInForm /> still looks like a polished page.
|
|
15
|
+
*/
|
|
16
|
+
export const AuthShell = ({ brand, footer, children, className }: AuthShellProps) => (
|
|
17
|
+
<div
|
|
18
|
+
className={cn(
|
|
19
|
+
"relative flex min-h-screen flex-col items-center justify-center gap-6 bg-background px-4 py-12",
|
|
20
|
+
"before:absolute before:inset-0 before:-z-10 before:bg-[radial-gradient(circle_at_1px_1px,hsl(var(--border))_1px,transparent_0)] before:bg-[size:24px_24px] before:opacity-50",
|
|
21
|
+
className
|
|
22
|
+
)}
|
|
23
|
+
>
|
|
24
|
+
{brand ? <div className="text-sm font-semibold tracking-tight">{brand}</div> : null}
|
|
25
|
+
{children}
|
|
26
|
+
{footer ? <div className="text-xs text-muted-foreground">{footer}</div> : null}
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Check, Monitor, Moon, Sun } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
import { useTheme, type Theme } from "../../context/theme-context.js";
|
|
4
|
+
import { cn } from "../../lib/utils.js";
|
|
5
|
+
import { Button } from "../ui/button.js";
|
|
6
|
+
import {
|
|
7
|
+
DropdownMenu,
|
|
8
|
+
DropdownMenuContent,
|
|
9
|
+
DropdownMenuItem,
|
|
10
|
+
DropdownMenuTrigger,
|
|
11
|
+
} from "../ui/dropdown-menu.js";
|
|
12
|
+
|
|
13
|
+
const OPTIONS: { value: Theme; label: string; icon: typeof Sun }[] = [
|
|
14
|
+
{ value: "light", label: "Light", icon: Sun },
|
|
15
|
+
{ value: "dark", label: "Dark", icon: Moon },
|
|
16
|
+
{ value: "system", label: "System", icon: Monitor },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
export interface ThemeToggleProps {
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Icon button + menu to pick light / dark / system. Needs <ThemeProvider>. */
|
|
24
|
+
export const ThemeToggle = ({ className }: ThemeToggleProps) => {
|
|
25
|
+
const { theme, resolvedTheme, setTheme } = useTheme();
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<DropdownMenu>
|
|
29
|
+
<DropdownMenuTrigger asChild>
|
|
30
|
+
<Button
|
|
31
|
+
variant="ghost"
|
|
32
|
+
size="icon"
|
|
33
|
+
aria-label="Change theme"
|
|
34
|
+
className={cn("text-muted-foreground", className)}
|
|
35
|
+
>
|
|
36
|
+
{resolvedTheme === "dark" ? <Moon /> : <Sun />}
|
|
37
|
+
</Button>
|
|
38
|
+
</DropdownMenuTrigger>
|
|
39
|
+
<DropdownMenuContent align="end" className="w-36">
|
|
40
|
+
{OPTIONS.map(({ value, label, icon: Icon }) => (
|
|
41
|
+
<DropdownMenuItem
|
|
42
|
+
key={value}
|
|
43
|
+
onSelect={() => setTheme(value)}
|
|
44
|
+
aria-checked={theme === value}
|
|
45
|
+
role="menuitemradio"
|
|
46
|
+
>
|
|
47
|
+
<Icon />
|
|
48
|
+
{label}
|
|
49
|
+
{theme === value ? <Check className="ml-auto" /> : null}
|
|
50
|
+
</DropdownMenuItem>
|
|
51
|
+
))}
|
|
52
|
+
</DropdownMenuContent>
|
|
53
|
+
</DropdownMenu>
|
|
54
|
+
);
|
|
55
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ChevronsUpDown, LogOut, type LucideIcon } from "lucide-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import { useAuth } from "../../context/auth-context.js";
|
|
5
|
+
import { initialsOf } from "../../lib/utils.js";
|
|
6
|
+
import { UserRoleBadge } from "../roles/role-badge.js";
|
|
7
|
+
import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar.js";
|
|
8
|
+
import {
|
|
9
|
+
DropdownMenu,
|
|
10
|
+
DropdownMenuContent,
|
|
11
|
+
DropdownMenuItem,
|
|
12
|
+
DropdownMenuLabel,
|
|
13
|
+
DropdownMenuSeparator,
|
|
14
|
+
DropdownMenuTrigger,
|
|
15
|
+
} from "../ui/dropdown-menu.js";
|
|
16
|
+
|
|
17
|
+
export interface UserMenuItem {
|
|
18
|
+
label: ReactNode;
|
|
19
|
+
icon?: LucideIcon;
|
|
20
|
+
onSelect: () => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface UserMenuProps {
|
|
24
|
+
image?: string | null;
|
|
25
|
+
items?: UserMenuItem[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const UserMenu = ({ image, items = [] }: UserMenuProps) => {
|
|
29
|
+
const { data, signOut } = useAuth();
|
|
30
|
+
if (!data) return null;
|
|
31
|
+
const { user } = data;
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<DropdownMenu>
|
|
35
|
+
<DropdownMenuTrigger className="group flex w-full items-center gap-2.5 rounded-md p-2 text-left text-sm transition-colors hover:bg-accent focus:outline-none focus:ring-2 focus:ring-ring/40">
|
|
36
|
+
<Avatar className="size-8">
|
|
37
|
+
{image ? <AvatarImage src={image} alt={user.name ?? user.email} /> : null}
|
|
38
|
+
<AvatarFallback>{initialsOf(user.name, user.email)}</AvatarFallback>
|
|
39
|
+
</Avatar>
|
|
40
|
+
<div className="flex flex-1 flex-col leading-tight">
|
|
41
|
+
<span className="line-clamp-1 font-medium">{user.name ?? user.email}</span>
|
|
42
|
+
<span className="line-clamp-1 text-xs text-muted-foreground">
|
|
43
|
+
{user.email}
|
|
44
|
+
</span>
|
|
45
|
+
</div>
|
|
46
|
+
<ChevronsUpDown className="size-4 text-muted-foreground transition-transform group-data-[state=open]:rotate-180" />
|
|
47
|
+
</DropdownMenuTrigger>
|
|
48
|
+
<DropdownMenuContent align="end" className="w-60">
|
|
49
|
+
<DropdownMenuLabel className="flex flex-col gap-1 text-foreground">
|
|
50
|
+
<span className="text-sm font-medium">{user.name ?? user.email}</span>
|
|
51
|
+
<span className="text-xs font-normal text-muted-foreground">
|
|
52
|
+
{user.email}
|
|
53
|
+
</span>
|
|
54
|
+
<UserRoleBadge role={user.role} className="mt-1 w-fit" />
|
|
55
|
+
</DropdownMenuLabel>
|
|
56
|
+
{items.length > 0 && <DropdownMenuSeparator />}
|
|
57
|
+
{items.map((item, i) => {
|
|
58
|
+
const Icon = item.icon;
|
|
59
|
+
return (
|
|
60
|
+
<DropdownMenuItem
|
|
61
|
+
key={i}
|
|
62
|
+
onSelect={(e) => {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
item.onSelect();
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
{Icon ? <Icon /> : null}
|
|
68
|
+
{item.label}
|
|
69
|
+
</DropdownMenuItem>
|
|
70
|
+
);
|
|
71
|
+
})}
|
|
72
|
+
<DropdownMenuSeparator />
|
|
73
|
+
<DropdownMenuItem
|
|
74
|
+
onSelect={(e) => {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
void signOut();
|
|
77
|
+
}}
|
|
78
|
+
>
|
|
79
|
+
<LogOut /> Sign out
|
|
80
|
+
</DropdownMenuItem>
|
|
81
|
+
</DropdownMenuContent>
|
|
82
|
+
</DropdownMenu>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { LucideIcon } from "lucide-react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
import { cn } from "../../lib/utils.js";
|
|
5
|
+
|
|
6
|
+
export interface EmptyStateProps {
|
|
7
|
+
icon?: LucideIcon;
|
|
8
|
+
title: ReactNode;
|
|
9
|
+
description?: ReactNode;
|
|
10
|
+
action?: ReactNode;
|
|
11
|
+
className?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const EmptyState = ({
|
|
15
|
+
icon: Icon,
|
|
16
|
+
title,
|
|
17
|
+
description,
|
|
18
|
+
action,
|
|
19
|
+
className,
|
|
20
|
+
}: EmptyStateProps) => (
|
|
21
|
+
<div
|
|
22
|
+
className={cn(
|
|
23
|
+
"flex flex-col items-center justify-center gap-3 rounded-xl border border-dashed bg-muted/30 px-6 py-12 text-center",
|
|
24
|
+
className
|
|
25
|
+
)}
|
|
26
|
+
>
|
|
27
|
+
{Icon ? (
|
|
28
|
+
<div className="flex size-11 items-center justify-center rounded-full bg-background shadow-sm">
|
|
29
|
+
<Icon className="size-5 text-muted-foreground" aria-hidden />
|
|
30
|
+
</div>
|
|
31
|
+
) : null}
|
|
32
|
+
<div className="space-y-1">
|
|
33
|
+
<p className="text-base font-medium">{title}</p>
|
|
34
|
+
{description ? (
|
|
35
|
+
<p className="text-sm text-muted-foreground">{description}</p>
|
|
36
|
+
) : null}
|
|
37
|
+
</div>
|
|
38
|
+
{action ? <div className="mt-2">{action}</div> : null}
|
|
39
|
+
</div>
|
|
40
|
+
);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
|
|
5
|
+
export interface PageHeaderProps {
|
|
6
|
+
title: ReactNode;
|
|
7
|
+
description?: ReactNode;
|
|
8
|
+
actions?: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const PageHeader = ({ title, description, actions, className }: PageHeaderProps) => (
|
|
13
|
+
<div
|
|
14
|
+
className={cn(
|
|
15
|
+
"flex flex-col gap-2 border-b pb-5 sm:flex-row sm:items-end sm:justify-between",
|
|
16
|
+
className
|
|
17
|
+
)}
|
|
18
|
+
>
|
|
19
|
+
<div className="space-y-1">
|
|
20
|
+
<h1 className="text-2xl font-semibold tracking-tight">{title}</h1>
|
|
21
|
+
{description ? (
|
|
22
|
+
<p className="text-sm text-muted-foreground">{description}</p>
|
|
23
|
+
) : null}
|
|
24
|
+
</div>
|
|
25
|
+
{actions ? <div className="flex items-center gap-2">{actions}</div> : null}
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Loader2 } from "lucide-react";
|
|
2
|
+
|
|
3
|
+
import { cn } from "../../lib/utils.js";
|
|
4
|
+
|
|
5
|
+
export const Spinner = ({
|
|
6
|
+
className,
|
|
7
|
+
size = "md",
|
|
8
|
+
}: {
|
|
9
|
+
className?: string;
|
|
10
|
+
size?: "sm" | "md" | "lg";
|
|
11
|
+
}) => (
|
|
12
|
+
<Loader2
|
|
13
|
+
aria-hidden
|
|
14
|
+
className={cn(
|
|
15
|
+
"animate-spin text-muted-foreground",
|
|
16
|
+
size === "sm" && "size-4",
|
|
17
|
+
size === "md" && "size-5",
|
|
18
|
+
size === "lg" && "size-8",
|
|
19
|
+
className
|
|
20
|
+
)}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export const FullPageSpinner = () => (
|
|
25
|
+
<div className="flex min-h-[40vh] items-center justify-center">
|
|
26
|
+
<Spinner size="lg" />
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiToken,
|
|
3
|
+
listApiTokens,
|
|
4
|
+
revokeApiToken,
|
|
5
|
+
type ApiTokenCreated,
|
|
6
|
+
type ApiTokenRow,
|
|
7
|
+
} from "@nexys/user-management-client";
|
|
8
|
+
import { AlertCircle, Check, Copy, KeySquare, Plus, ShieldOff } from "lucide-react";
|
|
9
|
+
import { useState, type FormEvent } from "react";
|
|
10
|
+
|
|
11
|
+
import { useUmClient } from "../../context/auth-context.js";
|
|
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 {
|
|
20
|
+
Card,
|
|
21
|
+
CardContent,
|
|
22
|
+
CardDescription,
|
|
23
|
+
CardHeader,
|
|
24
|
+
CardTitle,
|
|
25
|
+
} from "../ui/card.js";
|
|
26
|
+
import { Input } from "../ui/input.js";
|
|
27
|
+
import {
|
|
28
|
+
Table,
|
|
29
|
+
TableBody,
|
|
30
|
+
TableCell,
|
|
31
|
+
TableHead,
|
|
32
|
+
TableHeader,
|
|
33
|
+
TableRow,
|
|
34
|
+
} from "../ui/table.js";
|
|
35
|
+
|
|
36
|
+
const StatusBadge = ({ status }: { status: ApiTokenRow["status"] }) => (
|
|
37
|
+
<Badge variant={status === "active" ? "secondary" : "outline"}>
|
|
38
|
+
{status}
|
|
39
|
+
</Badge>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Personal API tokens — long-lived `um_…` credentials for CLIs and
|
|
44
|
+
* scripts. The plaintext is shown exactly once after creation.
|
|
45
|
+
*/
|
|
46
|
+
export const ApiTokensCard = () => {
|
|
47
|
+
const client = useUmClient();
|
|
48
|
+
const { data, loading, error, refresh } = useCall(listApiTokens);
|
|
49
|
+
const [name, setName] = useState("");
|
|
50
|
+
const [expiresInDays, setExpiresInDays] = useState("");
|
|
51
|
+
const [creating, setCreating] = useState(false);
|
|
52
|
+
const [created, setCreated] = useState<ApiTokenCreated | null>(null);
|
|
53
|
+
const [copied, setCopied] = useState(false);
|
|
54
|
+
const [busy, setBusy] = useState<string | null>(null);
|
|
55
|
+
const [actionError, setActionError] = useState<string | null>(null);
|
|
56
|
+
|
|
57
|
+
const tokens = data?.tokens ?? [];
|
|
58
|
+
|
|
59
|
+
const create = async (e: FormEvent) => {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
setCreating(true);
|
|
62
|
+
setActionError(null);
|
|
63
|
+
const days = expiresInDays.trim() ? Number(expiresInDays.trim()) : undefined;
|
|
64
|
+
const res = await client.call(createApiToken, {
|
|
65
|
+
name: name.trim(),
|
|
66
|
+
expiresInDays: days,
|
|
67
|
+
});
|
|
68
|
+
setCreating(false);
|
|
69
|
+
if (res.ok) {
|
|
70
|
+
setCreated(res.data);
|
|
71
|
+
setName("");
|
|
72
|
+
setExpiresInDays("");
|
|
73
|
+
await refresh();
|
|
74
|
+
} else {
|
|
75
|
+
setActionError(errorMessage(res.error, "Couldn't create the token."));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const revoke = async (t: ApiTokenRow) => {
|
|
80
|
+
setBusy(t.id);
|
|
81
|
+
setActionError(null);
|
|
82
|
+
const res = await client.call(revokeApiToken, { id: t.id });
|
|
83
|
+
setBusy(null);
|
|
84
|
+
if (res.ok) {
|
|
85
|
+
await refresh();
|
|
86
|
+
} else {
|
|
87
|
+
setActionError(errorMessage(res.error, "Couldn't revoke the token."));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const copyToken = async () => {
|
|
92
|
+
if (!created) return;
|
|
93
|
+
await navigator.clipboard.writeText(created.token);
|
|
94
|
+
setCopied(true);
|
|
95
|
+
setTimeout(() => setCopied(false), 2000);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Card>
|
|
100
|
+
<CardHeader>
|
|
101
|
+
<CardTitle className="flex items-center gap-2">
|
|
102
|
+
<KeySquare className="size-4 text-muted-foreground" />
|
|
103
|
+
API tokens
|
|
104
|
+
</CardTitle>
|
|
105
|
+
<CardDescription>
|
|
106
|
+
Long-lived credentials for CLIs and scripts. Use them as{" "}
|
|
107
|
+
<code className="font-mono text-xs">Authorization: Bearer um_…</code>.
|
|
108
|
+
Revoked tokens stay listed until the retention policy removes them.
|
|
109
|
+
</CardDescription>
|
|
110
|
+
</CardHeader>
|
|
111
|
+
<CardContent className="grid gap-4">
|
|
112
|
+
{error ? (
|
|
113
|
+
<Alert variant="destructive">
|
|
114
|
+
<AlertCircle />
|
|
115
|
+
<AlertDescription>{errorMessage(error)}</AlertDescription>
|
|
116
|
+
</Alert>
|
|
117
|
+
) : null}
|
|
118
|
+
{actionError ? (
|
|
119
|
+
<Alert variant="destructive">
|
|
120
|
+
<AlertCircle />
|
|
121
|
+
<AlertDescription>{actionError}</AlertDescription>
|
|
122
|
+
</Alert>
|
|
123
|
+
) : null}
|
|
124
|
+
|
|
125
|
+
{created ? (
|
|
126
|
+
<div className="grid gap-2 rounded-lg border border-dashed bg-muted/30 p-4">
|
|
127
|
+
<p className="text-sm font-medium">
|
|
128
|
+
Copy your new token now — it won't be shown again.
|
|
129
|
+
</p>
|
|
130
|
+
<div className="flex items-center gap-2">
|
|
131
|
+
<code
|
|
132
|
+
data-testid="api-token-plaintext"
|
|
133
|
+
className="flex-1 break-all rounded bg-muted px-2 py-1 font-mono text-xs"
|
|
134
|
+
>
|
|
135
|
+
{created.token}
|
|
136
|
+
</code>
|
|
137
|
+
<Button variant="outline" size="sm" onClick={copyToken}>
|
|
138
|
+
{copied ? <Check className="text-green-600" /> : <Copy />}
|
|
139
|
+
{copied ? "Copied" : "Copy"}
|
|
140
|
+
</Button>
|
|
141
|
+
<Button size="sm" onClick={() => setCreated(null)}>
|
|
142
|
+
Done
|
|
143
|
+
</Button>
|
|
144
|
+
</div>
|
|
145
|
+
</div>
|
|
146
|
+
) : (
|
|
147
|
+
<form
|
|
148
|
+
onSubmit={create}
|
|
149
|
+
className="grid items-end gap-3 sm:grid-cols-[1fr_auto_auto]"
|
|
150
|
+
>
|
|
151
|
+
<div className="grid gap-1.5">
|
|
152
|
+
<label htmlFor="token-name" className="text-sm font-medium leading-none">
|
|
153
|
+
Token name
|
|
154
|
+
</label>
|
|
155
|
+
<Input
|
|
156
|
+
id="token-name"
|
|
157
|
+
required
|
|
158
|
+
value={name}
|
|
159
|
+
onChange={(e) => setName(e.target.value)}
|
|
160
|
+
placeholder="e.g. CLI on work laptop"
|
|
161
|
+
/>
|
|
162
|
+
</div>
|
|
163
|
+
<div className="grid gap-1.5">
|
|
164
|
+
<label htmlFor="token-expiry" className="text-sm font-medium leading-none">
|
|
165
|
+
Expires (days, optional)
|
|
166
|
+
</label>
|
|
167
|
+
<Input
|
|
168
|
+
id="token-expiry"
|
|
169
|
+
type="number"
|
|
170
|
+
min={1}
|
|
171
|
+
max={3650}
|
|
172
|
+
value={expiresInDays}
|
|
173
|
+
onChange={(e) => setExpiresInDays(e.target.value)}
|
|
174
|
+
placeholder="90"
|
|
175
|
+
className="w-36"
|
|
176
|
+
/>
|
|
177
|
+
</div>
|
|
178
|
+
<Button type="submit" loading={creating} disabled={!name.trim()}>
|
|
179
|
+
<Plus />
|
|
180
|
+
Create token
|
|
181
|
+
</Button>
|
|
182
|
+
</form>
|
|
183
|
+
)}
|
|
184
|
+
|
|
185
|
+
{loading ? null : tokens.length === 0 ? (
|
|
186
|
+
<EmptyState
|
|
187
|
+
icon={KeySquare}
|
|
188
|
+
title="No API tokens"
|
|
189
|
+
description="Create one to authenticate scripts and CLI tools."
|
|
190
|
+
/>
|
|
191
|
+
) : (
|
|
192
|
+
<div className="overflow-hidden rounded-lg border">
|
|
193
|
+
<Table>
|
|
194
|
+
<TableHeader>
|
|
195
|
+
<TableRow>
|
|
196
|
+
<TableHead>Name</TableHead>
|
|
197
|
+
<TableHead>Token</TableHead>
|
|
198
|
+
<TableHead>Status</TableHead>
|
|
199
|
+
<TableHead>Last used</TableHead>
|
|
200
|
+
<TableHead className="text-right">Actions</TableHead>
|
|
201
|
+
</TableRow>
|
|
202
|
+
</TableHeader>
|
|
203
|
+
<TableBody>
|
|
204
|
+
{tokens.map((t) => (
|
|
205
|
+
<TableRow key={t.id}>
|
|
206
|
+
<TableCell className="font-medium">{t.name ?? "—"}</TableCell>
|
|
207
|
+
<TableCell className="font-mono text-xs text-muted-foreground">
|
|
208
|
+
{t.start ? `${t.start}…` : "—"}
|
|
209
|
+
</TableCell>
|
|
210
|
+
<TableCell>
|
|
211
|
+
<StatusBadge status={t.status} />
|
|
212
|
+
</TableCell>
|
|
213
|
+
<TableCell className="text-sm text-muted-foreground">
|
|
214
|
+
{t.lastUsedAt ? formatRelative(t.lastUsedAt) : "Never"}
|
|
215
|
+
</TableCell>
|
|
216
|
+
<TableCell className="text-right">
|
|
217
|
+
{t.status === "active" ? (
|
|
218
|
+
<Button
|
|
219
|
+
variant="ghost"
|
|
220
|
+
size="icon"
|
|
221
|
+
onClick={() => revoke(t)}
|
|
222
|
+
loading={busy === t.id}
|
|
223
|
+
aria-label={`Revoke token ${t.name ?? t.id}`}
|
|
224
|
+
>
|
|
225
|
+
<ShieldOff className="text-destructive" />
|
|
226
|
+
</Button>
|
|
227
|
+
) : null}
|
|
228
|
+
</TableCell>
|
|
229
|
+
</TableRow>
|
|
230
|
+
))}
|
|
231
|
+
</TableBody>
|
|
232
|
+
</Table>
|
|
233
|
+
</div>
|
|
234
|
+
)}
|
|
235
|
+
</CardContent>
|
|
236
|
+
</Card>
|
|
237
|
+
);
|
|
238
|
+
};
|