import Link from 'next/link'; import { prisma } from '@/lib/prisma'; import { isAdminAuthenticated } from '@/lib/adminAuth'; import AdminNav from '@/components/AdminNav'; export default async function AdminDashboard() { const isAdmin = await isAdminAuthenticated(); if (!isAdmin) { return
Unauthorized
; } // Fetch statistics const orders = await prisma.order.findMany({ include: { items: true, customer: true }, orderBy: { createdAt: 'desc' }, }); const activeOrders = orders.filter((o) => ['PENDING', 'PAID'].includes(o.status)); const totalRevenue = orders .filter((o) => o.status === 'PAID') .reduce((sum, o) => sum + o.total, 0); const deliveredCount = orders.filter((o) => o.status === 'DELIVERED').length; // Get top 10 active customers (by order count) const customers = await prisma.customer.findMany({ include: { orders: true }, }); const topCustomers = customers .map((c) => ({ id: c.id, name: c.name || c.email, email: c.email, orderCount: c.orders.length, totalSpent: c.orders.reduce((sum, o) => sum + o.total, 0), })) .sort((a, b) => b.orderCount - a.orderCount) .slice(0, 10); // Get pending design approvals const designApprovals = await prisma.designApproval.findMany({ where: { status: 'IN_REVIEW' }, include: { product: true }, }); // Get failed orders const failedOrders = orders.filter((o) => o.status === 'FAILED'); // Recent orders (last 5) const recentOrders = orders.slice(0, 5); return (
{/* Header */}

Admin Dashboard

← Back to site

Overview of orders, customers, and key metrics

{/* Main Navigation */}
{/* Key Statistics */}

Active Orders

{activeOrders.length}

Pending or paid

Revenue (Paid)

£{(totalRevenue / 100).toFixed(2)}

{orders.filter((o) => o.status === 'PAID').length} orders

Delivered

{deliveredCount}

Completed orders

Design Reviews

{designApprovals.length}

Awaiting approval

{/* Main Content Grid */}
{/* Active Orders */}

Active Orders

View all →
{activeOrders.length === 0 ? (

No active orders

) : (
{activeOrders.slice(0, 8).map((order) => (

Order #{order.id.slice(0, 8).toUpperCase()}

{order.email || order.guestName || 'Guest'} · {order.items.length} item {order.items.length !== 1 ? 's' : ''}

£{(order.total / 100).toFixed(2)}

{order.status === 'PENDING' ? 'Awaiting payment' : 'Paid'}
))}
)}
{/* Alerts */} {failedOrders.length > 0 && (

⚠ {failedOrders.length} Failed Order{failedOrders.length !== 1 ? 's' : ''}

{failedOrders.length} order{failedOrders.length !== 1 ? 's' : ''} failed payment processing.{' '} Review →

)} {designApprovals.length > 0 && (

✏ {designApprovals.length} Design Review{designApprovals.length !== 1 ? 's' : ''}

{designApprovals.length} design{designApprovals.length !== 1 ? 's' : ''} awaiting approval.{' '} Review →

)}
{/* Sidebar */}
{/* Top Customers */}

Top 10 Customers

{topCustomers.length === 0 ? (

No customers yet

) : (
{topCustomers.map((customer, idx) => (

{idx + 1}. {customer.name}

{customer.email}

{customer.orderCount} order{customer.orderCount !== 1 ? 's' : ''} · £ {(customer.totalSpent / 100).toFixed(2)}

))}
)}
{/* Quick Actions */}

Quick Actions

View All Orders Email Customers Design Reviews Add Product
); }