-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move /connect/analytics to app router
- Loading branch information
Showing
7 changed files
with
157 additions
and
133 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...d/src/app/(dashboard)/dashboard/connect/analytics/[clientId]/AnalyticsPageAPIKeysMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"use client"; | ||
|
||
import type { ApiKey } from "@3rdweb-sdk/react/hooks/useApi"; | ||
import { useDashboardRouter } from "../../../../../../@/lib/DashboardRouter"; | ||
import { ApiKeysMenu } from "../../../../../../components/settings/ApiKeys/Menu"; | ||
|
||
export function AnalyticsPageAPIKeysMenu(props: { | ||
apiKeys: Pick<ApiKey, "name" | "key">[]; | ||
selectedAPIKey: Pick<ApiKey, "name" | "key">; | ||
}) { | ||
const router = useDashboardRouter(); | ||
return ( | ||
<ApiKeysMenu | ||
apiKeys={props.apiKeys} | ||
selectedKey={props.selectedAPIKey} | ||
onSelect={(key) => { | ||
router.push(`/dashboard/connect/analytics/${key.key}`); | ||
}} | ||
/> | ||
); | ||
} |
60 changes: 60 additions & 0 deletions
60
apps/dashboard/src/app/(dashboard)/dashboard/connect/analytics/[clientId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { redirect } from "next/navigation"; | ||
import { ConnectSDKCard } from "../../../../../../components/shared/ConnectSDKCard"; | ||
import { getApiKeys } from "../../../../../api/lib/getAPIKeys"; | ||
import { getAuthToken } from "../../../../../api/lib/getAuthToken"; | ||
import { ConnectAnalyticsDashboard } from "../../../../../team/[team_slug]/[project_slug]/connect/analytics/ConnectAnalyticsDashboard"; | ||
import { AnalyticsPageAPIKeysMenu } from "./AnalyticsPageAPIKeysMenu"; | ||
|
||
export default async function Page(props: { | ||
params: { | ||
clientId: string; | ||
}; | ||
}) { | ||
const authToken = getAuthToken(); | ||
const { clientId } = props.params; | ||
|
||
if (!authToken) { | ||
redirect( | ||
`/login?next=${encodeURIComponent(`/dashboard/connect/analytics/${clientId}`)}`, | ||
); | ||
} | ||
|
||
const _apiKeys = await getApiKeys(); | ||
// slimmed down version to reduce client side payload | ||
const apiKeys = _apiKeys.map((key) => ({ | ||
name: key.name, | ||
key: key.key, | ||
})); | ||
|
||
const apiKey = apiKeys.find((key) => key.key === clientId); | ||
|
||
if (!apiKey) { | ||
redirect("/dashboard/connect/analytics"); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between"> | ||
<div> | ||
<h1 className="mb-1 font-semibold text-3xl tracking-tight"> | ||
Connect Analytics | ||
</h1> | ||
<p className="text-muted-foreground"> | ||
Visualize how users are connecting to your apps. | ||
</p> | ||
</div> | ||
|
||
<div> | ||
<AnalyticsPageAPIKeysMenu apiKeys={apiKeys} selectedAPIKey={apiKey} /> | ||
</div> | ||
</div> | ||
|
||
<div className="h-4 lg:h-8" /> | ||
|
||
<ConnectAnalyticsDashboard clientId={apiKey.key} /> | ||
|
||
<div className="h-4 lg:h-8" /> | ||
<ConnectSDKCard description="Add the Connect SDK to your app to start collecting analytics." /> | ||
</div> | ||
); | ||
} |
61 changes: 61 additions & 0 deletions
61
apps/dashboard/src/app/(dashboard)/dashboard/connect/analytics/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Button } from "@/components/ui/button"; | ||
import Link from "next/link"; | ||
import { redirect } from "next/navigation"; | ||
import { ConnectSDKCard } from "../../../../../components/shared/ConnectSDKCard"; | ||
import { getApiKeys } from "../../../../api/lib/getAPIKeys"; | ||
import { getAuthToken } from "../../../../api/lib/getAuthToken"; | ||
|
||
// base page | ||
// - if no keys -> show no keys page | ||
// - else redirect to first key | ||
|
||
export default async function Page() { | ||
const authToken = getAuthToken(); | ||
|
||
if (!authToken) { | ||
redirect( | ||
`/login?next=${encodeURIComponent("/dashboard/connect/analytics")}`, | ||
); | ||
} | ||
|
||
const apiKeys = await getApiKeys(); | ||
const firstKey = apiKeys[0]; | ||
|
||
if (firstKey) { | ||
redirect(`/dashboard/connect/analytics/${firstKey.key}`); | ||
} | ||
|
||
return <NoKeysCreatedPage />; | ||
} | ||
|
||
function NoKeysCreatedPage() { | ||
return ( | ||
<div> | ||
<div className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between"> | ||
<div> | ||
<h1 className="mb-1 font-semibold text-3xl tracking-tight"> | ||
Connect Analytics | ||
</h1> | ||
<p className="text-muted-foreground"> | ||
Visualize how users are connecting to your apps. | ||
</p> | ||
</div> | ||
</div> | ||
|
||
<div className="h-4 lg:h-8" /> | ||
|
||
<div className="flex flex-col items-center rounded-lg border border-border bg-muted/50 px-4 py-10 lg:px-6"> | ||
<h3 className="mb-3 font-semibold text-2xl">No API keys found</h3> | ||
<p className="mb-6 text-muted-foreground text-sm"> | ||
Start using the Connect SDK in your app with a free API key. | ||
</p> | ||
<Button asChild variant="primary"> | ||
<Link href="/dashboard/settings/api-keys">Create API Key</Link> | ||
</Button> | ||
</div> | ||
|
||
<div className="h-4 lg:h-8" /> | ||
<ConnectSDKCard description="Add the Connect SDK to your app to start collecting analytics." /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 0 additions & 115 deletions
115
apps/dashboard/src/pages/dashboard/connect/analytics.tsx
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.