Skip to content

Commit 0517c09

Browse files
committed
fix: better dashboard
1 parent 8295355 commit 0517c09

File tree

3 files changed

+63
-69
lines changed

3 files changed

+63
-69
lines changed

apps/api/src/agent/processor.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { User } from '@databuddy/auth';
2+
import type { Website } from '@databuddy/shared';
13
import { handleChartResponse } from './handlers/chart-handler';
24
import { handleMetricResponse } from './handlers/metric-handler';
35
import { comprehensiveUnifiedPrompt } from './prompts/agent';
@@ -20,8 +22,8 @@ export interface AssistantRequest {
2022
}
2123

2224
export interface AssistantContext {
23-
user: any;
24-
website: any;
25+
user: User;
26+
website: Website;
2527
debugInfo: Record<string, unknown>;
2628
}
2729

apps/dashboard/app/(main)/layout.tsx

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ import { headers } from 'next/headers';
33
import { redirect } from 'next/navigation';
44
import { Sidebar } from '@/components/layout/sidebar';
55

6-
export default async function MainLayout({
7-
children,
8-
}: {
9-
children: React.ReactNode;
10-
}) {
6+
async function AuthGuard({ children }: { children: React.ReactNode }) {
117
const session = await auth.api.getSession({ headers: await headers() });
128
if (!session) {
139
redirect('/login');
1410
}
11+
return <>{children}</>;
12+
}
1513

14+
export default function MainLayout({
15+
children,
16+
}: {
17+
children: React.ReactNode;
18+
}) {
1619
return (
17-
<div className="h-screen overflow-hidden text-foreground">
18-
<Sidebar />
19-
<div className="relative h-screen pt-16 md:pl-72">
20-
<div className="h-[calc(100vh-4rem)] overflow-y-scroll">{children}</div>
20+
<AuthGuard>
21+
<div className="h-screen overflow-hidden text-foreground">
22+
<Sidebar />
23+
<div className="relative h-screen pt-16 md:pl-64">
24+
<div className="h-[calc(100vh-4rem)] overflow-y-scroll">
25+
{children}
26+
</div>
27+
</div>
2128
</div>
22-
</div>
29+
</AuthGuard>
2330
);
2431
}

apps/dashboard/components/layout/sidebar.tsx

Lines changed: 42 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import { WebsiteHeader } from './navigation/website-header';
1919
import { OrganizationSelector } from './organization-selector';
2020
import { TopHeader } from './top-header';
2121

22+
type NavigationConfig = {
23+
navigation: typeof mainNavigation;
24+
header: React.ReactNode;
25+
currentWebsiteId?: string | null;
26+
};
27+
2228
export function Sidebar() {
2329
const pathname = usePathname();
2430
const [isMobileOpen, setIsMobileOpen] = useState(false);
@@ -48,73 +54,39 @@ export function Sidebar() {
4854
return () => document.removeEventListener('keydown', handleKeyDown);
4955
}, [isMobileOpen, closeSidebar]);
5056

51-
const renderNavigation = () => {
57+
const getNavigationConfig = (): NavigationConfig => {
5258
if (isWebsite) {
53-
return (
54-
<div className="space-y-4">
55-
<WebsiteHeader website={currentWebsite} />
56-
{websiteNavigation.map((section) => (
57-
<NavigationSection
58-
currentWebsiteId={websiteId}
59-
items={section.items}
60-
key={section.title}
61-
pathname={pathname}
62-
title={section.title}
63-
/>
64-
))}
65-
</div>
66-
);
59+
return {
60+
navigation: websiteNavigation,
61+
header: <WebsiteHeader website={currentWebsite} />,
62+
currentWebsiteId: websiteId,
63+
};
6764
}
6865

6966
if (isDemo) {
70-
return (
71-
<div className="space-y-4">
72-
<WebsiteHeader website={currentWebsite} />
73-
{demoNavigation.map((section) => (
74-
<NavigationSection
75-
currentWebsiteId={websiteId}
76-
items={section.items}
77-
key={section.title}
78-
pathname={pathname}
79-
title={section.title}
80-
/>
81-
))}
82-
</div>
83-
);
67+
return {
68+
navigation: demoNavigation,
69+
header: <WebsiteHeader website={currentWebsite} />,
70+
currentWebsiteId: websiteId,
71+
};
8472
}
8573

8674
if (isSandbox) {
87-
return (
88-
<div className="space-y-4">
89-
<SandboxHeader />
90-
{sandboxNavigation.map((section) => (
91-
<NavigationSection
92-
currentWebsiteId="sandbox"
93-
items={section.items}
94-
key={section.title}
95-
pathname={pathname}
96-
title={section.title}
97-
/>
98-
))}
99-
</div>
100-
);
75+
return {
76+
navigation: sandboxNavigation,
77+
header: <SandboxHeader />,
78+
currentWebsiteId: 'sandbox',
79+
};
10180
}
10281

103-
return (
104-
<div className="space-y-4">
105-
<OrganizationSelector />
106-
{mainNavigation.map((section) => (
107-
<NavigationSection
108-
items={section.items}
109-
key={section.title}
110-
pathname={pathname}
111-
title={section.title}
112-
/>
113-
))}
114-
</div>
115-
);
82+
return {
83+
navigation: mainNavigation,
84+
header: <OrganizationSelector />,
85+
};
11686
};
11787

88+
const { navigation, header, currentWebsiteId } = getNavigationConfig();
89+
11890
return (
11991
<>
12092
<TopHeader setMobileOpen={() => setIsMobileOpen(true)} />
@@ -124,6 +96,8 @@ export function Sidebar() {
12496
className="fixed inset-0 z-30 bg-black/20 md:hidden"
12597
onClick={closeSidebar}
12698
onKeyDown={closeSidebar}
99+
role="button"
100+
tabIndex={0}
127101
/>
128102
)}
129103

@@ -145,7 +119,18 @@ export function Sidebar() {
145119
</Button>
146120

147121
<ScrollArea className="h-[calc(100vh-4rem)]">
148-
<div className="select-none space-y-4 p-3">{renderNavigation()}</div>
122+
<div className="select-none space-y-4 p-3">
123+
{header}
124+
{navigation.map((section) => (
125+
<NavigationSection
126+
currentWebsiteId={currentWebsiteId}
127+
items={section.items}
128+
key={section.title}
129+
pathname={pathname}
130+
title={section.title}
131+
/>
132+
))}
133+
</div>
149134
</ScrollArea>
150135
</div>
151136
</>

0 commit comments

Comments
 (0)