From 9cf226526f76620120a74ca827dabf80e9cfca9d Mon Sep 17 00:00:00 2001 From: NotII <46204250+NotII@users.noreply.github.com> Date: Sat, 30 Aug 2025 22:53:47 +0100 Subject: [PATCH] Add customer insights dashboard to order table Introduced a CustomerInsightsDisplay component to show key metrics such as total orders, revenue, success rates, and recent activity above the order table. Updated data fetching and types to support customer insights from the API. --- components/tables/order-table.tsx | 106 +++++++++++++++++++++++++++++- public/git-info.json | 4 +- 2 files changed, 106 insertions(+), 4 deletions(-) diff --git a/components/tables/order-table.tsx b/components/tables/order-table.tsx index da2b047..862b796 100644 --- a/components/tables/order-table.tsx +++ b/components/tables/order-table.tsx @@ -30,12 +30,18 @@ import { MessageCircle, AlertTriangle, Tag, - Percent + Percent, + TrendingUp, + Users, + DollarSign, + ShoppingCart, + Calendar } from "lucide-react"; import Link from "next/link"; import { clientFetch } from '@/lib/api'; import { toast } from "sonner"; import { Checkbox } from "@/components/ui/checkbox"; +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { AlertDialog, AlertDialogAction, @@ -69,6 +75,35 @@ interface Order { subtotalBeforeDiscount?: number; } +interface CustomerInsights { + overview: { + totalOrders: number; + completedOrders: number; + cancelledOrders: number; + uniqueCustomers: number; + completionRate: number; + paymentSuccessRate: number; + cancellationRate: number; + }; + financial: { + totalRevenue: number; + averageOrderValue: number; + }; + recent30Days: { + orders: number; + revenue: number; + newCustomers: number; + }; +} + +interface OrdersResponse { + orders: Order[]; + page: number; + totalPages: number; + totalOrders: number; + customerInsights: CustomerInsights; +} + type SortableColumns = "orderId" | "totalPrice" | "status" | "orderDate" | "paidAt"; interface StatusConfig { @@ -120,6 +155,68 @@ const PageSizeSelector = ({ currentSize, onChange, options }: { currentSize: num ); }; +// Customer Insights Display Component +const CustomerInsightsDisplay = ({ insights }: { insights: CustomerInsights }) => { + return ( +
+ {insights.overview.uniqueCustomers} unique customers +
++ {insights.overview.completionRate.toFixed(1)}% completion rate +
++ £{insights.financial.averageOrderValue.toFixed(2)} avg order +
++ £{insights.recent30Days.revenue.toFixed(2)} revenue +
+