Files
juwan-frontend/app/(dashboard)/dashboard/shop/orders/page.tsx
T

127 lines
5.1 KiB
TypeScript

"use client"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table"
import { statusLabels } from "@/lib/constants"
import { isActiveOrder, isCompletedOrder, isDisputedOrder } from "@/lib/domain/order-filters"
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
import { useAuthStore } from "@/store/auth"
import { useOrderStore } from "@/store/orders"
import { useShopStore } from "@/store/shops"
import { AlertCircle, CheckCircle, Clock, ListOrdered } from "lucide-react"
import Link from "next/link"
export default function ShopOrdersPage() {
const userId = useAuthStore((state) => state.user?.id)
const shops = useShopStore((state) => state.shops)
const orders = useOrderStore((state) => state.orders)
const shop = resolveOwnerShop(userId, shops)
if (!shop) {
return <div className="text-sm text-muted-foreground"></div>
}
const shopOrders = orders.filter((order) => order.shopId === shop?.id)
const totalOrders = shopOrders.length
const activeOrders = shopOrders.filter((o) => isActiveOrder(o.status)).length
const completedOrders = shopOrders.filter((o) => isCompletedOrder(o.status)).length
const disputedOrders = shopOrders.filter((o) => isDisputedOrder(o.status)).length
return (
<div className="container mx-auto max-w-6xl px-4 py-8 space-y-8">
<div className="flex items-center justify-between">
<h1 className="text-2xl font-bold"></h1>
</div>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
<Card className="hover:shadow-[var(--shadow-card)]">
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<ListOrdered className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{totalOrders}</div>
</CardContent>
</Card>
<Card className="hover:shadow-[var(--shadow-card)]">
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<Clock className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{activeOrders}</div>
</CardContent>
</Card>
<Card className="hover:shadow-[var(--shadow-card)]">
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<CheckCircle className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{completedOrders}</div>
</CardContent>
</Card>
<Card className="hover:shadow-[var(--shadow-card)]">
<CardHeader className="flex flex-row items-center justify-between pb-2">
<CardTitle className="text-sm font-medium"></CardTitle>
<AlertCircle className="h-4 w-4 text-muted-foreground" />
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">{disputedOrders}</div>
</CardContent>
</Card>
</div>
<Card className="hover:shadow-[var(--shadow-card)]">
<CardHeader>
<CardTitle></CardTitle>
</CardHeader>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{shopOrders.map((order) => (
<TableRow key={order.id}>
<TableCell className="font-medium">{order.service.title}</TableCell>
<TableCell>{order.consumerName}</TableCell>
<TableCell>{order.playerName}</TableCell>
<TableCell>
<Badge variant="outline">{statusLabels[order.status]}</Badge>
</TableCell>
<TableCell>¥{order.totalPrice}</TableCell>
<TableCell>{new Date(order.createdAt).toLocaleDateString()}</TableCell>
<TableCell className="text-right">
<Button variant="ghost" size="sm" asChild>
<Link href={`/order/${order.id}`}></Link>
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</CardContent>
</Card>
</div>
)
}