|
1 | 1 | 'use client'; |
2 | 2 |
|
3 | 3 | import { useState, useEffect } from 'react'; |
| 4 | +import { useSearchParams } from 'next/navigation'; |
4 | 5 | import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; |
5 | 6 | import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; |
6 | 7 | import { Skeleton } from '@/components/ui/skeleton'; |
@@ -72,6 +73,9 @@ const COLORS = { |
72 | 73 | const PIE_COLORS = [COLORS.primary, COLORS.secondary, COLORS.tertiary, COLORS.quaternary, COLORS.quinary]; |
73 | 74 |
|
74 | 75 | export default function AnalyticsPage() { |
| 76 | + const searchParams = useSearchParams(); |
| 77 | + const isEmptyPreview = searchParams.get('preview') === 'empty'; |
| 78 | + |
75 | 79 | const [data, setData] = useState<AnalyticsData | null>(null); |
76 | 80 | const [insights, setInsights] = useState<Insight[]>([]); |
77 | 81 | const [loading, setLoading] = useState(true); |
@@ -122,8 +126,24 @@ export default function AnalyticsPage() { |
122 | 126 | }; |
123 | 127 |
|
124 | 128 | useEffect(() => { |
| 129 | + // Skip fetch if in empty preview mode |
| 130 | + if (isEmptyPreview) { |
| 131 | + setLoading(false); |
| 132 | + setData({ |
| 133 | + totalAnalyses: 0, |
| 134 | + maturityRate: 0, |
| 135 | + averageSweetness: 0, |
| 136 | + averageConfidence: 0, |
| 137 | + typeDistribution: [], |
| 138 | + trendData: [], |
| 139 | + skinQualityDistribution: [], |
| 140 | + sweetnessDistribution: [], |
| 141 | + }); |
| 142 | + setInsights([]); |
| 143 | + return; |
| 144 | + } |
125 | 145 | fetchAnalytics(); |
126 | | - }, []); |
| 146 | + }, [isEmptyPreview]); |
127 | 147 |
|
128 | 148 | const handleApplyFilters = () => { |
129 | 149 | fetchAnalytics(); |
@@ -214,6 +234,35 @@ export default function AnalyticsPage() { |
214 | 234 | return null; |
215 | 235 | } |
216 | 236 |
|
| 237 | + // Empty state when no data |
| 238 | + const isEmpty = data.totalAnalyses === 0; |
| 239 | + |
| 240 | + if (isEmpty) { |
| 241 | + return ( |
| 242 | + <div className="container mx-auto p-4 space-y-6"> |
| 243 | + <div> |
| 244 | + <h1 className="text-3xl font-bold">Dashboard Analitik</h1> |
| 245 | + <p className="text-muted-foreground"> |
| 246 | + Statistik dan tren analisis semangka & melon |
| 247 | + </p> |
| 248 | + </div> |
| 249 | + |
| 250 | + <Card> |
| 251 | + <CardContent className="py-12 text-center"> |
| 252 | + <TrendingUp className="mx-auto h-12 w-12 text-muted-foreground mb-4" /> |
| 253 | + <h3 className="text-lg font-semibold mb-2">Belum Ada Data Analitik</h3> |
| 254 | + <p className="text-muted-foreground mb-4"> |
| 255 | + Belum ada analisis yang dilakukan. Mulai analisis pertama Anda untuk melihat statistik! |
| 256 | + </p> |
| 257 | + <Button asChild> |
| 258 | + <a href="/">Mulai Analisis</a> |
| 259 | + </Button> |
| 260 | + </CardContent> |
| 261 | + </Card> |
| 262 | + </div> |
| 263 | + ); |
| 264 | + } |
| 265 | + |
217 | 266 | return ( |
218 | 267 | <div className="container mx-auto p-4 space-y-6"> |
219 | 268 | {/* Header */} |
|
0 commit comments