fix(dashboard): scope owner and service views by resolved shop
This commit is contained in:
@@ -14,6 +14,8 @@ import {
|
||||
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"
|
||||
@@ -22,21 +24,18 @@ 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 = shops.find((item) => item.owner.id === userId) ?? shops[0]
|
||||
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) =>
|
||||
[
|
||||
"pending_payment",
|
||||
"pending_accept",
|
||||
"in_progress",
|
||||
"pending_close",
|
||||
"pending_review",
|
||||
].includes(o.status),
|
||||
).length
|
||||
const completedOrders = shopOrders.filter((o) => o.status === "completed").length
|
||||
const disputedOrders = shopOrders.filter((o) => o.status === "disputed").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="space-y-6">
|
||||
|
||||
Reference in New Issue
Block a user