|
3 | 3 | import { useQueryState } from 'nuqs'; |
4 | 4 | import React, { useEffect, useState } from 'react'; |
5 | 5 | import { Card } from '@/components/ui/card'; |
6 | | -import { listDataSources, query } from '@/lib/tinybird'; |
7 | | -import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts'; |
8 | | -import Link from 'next/link'; |
9 | | - |
10 | | -const MOCK_DATA = [ |
11 | | - { name: 'Jan', value: 400 }, |
12 | | - { name: 'Feb', value: 300 }, |
13 | | - { name: 'Mar', value: 600 }, |
14 | | - { name: 'Apr', value: 800 }, |
15 | | - { name: 'May', value: 700 } |
16 | | -]; |
17 | | - |
18 | | -const INSTALLATION_GUIDES = { |
19 | | - clerk: `# Installing Clerk Integration |
20 | | -
|
21 | | -1. Sign up for a Clerk account |
22 | | -2. Create a new application |
23 | | -3. Configure your endpoints |
24 | | -4. Add the following to your Tinybird pipes...`, |
25 | | - |
26 | | - resend: `# Installing Resend Integration |
27 | | -
|
28 | | -1. Create a Resend account |
29 | | -2. Generate an API key |
30 | | -3. Set up your email domain |
31 | | -4. Configure the data source...`, |
32 | | - |
33 | | - auth0: `# Installing Auth0 Integration |
34 | | -
|
35 | | -1. Set up an Auth0 account |
36 | | -2. Create a new application |
37 | | -3. Configure your callbacks |
38 | | -4. Set up the event tracking...` |
39 | | -}; |
| 6 | +import { listDataSources } from '@/lib/tinybird'; |
| 7 | +import dynamic from 'next/dynamic'; |
| 8 | + |
| 9 | +const TOOLS = { |
| 10 | + clerk: { |
| 11 | + name: 'Clerk', |
| 12 | + Dashboard: dynamic(() => import('@/components/tools/clerk/dashboard')), |
| 13 | + Readme: dynamic(() => import('@/components/tools/clerk/readme')), |
| 14 | + }, |
| 15 | + resend: { |
| 16 | + name: 'Resend', |
| 17 | + Dashboard: dynamic(() => import('@/components/tools/resend/dashboard')), |
| 18 | + Readme: dynamic(() => import('@/components/tools/resend/readme')), |
| 19 | + }, |
| 20 | + auth0: { |
| 21 | + name: 'Auth0', |
| 22 | + Dashboard: dynamic(() => import('@/components/tools/auth0/dashboard')), |
| 23 | + Readme: dynamic(() => import('@/components/tools/auth0/readme')), |
| 24 | + }, |
| 25 | +} as const; |
| 26 | + |
| 27 | +type ToolId = keyof typeof TOOLS; |
40 | 28 |
|
41 | 29 | export default function AppPage({ params }: { params: Promise<{ id: string }> }) { |
42 | 30 | const [token, setToken] = useQueryState('token'); |
43 | 31 | const [isInstalled, setIsInstalled] = useState(false); |
44 | | - const [totalCount, setTotalCount] = useState<number | null>(null); |
45 | | - const { id } = React.use(params); |
| 32 | + const { id } = React.use(params) as { id: ToolId }; |
46 | 33 |
|
47 | 34 | useEffect(() => { |
48 | 35 | async function checkInstallation() { |
49 | 36 | if (!token) return; |
50 | | - |
51 | | - try { |
52 | | - const sources = await listDataSources(token); |
53 | | - setIsInstalled(sources.some(s => s.name === id)); |
54 | | - |
55 | | - if (sources.some(s => s.name === id)) { |
56 | | - const result = await query(token, `select count() as total from ${id} format json`); |
57 | | - setTotalCount(result.data[0]?.total || 0); |
58 | | - } |
59 | | - } catch (error) { |
60 | | - console.error('Failed to check installation:', error); |
61 | | - } |
| 37 | + const sources = await listDataSources(token); |
| 38 | + setIsInstalled(sources.some(source => source.name.startsWith(id))); |
62 | 39 | } |
63 | | - |
64 | 40 | checkInstallation(); |
65 | 41 | }, [token, id]); |
66 | 42 |
|
67 | | - if (!isInstalled) { |
68 | | - return ( |
69 | | - <div className="container mx-auto p-6"> |
70 | | - <h1 className="text-3xl font-bold mb-2">Analytics for {id}</h1> |
71 | | - <Link |
72 | | - href={token ? `/?token=${token}` : '/'} |
73 | | - className="text-sm text-gray-500 hover:text-gray-700 mb-8 inline-block" |
74 | | - > |
75 | | - ← Back to Apps |
76 | | - </Link> |
77 | | - <Card className="p-6"> |
78 | | - <div className="prose"> |
79 | | - <pre className="p-4 bg-gray-100 rounded"> |
80 | | - {INSTALLATION_GUIDES[id as keyof typeof INSTALLATION_GUIDES] || 'Installation guide coming soon...'} |
81 | | - </pre> |
82 | | - </div> |
83 | | - </Card> |
84 | | - </div> |
85 | | - ); |
| 43 | + const tool = TOOLS[id]; |
| 44 | + if (!tool) { |
| 45 | + return <div>Tool not found</div>; |
86 | 46 | } |
87 | 47 |
|
| 48 | + const Component = isInstalled ? tool.Dashboard : tool.Readme; |
| 49 | + |
88 | 50 | return ( |
89 | | - <div className="container mx-auto p-6"> |
90 | | - <h1 className="text-3xl font-bold mb-2">Analytics for {id}</h1> |
91 | | - <Link |
92 | | - href={token ? `/?token=${token}` : '/'} |
93 | | - className="text-sm text-gray-500 hover:text-gray-700 mb-8 inline-block" |
94 | | - > |
95 | | - ← Back to Apps |
96 | | - </Link> |
97 | | - <div className="space-y-6"> |
98 | | - <Card className="p-6"> |
99 | | - <h2 className="text-xl font-semibold mb-4">Total Records</h2> |
100 | | - <p className="text-4xl font-bold">{totalCount?.toLocaleString() || '...'}</p> |
101 | | - </Card> |
102 | | - <Card className="p-6"> |
103 | | - <h2 className="text-xl font-semibold mb-4">Usage Over Time</h2> |
104 | | - <div className="h-[400px]"> |
105 | | - <ResponsiveContainer width="100%" height="100%"> |
106 | | - <LineChart data={MOCK_DATA}> |
107 | | - <CartesianGrid strokeDasharray="3 3" /> |
108 | | - <XAxis dataKey="name" /> |
109 | | - <YAxis /> |
110 | | - <Tooltip /> |
111 | | - <Line type="monotone" dataKey="value" stroke="#8884d8" /> |
112 | | - </LineChart> |
113 | | - </ResponsiveContainer> |
114 | | - </div> |
115 | | - </Card> |
| 51 | + <div className="container py-6"> |
| 52 | + <div className="flex flex-col gap-6"> |
| 53 | + <h1 className="text-2xl font-bold">{tool.name}</h1> |
| 54 | + <Component /> |
116 | 55 | </div> |
117 | 56 | </div> |
118 | 57 | ); |
|
0 commit comments