Skip to content

Commit 16a569f

Browse files
committed
Move /connect/analytics to app router
1 parent a453d96 commit 16a569f

File tree

4 files changed

+117
-117
lines changed

4 files changed

+117
-117
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use client";
2+
3+
import { Button } from "@/components/ui/button";
4+
import type { ApiKey } from "@3rdweb-sdk/react/hooks/useApi";
5+
import { ApiKeysMenu } from "components/settings/ApiKeys/Menu";
6+
import Link from "next/link";
7+
import { useMemo, useState } from "react";
8+
import { ConnectSDKCard } from "../../../../../components/shared/ConnectSDKCard";
9+
import { ConnectAnalyticsDashboard } from "../../../../team/[team_slug]/[project_slug]/connect/analytics/ConnectAnalyticsDashboard";
10+
11+
export function ConnectAnalyticsPage(props: {
12+
defaultClientId: string | undefined;
13+
apiKeys: ApiKey[];
14+
}) {
15+
const { defaultClientId, apiKeys } = props;
16+
const [selectedKey_, setSelectedKey] = useState<undefined | ApiKey>();
17+
18+
const selectedKey = useMemo(() => {
19+
if (selectedKey_) {
20+
return selectedKey_;
21+
}
22+
if (apiKeys.length) {
23+
if (defaultClientId) {
24+
return apiKeys.find((k) => k.key === defaultClientId);
25+
}
26+
return apiKeys[0];
27+
}
28+
return undefined;
29+
}, [apiKeys, defaultClientId, selectedKey_]);
30+
31+
return (
32+
<div>
33+
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
34+
<div>
35+
<h1 className="mb-1 font-semibold text-3xl tracking-tight">
36+
Connect Analytics
37+
</h1>
38+
<p className="text-muted-foreground">
39+
Visualize how users are connecting to your apps.
40+
</p>
41+
</div>
42+
43+
{/* API selector */}
44+
{selectedKey && (
45+
<div>
46+
<ApiKeysMenu
47+
apiKeys={apiKeys}
48+
selectedKey={selectedKey}
49+
onSelect={(key) => {
50+
// add clientId search param to the url without affecting router
51+
window.history.replaceState(
52+
{},
53+
"",
54+
`/dashboard/connect/analytics?clientId=${key.key}`,
55+
);
56+
setSelectedKey(key);
57+
}}
58+
/>
59+
</div>
60+
)}
61+
</div>
62+
63+
<div className="h-4 lg:h-8" />
64+
65+
{selectedKey ? (
66+
<ConnectAnalyticsDashboard clientId={selectedKey.key} />
67+
) : (
68+
<NoAPIFoundCard />
69+
)}
70+
71+
<div className="h-4 lg:h-8" />
72+
<ConnectSDKCard description="Add the Connect SDK to your app to start collecting analytics." />
73+
</div>
74+
);
75+
}
76+
77+
function NoAPIFoundCard() {
78+
return (
79+
<div className="flex flex-col items-center rounded-lg border border-border bg-muted/50 px-4 py-10 lg:px-6">
80+
<h3 className="mb-3 font-semibold text-2xl">No API keys found</h3>
81+
<p className="mb-6 text-muted-foreground text-sm">
82+
Start using the Connect SDK in your app with a free API key.
83+
</p>
84+
<Button asChild variant="primary">
85+
<Link href="/dashboard/settings/api-keys">Create API Key</Link>
86+
</Button>
87+
</div>
88+
);
89+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { redirect } from "next/navigation";
2+
import { getApiKeys } from "../../../../api/lib/getAPIKeys";
3+
import { getAuthToken } from "../../../../api/lib/getAuthToken";
4+
import { ConnectAnalyticsPage } from "./ConnectAnalyticsPage";
5+
6+
export default async function Page(props: {
7+
searchParams: {
8+
clientId?: string;
9+
};
10+
}) {
11+
const authToken = getAuthToken();
12+
const { clientId } = props.searchParams;
13+
14+
if (!authToken) {
15+
const params = new URLSearchParams();
16+
params.append("next", "/dashboard/connect/analytics");
17+
if (clientId) {
18+
params.append("clientId", clientId);
19+
}
20+
redirect(`/login?${params.toString()}`);
21+
}
22+
23+
const apiKeys = await getApiKeys();
24+
25+
return <ConnectAnalyticsPage defaultClientId={clientId} apiKeys={apiKeys} />;
26+
}
27+
28+
export const dynamic = "force-dynamic";

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.

0 commit comments

Comments
 (0)