Add admin dashboard and middleware protection
Introduces an admin dashboard page with cards for inviting vendors, banning users, and viewing recent orders. Adds middleware logic to restrict /admin routes to the 'admin1' user and updates route matching. Also updates git-info.json with latest commit metadata.
This commit is contained in:
74
components/admin/RecentOrdersCard.tsx
Normal file
74
components/admin/RecentOrdersCard.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { fetchClient } from "@/lib/api-client";
|
||||
|
||||
interface OrderItem {
|
||||
name: string;
|
||||
quantity: number;
|
||||
}
|
||||
|
||||
interface Order {
|
||||
orderId: number | string;
|
||||
userId: number;
|
||||
total: number;
|
||||
createdAt: string;
|
||||
items?: OrderItem[];
|
||||
}
|
||||
|
||||
export default function RecentOrdersCard() {
|
||||
const [orders, setOrders] = useState<Order[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
(async () => {
|
||||
try {
|
||||
const data = await fetchClient<Order[]>("/admin/recent-orders");
|
||||
if (mounted) setOrders(data);
|
||||
} catch (e: any) {
|
||||
if (mounted) setError(e?.message || "Failed to load orders");
|
||||
} finally {
|
||||
if (mounted) setLoading(false);
|
||||
}
|
||||
})();
|
||||
return () => { mounted = false; };
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border border-border/60 bg-background p-4">
|
||||
<h2 className="font-medium">Recent Orders</h2>
|
||||
<p className="text-sm text-muted-foreground mt-1">Last 10 orders across stores</p>
|
||||
{loading ? (
|
||||
<p className="text-sm text-muted-foreground mt-3">Loading...</p>
|
||||
) : error ? (
|
||||
<p className="text-sm text-muted-foreground mt-3">{error}</p>
|
||||
) : orders.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground mt-3">No recent orders</p>
|
||||
) : (
|
||||
<div className="mt-3 space-y-3">
|
||||
{orders.slice(0, 10).map((o) => (
|
||||
<div key={String(o.orderId)} className="rounded border border-border/50 p-3">
|
||||
<div className="flex items-center justify-between text-sm">
|
||||
<div className="font-medium">Order #{o.orderId}</div>
|
||||
<div className="text-muted-foreground">{new Date(o.createdAt).toLocaleString()}</div>
|
||||
</div>
|
||||
<div className="mt-1 text-xs text-muted-foreground">
|
||||
User: {o.userId} · Total: {o.total}
|
||||
</div>
|
||||
{o.items && o.items.length > 0 && (
|
||||
<ul className="mt-2 text-xs list-disc pl-4 text-muted-foreground">
|
||||
{o.items.map((it, idx) => (
|
||||
<li key={idx}>{it.name} × {it.quantity}</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user