This commit is contained in:
NotII
2025-06-30 16:56:57 +01:00
parent 6516c6d2f9
commit 84e4515a26
4 changed files with 122 additions and 218 deletions

View File

@@ -145,136 +145,64 @@ export default function OrderAnalyticsChart({ timeRange }: OrderAnalyticsChartPr
}
const totalOrders = data.statusDistribution.reduce((sum, item) => sum + item.count, 0);
const totalRevenue = data.dailyOrders.reduce((sum, item) => sum + item.revenue, 0);
return (
<div className="space-y-6">
{/* Order Status Distribution */}
<Card>
<CardHeader>
<CardTitle>Order Status Distribution</CardTitle>
<CardDescription>
Breakdown of orders by current status
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
{data.statusDistribution.map((status) => {
const percentage = totalOrders > 0 ? (status.count / totalOrders * 100).toFixed(1) : '0';
const Icon = getStatusIcon(status._id);
return (
<div key={status._id} className="flex items-center justify-between p-3 border rounded-lg">
<div className="flex items-center gap-3">
<div className={`p-2 rounded-full ${getStatusColor(status._id)}`}>
{Icon}
</div>
<div>
<div className="font-medium">{getStatusLabel(status._id)}</div>
<div className="text-sm text-muted-foreground">
{status.count} orders
</div>
</div>
</div>
<div className="text-right">
<div className="text-lg font-bold">{percentage}%</div>
<div className="text-sm text-muted-foreground">of total</div>
</div>
</div>
);
})}
</div>
</CardContent>
</Card>
{/* Daily Order Trends */}
<Card>
<CardHeader>
<CardTitle>Daily Order Trends</CardTitle>
<CardDescription>
Orders and revenue over the selected time period
</CardDescription>
</CardHeader>
<CardContent>
{data.dailyOrders.length === 0 ? (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<BarChart3 className="h-5 w-5" />
Order Analytics
</CardTitle>
<CardDescription>
Order status distribution for the selected time period
</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
{data.statusDistribution.length === 0 ? (
<div className="text-center py-8">
<BarChart3 className="h-12 w-12 mx-auto text-muted-foreground mb-4" />
<p className="text-muted-foreground">No order data available for this period</p>
</div>
) : (
<div className="space-y-4">
{/* Summary Stats */}
<div className="grid grid-cols-3 gap-4 mb-6">
<div className="text-center">
<div className="text-2xl font-bold text-blue-600">
{data.dailyOrders.length}
</div>
<div className="text-sm text-muted-foreground">Days with Orders</div>
</div>
<div className="text-center">
<div className="text-2xl font-bold text-green-600">
{totalOrders}
</div>
<div className="text-sm text-muted-foreground">Total Orders</div>
</div>
<div className="text-center">
<div className="text-2xl font-bold text-purple-600">
{formatGBP(totalRevenue)}
</div>
<div className="text-sm text-muted-foreground">Total Revenue</div>
<>
{/* Summary */}
<div className="text-center mb-6">
<div className="text-3xl font-bold text-blue-600">
{totalOrders}
</div>
<div className="text-sm text-muted-foreground">Total Orders</div>
</div>
{/* Chart */}
<div className="h-64 flex items-end justify-between gap-1">
{data.dailyOrders.map((item, index) => {
const maxOrders = Math.max(...data.dailyOrders.map(d => d.orders));
const height = maxOrders > 0 ? (item.orders / maxOrders) * 100 : 0;
const date = new Date(item._id.year, item._id.month - 1, item._id.day);
const dateLabel = date.toLocaleDateString('en-GB', {
month: 'short',
day: 'numeric'
});
return (
<div key={index} className="flex-1 flex flex-col items-center">
<div
className="w-full bg-primary/20 hover:bg-primary/30 transition-colors rounded-t"
style={{ height: `${height}%` }}
title={`${dateLabel}: ${item.orders} orders, ${formatGBP(item.revenue)} revenue`}
/>
<div className="text-xs text-muted-foreground mt-1 rotate-45 origin-left">
{dateLabel}
{/* Status Distribution */}
{data.statusDistribution.map((status) => {
const percentage = totalOrders > 0 ? (status.count / totalOrders * 100).toFixed(1) : '0';
const Icon = getStatusIcon(status._id);
return (
<div key={status._id} className="flex items-center justify-between p-3 border rounded-lg">
<div className="flex items-center gap-3">
<div className={`p-2 rounded-full ${getStatusColor(status._id)}`}>
{Icon}
</div>
<div>
<div className="font-medium">{getStatusLabel(status._id)}</div>
<div className="text-sm text-muted-foreground">
{status.count} orders
</div>
</div>
</div>
);
})}
</div>
</div>
<div className="text-right">
<div className="text-lg font-bold">{percentage}%</div>
<div className="text-sm text-muted-foreground">of total</div>
</div>
</div>
);
})}
</>
)}
</CardContent>
</Card>
{/* Processing Time */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Clock className="h-5 w-5" />
Order Processing Time
</CardTitle>
<CardDescription>
Average time to complete orders
</CardDescription>
</CardHeader>
<CardContent>
<div className="text-center">
<div className="text-3xl font-bold text-blue-600">
{data.averageProcessingDays.toFixed(1)}
</div>
<div className="text-sm text-muted-foreground">Average Days to Complete</div>
</div>
</CardContent>
</Card>
</div>
</div>
</CardContent>
</Card>
);
}