Skip to content

Commit b70a030

Browse files
committed
Move /connect/analytics to app router
1 parent 7cd39f0 commit b70a030

File tree

7 files changed

+157
-133
lines changed

7 files changed

+157
-133
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use client";
2+
3+
import type { ApiKey } from "@3rdweb-sdk/react/hooks/useApi";
4+
import { useDashboardRouter } from "../../../../../../@/lib/DashboardRouter";
5+
import { ApiKeysMenu } from "../../../../../../components/settings/ApiKeys/Menu";
6+
7+
export function AnalyticsPageAPIKeysMenu(props: {
8+
apiKeys: Pick<ApiKey, "name" | "key">[];
9+
selectedAPIKey: Pick<ApiKey, "name" | "key">;
10+
}) {
11+
const router = useDashboardRouter();
12+
return (
13+
<ApiKeysMenu
14+
apiKeys={props.apiKeys}
15+
selectedKey={props.selectedAPIKey}
16+
onSelect={(key) => {
17+
router.push(`/dashboard/connect/analytics/${key.key}`);
18+
}}
19+
/>
20+
);
21+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { redirect } from "next/navigation";
2+
import { ConnectSDKCard } from "../../../../../../components/shared/ConnectSDKCard";
3+
import { getApiKeys } from "../../../../../api/lib/getAPIKeys";
4+
import { getAuthToken } from "../../../../../api/lib/getAuthToken";
5+
import { ConnectAnalyticsDashboard } from "../../../../../team/[team_slug]/[project_slug]/connect/analytics/ConnectAnalyticsDashboard";
6+
import { AnalyticsPageAPIKeysMenu } from "./AnalyticsPageAPIKeysMenu";
7+
8+
export default async function Page(props: {
9+
params: {
10+
clientId: string;
11+
};
12+
}) {
13+
const authToken = getAuthToken();
14+
const { clientId } = props.params;
15+
16+
if (!authToken) {
17+
redirect(
18+
`/login?next=${encodeURIComponent(`/dashboard/connect/analytics/${clientId}`)}`,
19+
);
20+
}
21+
22+
const _apiKeys = await getApiKeys();
23+
// slimmed down version to reduce client side payload
24+
const apiKeys = _apiKeys.map((key) => ({
25+
name: key.name,
26+
key: key.key,
27+
}));
28+
29+
const apiKey = apiKeys.find((key) => key.key === clientId);
30+
31+
if (!apiKey) {
32+
redirect("/dashboard/connect/analytics");
33+
}
34+
35+
return (
36+
<div>
37+
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
38+
<div>
39+
<h1 className="mb-1 font-semibold text-3xl tracking-tight">
40+
Connect Analytics
41+
</h1>
42+
<p className="text-muted-foreground">
43+
Visualize how users are connecting to your apps.
44+
</p>
45+
</div>
46+
47+
<div>
48+
<AnalyticsPageAPIKeysMenu apiKeys={apiKeys} selectedAPIKey={apiKey} />
49+
</div>
50+
</div>
51+
52+
<div className="h-4 lg:h-8" />
53+
54+
<ConnectAnalyticsDashboard clientId={apiKey.key} />
55+
56+
<div className="h-4 lg:h-8" />
57+
<ConnectSDKCard description="Add the Connect SDK to your app to start collecting analytics." />
58+
</div>
59+
);
60+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { Button } from "@/components/ui/button";
2+
import Link from "next/link";
3+
import { redirect } from "next/navigation";
4+
import { ConnectSDKCard } from "../../../../../components/shared/ConnectSDKCard";
5+
import { getApiKeys } from "../../../../api/lib/getAPIKeys";
6+
import { getAuthToken } from "../../../../api/lib/getAuthToken";
7+
8+
// base page
9+
// - if no keys -> show no keys page
10+
// - else redirect to first key
11+
12+
export default async function Page() {
13+
const authToken = getAuthToken();
14+
15+
if (!authToken) {
16+
redirect(
17+
`/login?next=${encodeURIComponent("/dashboard/connect/analytics")}`,
18+
);
19+
}
20+
21+
const apiKeys = await getApiKeys();
22+
const firstKey = apiKeys[0];
23+
24+
if (firstKey) {
25+
redirect(`/dashboard/connect/analytics/${firstKey.key}`);
26+
}
27+
28+
return <NoKeysCreatedPage />;
29+
}
30+
31+
function NoKeysCreatedPage() {
32+
return (
33+
<div>
34+
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
35+
<div>
36+
<h1 className="mb-1 font-semibold text-3xl tracking-tight">
37+
Connect Analytics
38+
</h1>
39+
<p className="text-muted-foreground">
40+
Visualize how users are connecting to your apps.
41+
</p>
42+
</div>
43+
</div>
44+
45+
<div className="h-4 lg:h-8" />
46+
47+
<div className="flex flex-col items-center rounded-lg border border-border bg-muted/50 px-4 py-10 lg:px-6">
48+
<h3 className="mb-3 font-semibold text-2xl">No API keys found</h3>
49+
<p className="mb-6 text-muted-foreground text-sm">
50+
Start using the Connect SDK in your app with a free API key.
51+
</p>
52+
<Button asChild variant="primary">
53+
<Link href="/dashboard/settings/api-keys">Create API Key</Link>
54+
</Button>
55+
</div>
56+
57+
<div className="h-4 lg:h-8" />
58+
<ConnectSDKCard description="Add the Connect SDK to your app to start collecting analytics." />
59+
</div>
60+
);
61+
}

apps/dashboard/src/components/settings/ApiKeys/Menu.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ import {
88
import type { ApiKey } from "@3rdweb-sdk/react/hooks/useApi";
99
import { shortenString } from "utils/usedapp-external";
1010

11-
interface ApiKeysMenuProps {
12-
apiKeys: ApiKey[];
13-
selectedKey: ApiKey | undefined;
14-
onSelect: (apiKey: ApiKey) => void;
15-
}
11+
type ApiKeysMenuProps<T extends Pick<ApiKey, "name" | "key">> = {
12+
apiKeys: T[];
13+
selectedKey: T | undefined;
14+
onSelect: (apiKey: T) => void;
15+
};
1616

17-
export const ApiKeysMenu: React.FC<ApiKeysMenuProps> = ({
18-
apiKeys,
19-
selectedKey,
20-
onSelect,
21-
}) => {
17+
export function ApiKeysMenu<T extends Pick<ApiKey, "name" | "key">>(
18+
props: ApiKeysMenuProps<T>,
19+
) {
20+
const { apiKeys, selectedKey, onSelect } = props;
2221
return (
2322
<Select
24-
value={selectedKey?.id}
25-
onValueChange={(keyId) => {
26-
const selectedKey = apiKeys.find((apiKey) => apiKey.id === keyId);
23+
value={selectedKey?.key}
24+
onValueChange={(key) => {
25+
const selectedKey = apiKeys.find((apiKey) => apiKey.key === key);
2726
if (selectedKey) {
2827
onSelect(selectedKey);
2928
}
@@ -34,11 +33,11 @@ export const ApiKeysMenu: React.FC<ApiKeysMenuProps> = ({
3433
</SelectTrigger>
3534
<SelectContent>
3635
{apiKeys.map((apiKey) => (
37-
<SelectItem key={apiKey.id} value={apiKey.id}>
36+
<SelectItem key={apiKey.key} value={apiKey.key}>
3837
{apiKey.name} ({shortenString(apiKey.key)})
3938
</SelectItem>
4039
))}
4140
</SelectContent>
4241
</Select>
4342
);
44-
};
43+
}

apps/dashboard/src/page-id.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ export enum PageId {
100100
DashboardConnectAccountAbstraction = "dashboard-wallets-smart-wallet",
101101
// thirdweb.com/dashboard/connect/embedded
102102
DashboardConnectEmbeddedWallets = "dashboard-wallets-embedded",
103-
// thirdweb.com/dashboard/connect/analytics
104-
DashboardConnectAnalytics = "dashboard-wallets-analytics",
105103
// thirdweb.com/dashboard/contracts/build
106104
DashboardContractsBuild = "dashboard-contracts-build",
107105

apps/dashboard/src/pages/dashboard/connect/analytics.tsx

Lines changed: 0 additions & 115 deletions
This file was deleted.

apps/dashboard/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)