feat: add admin dashboard revenue chart and fix empty customer order bug
All checks were successful
Staging Build / build (push) Successful in 2m35s
All checks were successful
Staging Build / build (push) Successful in 2m35s
This commit is contained in:
@@ -4,6 +4,7 @@ import { useEffect, useState, useRef } from 'react'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import Link from 'next/link'
|
||||
import { RevenueChart } from './revenue-chart'
|
||||
|
||||
type RecentOrder = {
|
||||
id: string
|
||||
@@ -34,6 +35,7 @@ const POLL_INTERVAL_MS = 30_000
|
||||
|
||||
export function AdminRecentOrders() {
|
||||
const [orders, setOrders] = useState<RecentOrder[]>([])
|
||||
const [chartData, setChartData] = useState<{ name: string; value: number }[]>([])
|
||||
const [newOrderIds, setNewOrderIds] = useState<Set<string>>(new Set())
|
||||
const [lastChecked, setLastChecked] = useState<Date>(new Date())
|
||||
const knownIds = useRef<Set<string>>(new Set())
|
||||
@@ -43,7 +45,7 @@ export function AdminRecentOrders() {
|
||||
const baseUrl = process.env.NEXT_PUBLIC_BASE_URL || 'http://localhost:3000';
|
||||
const res = await fetch(`${baseUrl}/api/admin/recent-orders`, { cache: 'no-store' });
|
||||
if (!res.ok) return
|
||||
const { orders: fresh } = await res.json()
|
||||
const { orders: fresh, chartData: freshChart } = await res.json()
|
||||
|
||||
// Neue Bestellungen erkennen (Highlight)
|
||||
const freshIds = new Set<string>(fresh.map((o: RecentOrder) => o.id))
|
||||
@@ -54,6 +56,7 @@ export function AdminRecentOrders() {
|
||||
knownIds.current = freshIds
|
||||
|
||||
setOrders(fresh)
|
||||
setChartData(freshChart || [])
|
||||
setNewOrderIds(newOnes)
|
||||
setLastChecked(new Date())
|
||||
|
||||
@@ -76,12 +79,10 @@ export function AdminRecentOrders() {
|
||||
<div className="grid gap-4 md:grid-cols-2 lg:grid-cols-7">
|
||||
<Card className="col-span-4 glass-dark border-white/5">
|
||||
<CardHeader>
|
||||
<CardTitle>Übersicht</CardTitle>
|
||||
<CardTitle>Übersicht (letzte 6 Monate)</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="pl-2">
|
||||
<div className="h-[200px] flex items-center justify-center text-slate-400 italic">
|
||||
[Umsatz-Chart – folgt in nächstem Update]
|
||||
</div>
|
||||
<RevenueChart data={chartData} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user