@lukoweb/apitogo-module-user-panel 0.2.38 → 0.2.39
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/package.json +2 -2
- package/src/components/AccountLayout.tsx +135 -119
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lukoweb/apitogo-module-user-panel",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./src/index.tsx"
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/react": "19.2.14",
|
|
16
16
|
"@types/react-dom": "19.2.3",
|
|
17
|
-
"@lukoweb/apitogo": "0.2.
|
|
17
|
+
"@lukoweb/apitogo": "0.2.39",
|
|
18
18
|
"react": "19.2.4",
|
|
19
19
|
"react-dom": "19.2.4",
|
|
20
20
|
"react-router": "7.13.1",
|
|
@@ -1,119 +1,135 @@
|
|
|
1
|
-
import { cn } from "@lukoweb/apitogo";
|
|
2
|
-
import { useAuth } from "@lukoweb/apitogo/hooks";
|
|
3
|
-
import {
|
|
4
|
-
BookOpenIcon,
|
|
5
|
-
CreditCardIcon,
|
|
6
|
-
KeyRoundIcon,
|
|
7
|
-
LayoutGridIcon,
|
|
8
|
-
LogOutIcon,
|
|
9
|
-
SettingsIcon,
|
|
10
|
-
BarChart3Icon,
|
|
11
|
-
} from "@lukoweb/apitogo/icons";
|
|
12
|
-
import { Link, NavLink, Outlet } from "@lukoweb/apitogo/router";
|
|
13
|
-
import type { ReactNode } from "react";
|
|
14
|
-
import {
|
|
15
|
-
buildAccountNavPaths,
|
|
16
|
-
DEFAULT_ACCOUNT_BASE_PATH,
|
|
17
|
-
} from "../account-paths.js";
|
|
18
|
-
|
|
19
|
-
type AccountNavItem = {
|
|
20
|
-
label: string;
|
|
21
|
-
to: string;
|
|
22
|
-
icon: typeof LayoutGridIcon;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export type AccountLayoutProps = {
|
|
26
|
-
basePath?: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
1
|
+
import { cn } from "@lukoweb/apitogo";
|
|
2
|
+
import { useAuth } from "@lukoweb/apitogo/hooks";
|
|
3
|
+
import {
|
|
4
|
+
BookOpenIcon,
|
|
5
|
+
CreditCardIcon,
|
|
6
|
+
KeyRoundIcon,
|
|
7
|
+
LayoutGridIcon,
|
|
8
|
+
LogOutIcon,
|
|
9
|
+
SettingsIcon,
|
|
10
|
+
BarChart3Icon,
|
|
11
|
+
} from "@lukoweb/apitogo/icons";
|
|
12
|
+
import { Link, NavLink, Outlet } from "@lukoweb/apitogo/router";
|
|
13
|
+
import type { ReactNode } from "react";
|
|
14
|
+
import {
|
|
15
|
+
buildAccountNavPaths,
|
|
16
|
+
DEFAULT_ACCOUNT_BASE_PATH,
|
|
17
|
+
} from "../account-paths.js";
|
|
18
|
+
|
|
19
|
+
type AccountNavItem = {
|
|
20
|
+
label: string;
|
|
21
|
+
to: string;
|
|
22
|
+
icon: typeof LayoutGridIcon;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type AccountLayoutProps = {
|
|
26
|
+
basePath?: string;
|
|
27
|
+
/** Where the "Documentation" link goes: a path, an external address, or null for no link (the portal has no docs of its own). */
|
|
28
|
+
docsPath?: string | null;
|
|
29
|
+
/** The "Overview" entry; a portal that does not register the dashboard page leaves it out. */
|
|
30
|
+
includeOverview?: boolean;
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
/** When true, show API keys / Usage / Billing (billing plugin routes). */
|
|
33
|
+
includeBillingNav?: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function AccountLayout({
|
|
37
|
+
basePath = DEFAULT_ACCOUNT_BASE_PATH,
|
|
38
|
+
docsPath = "/introduction",
|
|
39
|
+
includeOverview = true,
|
|
40
|
+
children,
|
|
41
|
+
includeBillingNav = false,
|
|
42
|
+
}: AccountLayoutProps) {
|
|
43
|
+
const auth = useAuth();
|
|
44
|
+
const paths = buildAccountNavPaths(basePath, docsPath ?? undefined);
|
|
45
|
+
|
|
46
|
+
const navItems: AccountNavItem[] = [
|
|
47
|
+
...(includeOverview
|
|
48
|
+
? [{ label: "Overview", to: paths.overview, icon: LayoutGridIcon }]
|
|
49
|
+
: []),
|
|
50
|
+
...(includeBillingNav
|
|
51
|
+
? [
|
|
52
|
+
{ label: "API keys", to: paths.apiKeys, icon: KeyRoundIcon },
|
|
53
|
+
{ label: "Usage", to: paths.usage, icon: BarChart3Icon },
|
|
54
|
+
{ label: "Billing", to: paths.billing, icon: CreditCardIcon },
|
|
55
|
+
]
|
|
56
|
+
: []),
|
|
57
|
+
{ label: "Settings", to: paths.settings, icon: SettingsIcon },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const renderNavLink = (item: AccountNavItem, compact = false) => (
|
|
61
|
+
<NavLink
|
|
62
|
+
key={item.to}
|
|
63
|
+
to={item.to}
|
|
64
|
+
end={item.to === paths.overview}
|
|
65
|
+
className={({ isActive }) =>
|
|
66
|
+
cn(
|
|
67
|
+
compact
|
|
68
|
+
? "inline-flex shrink-0 items-center gap-2 rounded-lg px-3 py-2 text-sm font-medium transition-colors"
|
|
69
|
+
: "flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors",
|
|
70
|
+
isActive
|
|
71
|
+
? "bg-primary/14 font-semibold text-primary"
|
|
72
|
+
: "text-muted-foreground hover:bg-muted/80 hover:text-foreground",
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
>
|
|
76
|
+
<item.icon
|
|
77
|
+
size={compact ? 18 : 20}
|
|
78
|
+
strokeWidth={1.8}
|
|
79
|
+
className="shrink-0 opacity-80"
|
|
80
|
+
/>
|
|
81
|
+
{item.label}
|
|
82
|
+
</NavLink>
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
<div className="flex min-h-[calc(100dvh-var(--header-height))] flex-col bg-muted md:flex-row">
|
|
87
|
+
<nav
|
|
88
|
+
aria-label="Account"
|
|
89
|
+
className="flex gap-1 overflow-x-auto border-b border-border bg-card px-3 py-2 md:hidden"
|
|
90
|
+
>
|
|
91
|
+
{navItems.map((item) => renderNavLink(item, true))}
|
|
92
|
+
</nav>
|
|
93
|
+
|
|
94
|
+
<aside className="hidden w-[236px] shrink-0 flex-col justify-between border-r border-border bg-card px-3 py-4 md:flex">
|
|
95
|
+
<nav className="flex flex-col gap-1">
|
|
96
|
+
{navItems.map((item) => renderNavLink(item))}
|
|
97
|
+
</nav>
|
|
98
|
+
|
|
99
|
+
<div className="flex flex-col gap-1 border-t border-border pt-3">
|
|
100
|
+
{docsPath === null ? null : /^https?:\/\//.test(paths.docs) ? (
|
|
101
|
+
<a
|
|
102
|
+
href={paths.docs}
|
|
103
|
+
className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
|
|
104
|
+
>
|
|
105
|
+
<BookOpenIcon size={20} strokeWidth={1.8} className="shrink-0" />
|
|
106
|
+
Documentation
|
|
107
|
+
</a>
|
|
108
|
+
) : (
|
|
109
|
+
<Link
|
|
110
|
+
to={paths.docs}
|
|
111
|
+
className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
|
|
112
|
+
>
|
|
113
|
+
<BookOpenIcon size={20} strokeWidth={1.8} className="shrink-0" />
|
|
114
|
+
Documentation
|
|
115
|
+
</Link>
|
|
116
|
+
)}
|
|
117
|
+
{auth.isAuthEnabled ? (
|
|
118
|
+
<button
|
|
119
|
+
type="button"
|
|
120
|
+
className="flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-left text-sm font-medium text-muted-foreground transition-colors hover:bg-muted/80 hover:text-foreground"
|
|
121
|
+
onClick={() => {
|
|
122
|
+
void auth.logout();
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
<LogOutIcon size={20} strokeWidth={1.8} className="shrink-0" />
|
|
126
|
+
Log out
|
|
127
|
+
</button>
|
|
128
|
+
) : null}
|
|
129
|
+
</div>
|
|
130
|
+
</aside>
|
|
131
|
+
|
|
132
|
+
<main className="min-w-0 flex-1">{children ?? <Outlet />}</main>
|
|
133
|
+
</div>
|
|
134
|
+
);
|
|
135
|
+
}
|