@lukoweb/apitogo-module-user-panel 0.2.73 → 0.2.75
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 -135
- package/src/userPanelModule.tsx +188 -182
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.75",
|
|
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.75",
|
|
18
18
|
"react": "19.2.4",
|
|
19
19
|
"react-dom": "19.2.4",
|
|
20
20
|
"react-router": "7.13.1",
|
|
@@ -1,135 +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
|
-
/** 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
|
-
}
|
|
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
|
+
}
|
package/src/userPanelModule.tsx
CHANGED
|
@@ -1,182 +1,188 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ResolvedDashboardModule,
|
|
3
|
-
ResolvedPlansModule,
|
|
4
|
-
ResolvedUserManagementModule,
|
|
5
|
-
ResolvedUserPanelModule,
|
|
6
|
-
} from "@lukoweb/apitogo";
|
|
7
|
-
import {
|
|
8
|
-
CreditCardIcon,
|
|
9
|
-
LayoutDashboardIcon,
|
|
10
|
-
SettingsIcon,
|
|
11
|
-
} from "@lukoweb/apitogo/icons";
|
|
12
|
-
import type {
|
|
13
|
-
ProfileMenuPlugin,
|
|
14
|
-
ApitogoPlugin,
|
|
15
|
-
} from "@lukoweb/apitogo/plugins";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
1
|
+
import type {
|
|
2
|
+
ResolvedDashboardModule,
|
|
3
|
+
ResolvedPlansModule,
|
|
4
|
+
ResolvedUserManagementModule,
|
|
5
|
+
ResolvedUserPanelModule,
|
|
6
|
+
} from "@lukoweb/apitogo";
|
|
7
|
+
import {
|
|
8
|
+
CreditCardIcon,
|
|
9
|
+
LayoutDashboardIcon,
|
|
10
|
+
SettingsIcon,
|
|
11
|
+
} from "@lukoweb/apitogo/icons";
|
|
12
|
+
import type {
|
|
13
|
+
ProfileMenuPlugin,
|
|
14
|
+
ApitogoPlugin,
|
|
15
|
+
} from "@lukoweb/apitogo/plugins";
|
|
16
|
+
// The portal's own router, through the core package: a `react-router` of this module's own can be a second copy
|
|
17
|
+
// whose <Navigate> sees no router, which crashed the prerender of `/account/your-plan` (API-110, CI e2e).
|
|
18
|
+
import { Navigate, type RouteObject } from "@lukoweb/apitogo/router";
|
|
19
|
+
import type { ComponentType, ReactNode } from "react";
|
|
20
|
+
import { toAccountChildPath } from "./account-paths.js";
|
|
21
|
+
import { AccountLayout } from "./components/AccountLayout.js";
|
|
22
|
+
import { DefaultDashboardPage } from "./pages/DefaultDashboardPage.js";
|
|
23
|
+
import { DefaultPlansPage } from "./pages/DefaultPlansPage.js";
|
|
24
|
+
import { SettingsPage } from "./pages/SettingsPage.js";
|
|
25
|
+
import { renderModuleElement } from "./renderModuleElement.js";
|
|
26
|
+
|
|
27
|
+
type DashboardModuleOptions = ResolvedDashboardModule & {
|
|
28
|
+
component?: ComponentType | ReactNode;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
type UserManagementModuleOptions = ResolvedUserManagementModule & {
|
|
32
|
+
component?: ComponentType | ReactNode;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type PlansModuleOptions = ResolvedPlansModule & {
|
|
36
|
+
component?: ComponentType | ReactNode;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type UserPanelModuleOptions = ResolvedUserPanelModule & {
|
|
40
|
+
dashboard: DashboardModuleOptions;
|
|
41
|
+
userManagement: UserManagementModuleOptions;
|
|
42
|
+
plans: PlansModuleOptions;
|
|
43
|
+
/**
|
|
44
|
+
* The billing plugin is on: it owns the plans page (`/account/plans`), so this module registers no placeholder of its
|
|
45
|
+
* own, and its pages show the billing plugin's side menu (API keys, Usage, Billing, Settings).
|
|
46
|
+
*/
|
|
47
|
+
billingNav?: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** The billing plugin's plans page, where "Plans" leads once that plugin is on. */
|
|
51
|
+
const BILLING_PLANS_PATH = "/account/plans";
|
|
52
|
+
|
|
53
|
+
const protectAccountRoute = (
|
|
54
|
+
protectedRoutes: string[],
|
|
55
|
+
enabled: boolean,
|
|
56
|
+
path: string,
|
|
57
|
+
) => {
|
|
58
|
+
if (enabled) {
|
|
59
|
+
protectedRoutes.push(path);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const userPanelModule = (
|
|
64
|
+
options: UserPanelModuleOptions,
|
|
65
|
+
): (ApitogoPlugin & ProfileMenuPlugin) | undefined => {
|
|
66
|
+
if (!options.enabled) {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const routes: RouteObject[] = [];
|
|
71
|
+
const protectedRoutes: string[] = [];
|
|
72
|
+
const profileMenuItems: ReturnType<ProfileMenuPlugin["getProfileMenuItems"]> =
|
|
73
|
+
[];
|
|
74
|
+
const protectAccountRoutes = options.userManagement.enabled;
|
|
75
|
+
const basePath = options.basePath ?? "/account";
|
|
76
|
+
const accountChildren: RouteObject[] = [];
|
|
77
|
+
|
|
78
|
+
if (options.dashboard.enabled) {
|
|
79
|
+
accountChildren.push({
|
|
80
|
+
path: toAccountChildPath(basePath, options.dashboard.path),
|
|
81
|
+
element: renderModuleElement(
|
|
82
|
+
options.dashboard.component,
|
|
83
|
+
<DefaultDashboardPage content={options.dashboard.content} />,
|
|
84
|
+
),
|
|
85
|
+
handle: { layout: "none" },
|
|
86
|
+
});
|
|
87
|
+
protectAccountRoute(
|
|
88
|
+
protectedRoutes,
|
|
89
|
+
protectAccountRoutes,
|
|
90
|
+
options.dashboard.path,
|
|
91
|
+
);
|
|
92
|
+
profileMenuItems.push({
|
|
93
|
+
label: "Dashboard",
|
|
94
|
+
path: options.dashboard.path,
|
|
95
|
+
category: "top",
|
|
96
|
+
icon: LayoutDashboardIcon,
|
|
97
|
+
weight: 10,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (options.userManagement.enabled) {
|
|
102
|
+
const profilePath = options.userManagement.routes.profile;
|
|
103
|
+
accountChildren.push({
|
|
104
|
+
path: toAccountChildPath(basePath, profilePath),
|
|
105
|
+
element: renderModuleElement(
|
|
106
|
+
options.userManagement.component,
|
|
107
|
+
<SettingsPage content={options.userManagement.content} />,
|
|
108
|
+
),
|
|
109
|
+
handle: { layout: "none" },
|
|
110
|
+
});
|
|
111
|
+
protectAccountRoute(protectedRoutes, protectAccountRoutes, profilePath);
|
|
112
|
+
profileMenuItems.push({
|
|
113
|
+
label: "Settings",
|
|
114
|
+
path: profilePath,
|
|
115
|
+
category: "middle",
|
|
116
|
+
icon: SettingsIcon,
|
|
117
|
+
weight: 20,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (options.plans.enabled && options.billingNav) {
|
|
122
|
+
// The placeholder would be an empty page next to the real one: its old address leads to the real one instead.
|
|
123
|
+
if (options.plans.path !== BILLING_PLANS_PATH)
|
|
124
|
+
accountChildren.push({
|
|
125
|
+
path: toAccountChildPath(basePath, options.plans.path),
|
|
126
|
+
element: <Navigate to={BILLING_PLANS_PATH} replace />,
|
|
127
|
+
handle: { layout: "none" },
|
|
128
|
+
});
|
|
129
|
+
profileMenuItems.push({
|
|
130
|
+
label: "Plans",
|
|
131
|
+
path: BILLING_PLANS_PATH,
|
|
132
|
+
category: "middle",
|
|
133
|
+
icon: CreditCardIcon,
|
|
134
|
+
weight: 30,
|
|
135
|
+
});
|
|
136
|
+
} else if (options.plans.enabled) {
|
|
137
|
+
accountChildren.push({
|
|
138
|
+
path: toAccountChildPath(basePath, options.plans.path),
|
|
139
|
+
element: renderModuleElement(
|
|
140
|
+
options.plans.component,
|
|
141
|
+
<DefaultPlansPage content={options.plans.content} />,
|
|
142
|
+
),
|
|
143
|
+
handle: { layout: "none" },
|
|
144
|
+
});
|
|
145
|
+
protectAccountRoute(protectedRoutes, true, options.plans.path);
|
|
146
|
+
profileMenuItems.push({
|
|
147
|
+
label: "Plans",
|
|
148
|
+
path: options.plans.path,
|
|
149
|
+
category: "middle",
|
|
150
|
+
icon: CreditCardIcon,
|
|
151
|
+
weight: 30,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (options.apiKeys.enabled) {
|
|
156
|
+
protectAccountRoute(
|
|
157
|
+
protectedRoutes,
|
|
158
|
+
protectAccountRoutes,
|
|
159
|
+
options.apiKeys.path,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (accountChildren.length > 0) {
|
|
164
|
+
routes.push({
|
|
165
|
+
path: basePath,
|
|
166
|
+
// The same side menu as the billing plugin's pages, and "Overview" only when its page is registered here.
|
|
167
|
+
element: (
|
|
168
|
+
<AccountLayout
|
|
169
|
+
basePath={basePath}
|
|
170
|
+
includeOverview={options.dashboard.enabled}
|
|
171
|
+
includeBillingNav={options.billingNav === true}
|
|
172
|
+
// The portal's real docs page, or no link: the default `/introduction` was a 404 on most portals (API-110).
|
|
173
|
+
{...(options.docsPath !== undefined
|
|
174
|
+
? { docsPath: options.docsPath }
|
|
175
|
+
: {})}
|
|
176
|
+
/>
|
|
177
|
+
),
|
|
178
|
+
handle: { layout: "default" },
|
|
179
|
+
children: accountChildren,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
getRoutes: () => routes,
|
|
185
|
+
getProtectedRoutes: () => protectedRoutes,
|
|
186
|
+
getProfileMenuItems: () => profileMenuItems,
|
|
187
|
+
};
|
|
188
|
+
};
|