admin
All checks were successful
Build Frontend / build (push) Successful in 1m6s

This commit is contained in:
g
2026-01-12 07:52:36 +00:00
parent e9737c8b24
commit 3ffb64cf9a
2 changed files with 339 additions and 240 deletions

View File

@@ -1,8 +1,9 @@
import React from "react";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Package, AlertTriangle } from "lucide-react";
import { Package, AlertTriangle, CheckCircle2, XCircle, DollarSign } from "lucide-react";
import { fetchServer } from "@/lib/api";
import OrdersTable from "@/components/admin/OrdersTable";
import { MotionWrapper } from "@/components/ui/motion-wrapper";
export const dynamic = 'force-dynamic';
@@ -26,7 +27,6 @@ interface SystemStats {
chats: number;
}
export default async function AdminOrdersPage() {
let orders: Order[] = [];
let systemStats: SystemStats | null = null;
@@ -46,14 +46,14 @@ export default async function AdminOrdersPage() {
if (error) {
return (
<div className="space-y-6">
<div className="space-y-6 p-1">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Recent Orders</h1>
<p className="text-sm text-muted-foreground mt-1">Monitor and manage platform orders</p>
<h1 className="text-3xl font-bold tracking-tight">Recent Orders</h1>
<p className="text-muted-foreground mt-2">Monitor and manage platform orders</p>
</div>
<Card>
<Card className="border-destructive/50 bg-destructive/10">
<CardContent className="pt-6">
<div className="text-center text-red-500">
<div className="text-center text-destructive">
<p>{error}</p>
</div>
</CardContent>
@@ -62,146 +62,182 @@ export default async function AdminOrdersPage() {
);
}
const acknowledgedOrders = orders.filter(o => o.status === 'acknowledged');
const paidOrders = orders.filter(o => o.status === 'paid');
const completedOrders = orders.filter(o => o.status === 'completed');
const cancelledOrders = orders.filter(o => o.status === 'cancelled');
return (
<div className="space-y-6">
<div className="space-y-8 p-1">
<div>
<h1 className="text-2xl font-semibold tracking-tight">Recent Orders</h1>
<p className="text-sm text-muted-foreground mt-1">Monitor and manage platform orders</p>
<h1 className="text-3xl font-bold tracking-tight bg-clip-text text-transparent bg-gradient-to-r from-foreground to-foreground/70">
Recent Orders
</h1>
<p className="text-muted-foreground mt-2 text-lg">
Monitor and manage platform transaction activity
</p>
</div>
{/* Stats Cards */}
<div className="grid gap-4 md:grid-cols-4">
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Total Orders</CardTitle>
<Package className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{systemStats?.orders || 0}</div>
<p className="text-xs text-muted-foreground">All platform orders</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Acknowledged</CardTitle>
<AlertTriangle className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{acknowledgedOrders.length}</div>
<p className="text-xs text-muted-foreground">Vendor accepted</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Paid</CardTitle>
<Package className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{paidOrders.length}</div>
<p className="text-xs text-muted-foreground">Payment received</p>
</CardContent>
</Card>
<Card>
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium">Completed</CardTitle>
<Package className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{completedOrders.length}</div>
<p className="text-xs text-muted-foreground">Successfully delivered</p>
</CardContent>
</Card>
</div>
<MotionWrapper>
<div className="space-y-8">
{/* Stats Cards */}
<div className="grid gap-4 md:grid-cols-4">
<Card className="bg-background/50 backdrop-blur-sm border-border/40 shadow-sm hover:shadow-md transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Total Orders</CardTitle>
<div className="p-2 rounded-lg bg-primary/10">
<Package className="h-4 w-4 text-primary" />
</div>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{systemStats?.orders || 0}</div>
<div className="flex items-center mt-1">
<div className="h-1.5 w-1.5 rounded-full bg-primary mr-2" />
<p className="text-xs text-muted-foreground">Lifetime volume</p>
</div>
</CardContent>
</Card>
{/* Orders Table with Pagination */}
<OrdersTable orders={orders} />
<Card className="bg-background/50 backdrop-blur-sm border-border/40 shadow-sm hover:shadow-md transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Acknowledged</CardTitle>
<div className="p-2 rounded-lg bg-purple-500/10">
<AlertTriangle className="h-4 w-4 text-purple-500" />
</div>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{acknowledgedOrders.length}</div>
<div className="flex items-center mt-1">
<div className="h-1.5 w-1.5 rounded-full bg-purple-500 mr-2" />
<p className="text-xs text-muted-foreground">Vendor pending</p>
</div>
</CardContent>
</Card>
{/* Order Analytics */}
<div className="grid gap-6 md:grid-cols-2">
<Card>
<CardHeader>
<CardTitle>Order Status Distribution</CardTitle>
<CardDescription>Breakdown of recent orders by status</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<div className="w-3 h-3 bg-purple-500 rounded-full"></div>
<span className="text-sm">Acknowledged</span>
<Card className="bg-background/50 backdrop-blur-sm border-border/40 shadow-sm hover:shadow-md transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Paid</CardTitle>
<div className="p-2 rounded-lg bg-emerald-500/10">
<DollarSign className="h-4 w-4 text-emerald-500" />
</div>
<span className="text-sm font-medium">
{orders.length > 0 ? Math.round((acknowledgedOrders.length / orders.length) * 100) : 0}%
</span>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<div className="w-3 h-3 bg-emerald-500 rounded-full"></div>
<span className="text-sm">Paid</span>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{paidOrders.length}</div>
<div className="flex items-center mt-1">
<div className="h-1.5 w-1.5 rounded-full bg-emerald-500 mr-2" />
<p className="text-xs text-muted-foreground">Processing</p>
</div>
<span className="text-sm font-medium">
{orders.length > 0 ? Math.round((paidOrders.length / orders.length) * 100) : 0}%
</span>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<div className="w-3 h-3 bg-green-500 rounded-full"></div>
<span className="text-sm">Completed</span>
</div>
<span className="text-sm font-medium">
{orders.length > 0 ? Math.round((completedOrders.length / orders.length) * 100) : 0}%
</span>
</div>
<div className="flex items-center justify-between">
<div className="flex items-center space-x-2">
<div className="w-3 h-3 bg-red-500 rounded-full"></div>
<span className="text-sm">Cancelled</span>
</div>
<span className="text-sm font-medium">
{orders.length > 0 ? Math.round((cancelledOrders.length / orders.length) * 100) : 0}%
</span>
</div>
</div>
</CardContent>
</Card>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle>Order Summary</CardTitle>
<CardDescription>Recent order activity breakdown</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div className="flex items-center justify-between">
<span className="text-sm">Total Recent Orders</span>
<span className="text-sm font-medium">{orders.length}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm">Acknowledged</span>
<span className="text-sm font-medium">{acknowledgedOrders.length}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm">Paid</span>
<span className="text-sm font-medium">{paidOrders.length}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm">Completed</span>
<span className="text-sm font-medium">{completedOrders.length}</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm">Cancelled</span>
<span className="text-sm font-medium">{cancelledOrders.length}</span>
</div>
</div>
</CardContent>
</Card>
</div>
<Card className="bg-background/50 backdrop-blur-sm border-border/40 shadow-sm hover:shadow-md transition-all duration-300">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-medium text-muted-foreground">Completed</CardTitle>
<div className="p-2 rounded-lg bg-blue-500/10">
<CheckCircle2 className="h-4 w-4 text-blue-500" />
</div>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{completedOrders.length}</div>
<div className="flex items-center mt-1">
<div className="h-1.5 w-1.5 rounded-full bg-blue-500 mr-2" />
<p className="text-xs text-muted-foreground">Delivered</p>
</div>
</CardContent>
</Card>
</div>
{/* Orders Table with Pagination */}
<div className="bg-background/50 backdrop-blur-sm rounded-xl border border-border/40 overflow-hidden shadow-sm">
<OrdersTable orders={orders} />
</div>
{/* Order Analytics */}
<div className="grid gap-6 md:grid-cols-2">
<Card className="bg-background/50 backdrop-blur-sm border-border/40 shadow-sm">
<CardHeader>
<CardTitle>Status Distribution</CardTitle>
<CardDescription>Breakdown of active orders</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-4">
<div className="flex items-center justify-between p-2 rounded-lg hover:bg-muted/30 transition-colors">
<div className="flex items-center space-x-3">
<div className="w-2 h-12 bg-purple-500 rounded-full"></div>
<div>
<p className="font-medium text-sm">Acknowledged</p>
<p className="text-xs text-muted-foreground">Waiting for shipment</p>
</div>
</div>
<span className="font-bold">
{orders.length > 0 ? Math.round((acknowledgedOrders.length / orders.length) * 100) : 0}%
</span>
</div>
<div className="flex items-center justify-between p-2 rounded-lg hover:bg-muted/30 transition-colors">
<div className="flex items-center space-x-3">
<div className="w-2 h-12 bg-emerald-500 rounded-full"></div>
<div>
<p className="font-medium text-sm">Paid</p>
<p className="text-xs text-muted-foreground">Payment confirmed</p>
</div>
</div>
<span className="font-bold">
{orders.length > 0 ? Math.round((paidOrders.length / orders.length) * 100) : 0}%
</span>
</div>
<div className="flex items-center justify-between p-2 rounded-lg hover:bg-muted/30 transition-colors">
<div className="flex items-center space-x-3">
<div className="w-2 h-12 bg-blue-500 rounded-full"></div>
<div>
<p className="font-medium text-sm">Completed</p>
<p className="text-xs text-muted-foreground">Successfully concluded</p>
</div>
</div>
<span className="font-bold">
{orders.length > 0 ? Math.round((completedOrders.length / orders.length) * 100) : 0}%
</span>
</div>
</div>
</CardContent>
</Card>
<Card className="bg-background/50 backdrop-blur-sm border-border/40 shadow-sm">
<CardHeader>
<CardTitle>Activity Summary</CardTitle>
<CardDescription>Recent volume breakdown</CardDescription>
</CardHeader>
<CardContent>
<div className="space-y-6">
<div className="flex items-center justify-between pb-4 border-b border-border/40">
<span className="text-sm text-muted-foreground">Total Displayed Orders</span>
<span className="text-xl font-bold">{orders.length}</span>
</div>
<div className="grid grid-cols-2 gap-4">
<div className="space-y-1">
<span className="text-xs uppercase text-muted-foreground tracking-wider">Active</span>
<p className="text-lg font-semibold">{acknowledgedOrders.length + paidOrders.length}</p>
</div>
<div className="space-y-1">
<span className="text-xs uppercase text-muted-foreground tracking-wider">Finished</span>
<p className="text-lg font-semibold">{completedOrders.length}</p>
</div>
<div className="space-y-1">
<span className="text-xs uppercase text-muted-foreground tracking-wider">Voided</span>
<p className="text-lg font-semibold text-destructive">{cancelledOrders.length}</p>
</div>
<div className="space-y-1">
<span className="text-xs uppercase text-muted-foreground tracking-wider">Success Rate</span>
<p className="text-lg font-semibold text-green-500">
{orders.length > 0 ? Math.round((completedOrders.length / (orders.length - (acknowledgedOrders.length + paidOrders.length))) * 100) || 100 : 0}%
</p>
</div>
</div>
</div>
</CardContent>
</Card>
</div>
</div>
</MotionWrapper>
</div>
);
}