88 | {/* Top component */}
89 |
90 | {topComponent}
91 |
92 |
93 | {/* Drag handle */}
94 |
103 |
104 | {/* Bottom component */}
105 |
106 | {bottomComponent}
107 |
108 |
109 | );
110 | }
--------------------------------------------------------------------------------
/dashboard/ai-analytics/src/app/components/RootLayoutContent.tsx:
--------------------------------------------------------------------------------
1 | 'use client';
2 |
3 | import { ReactNode, useEffect } from 'react';
4 | import { useTinybirdToken } from '@/providers/TinybirdProvider';
5 | import { useModal } from '../context/ModalContext';
6 | import { useKeyboardShortcut } from '@/hooks/useKeyboardShortcut';
7 | import CostPredictionModal from './CostPredictionModal';
8 | import { FloatingNotification } from '@/components/ui/floating-notification';
9 | import { useSearchParams } from 'next/navigation';
10 | import { getApiUrlFromHost, extractHostFromToken } from '@/lib/tinybird-utils';
11 |
12 | interface RootLayoutContentProps {
13 | children: ReactNode;
14 | initialToken: string;
15 | initialOrgName: string;
16 | }
17 |
18 | export function RootLayoutContent({ children, initialToken, initialOrgName }: RootLayoutContentProps) {
19 | const { setToken, setOrgName, setApiUrl } = useTinybirdToken();
20 | const searchParams = useSearchParams();
21 | const tokenParam = searchParams.get('token');
22 |
23 | // Set the initial values from the server
24 | useEffect(() => {
25 | if (tokenParam) {
26 | setToken(tokenParam);
27 | // Extract host from token if it's a JWT
28 | try {
29 | const host = extractHostFromToken(tokenParam);
30 | if (host) {
31 | // Convert host to API URL
32 | const apiUrl = getApiUrlFromHost(host);
33 | setApiUrl(apiUrl);
34 | setOrgName(host);
35 | }
36 | } catch (e) {
37 | console.error('Error decoding token:', e);
38 | }
39 | } else {
40 | setToken(initialToken);
41 | setOrgName(initialOrgName);
42 | setApiUrl(process.env.NEXT_PUBLIC_TINYBIRD_API_URL || 'https://api.tinybird.co');
43 | }
44 | }, [tokenParam, initialToken, initialOrgName, setToken, setOrgName, setApiUrl]);
45 |
46 | return (
47 | <>
48 | {children}
49 |