fix(dashboard): scope owner and service views by resolved shop
This commit is contained in:
@@ -22,6 +22,8 @@ import {
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { usePlayerStore } from "@/store/players"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
|
||||
@@ -39,27 +41,32 @@ const statusVariants: Record<string, "default" | "secondary" | "outline"> = {
|
||||
|
||||
export default function EmployeesPage() {
|
||||
const [search, setSearch] = useState("")
|
||||
const userId = useAuthStore((state) => state.user?.id)
|
||||
const shops = useShopStore((state) => state.shops)
|
||||
const players = usePlayerStore((state) => state.players)
|
||||
const assignToShop = usePlayerStore((state) => state.assignToShop)
|
||||
const removeFromShop = usePlayerStore((state) => state.removeFromShop)
|
||||
const shop = useShopStore((state) => state.shops[0])
|
||||
const shop = resolveOwnerShop(userId, shops)
|
||||
const updateShop = useShopStore((state) => state.updateShop)
|
||||
|
||||
const shopPlayers = useMemo(
|
||||
() =>
|
||||
players.filter(
|
||||
(player) =>
|
||||
player.shopId === shop.id &&
|
||||
player.user.nickname.toLowerCase().includes(search.trim().toLowerCase()),
|
||||
),
|
||||
[players, shop.id, search],
|
||||
)
|
||||
const shopPlayers = useMemo(() => {
|
||||
if (!shop) return []
|
||||
return players.filter(
|
||||
(player) =>
|
||||
player.shopId === shop.id &&
|
||||
player.user.nickname.toLowerCase().includes(search.trim().toLowerCase()),
|
||||
)
|
||||
}, [players, shop, search])
|
||||
|
||||
const inviteCandidate = useMemo(
|
||||
() => players.find((player) => player.shopId !== shop.id),
|
||||
[players, shop.id],
|
||||
() => (shop ? players.find((player) => player.shopId !== shop.id) : undefined),
|
||||
[players, shop],
|
||||
)
|
||||
|
||||
if (!shop) {
|
||||
return <div className="text-sm text-muted-foreground">当前账号没有可管理的店铺</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { listTransactions } from "@/lib/api"
|
||||
import { isActiveOrder, isCompletedOrder } 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"
|
||||
@@ -20,9 +22,14 @@ export default function ShopIncomePage() {
|
||||
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 completedOrders = shopOrders.filter((o) => o.status === "completed")
|
||||
const completedOrders = shopOrders.filter((o) => isCompletedOrder(o.status))
|
||||
const totalIncome = completedOrders.reduce((acc, order) => acc + order.totalPrice, 0)
|
||||
|
||||
const currentMonth = new Date().getMonth()
|
||||
@@ -31,7 +38,10 @@ export default function ShopIncomePage() {
|
||||
.reduce((acc, order) => acc + order.totalPrice, 0)
|
||||
|
||||
const pendingSettlement = shopOrders
|
||||
.filter((o) => ["in_progress", "pending_close", "pending_review"].includes(o.status))
|
||||
.filter(
|
||||
(o) =>
|
||||
isActiveOrder(o.status) && o.status !== "pending_payment" && o.status !== "pending_accept",
|
||||
)
|
||||
.reduce((acc, order) => acc + order.totalPrice, 0)
|
||||
|
||||
const shopOrderIds = new Set(shopOrders.map((order) => order.id))
|
||||
|
||||
@@ -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">
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { DollarSign, Edit, ExternalLink, ListOrdered, Star, Users } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useState } from "react"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
@@ -10,21 +10,48 @@ import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import type { Shop } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
|
||||
export default function ShopManagementPage() {
|
||||
const shop = useShopStore((state) => state.shops[0])
|
||||
const userId = useAuthStore((state) => state.user?.id)
|
||||
const shops = useShopStore((state) => state.shops)
|
||||
const shop = resolveOwnerShop(userId, shops)
|
||||
const updateShop = useShopStore((state) => state.updateShop)
|
||||
const updateAnnouncement = useShopStore((state) => state.updateAnnouncement)
|
||||
const addAnnouncement = useShopStore((state) => state.addAnnouncement)
|
||||
|
||||
if (!shop) {
|
||||
return <div className="text-sm text-muted-foreground">当前账号没有可管理的店铺</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<ShopManagementContent
|
||||
key={shop.id}
|
||||
shop={shop}
|
||||
updateShop={updateShop}
|
||||
updateAnnouncement={updateAnnouncement}
|
||||
addAnnouncement={addAnnouncement}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ShopManagementContent({
|
||||
shop,
|
||||
updateShop,
|
||||
updateAnnouncement,
|
||||
addAnnouncement,
|
||||
}: {
|
||||
shop: Shop
|
||||
updateShop: (shopId: string, patch: Partial<Omit<Shop, "id" | "owner">>) => void
|
||||
updateAnnouncement: (shopId: string, index: number, announcement: string) => void
|
||||
addAnnouncement: (shopId: string, announcement: string) => void
|
||||
}) {
|
||||
const [name, setName] = useState(shop.name)
|
||||
const [description, setDescription] = useState(shop.description)
|
||||
|
||||
useEffect(() => {
|
||||
setName(shop.name)
|
||||
setDescription(shop.description)
|
||||
}, [shop])
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center justify-between">
|
||||
|
||||
@@ -14,13 +14,31 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
import { Switch } from "@/components/ui/switch"
|
||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import type { Shop } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
|
||||
export default function ShopRulesPage() {
|
||||
const shop = useShopStore((state) => state.shops[0])
|
||||
const userId = useAuthStore((state) => state.user?.id)
|
||||
const shops = useShopStore((state) => state.shops)
|
||||
const shop = resolveOwnerShop(userId, shops)
|
||||
const updateShop = useShopStore((state) => state.updateShop)
|
||||
|
||||
if (!shop) {
|
||||
return <div className="text-sm text-muted-foreground">当前账号没有可管理的店铺</div>
|
||||
}
|
||||
|
||||
return <ShopRulesForm key={shop.id} shop={shop} updateShop={updateShop} />
|
||||
}
|
||||
|
||||
function ShopRulesForm({
|
||||
shop,
|
||||
updateShop,
|
||||
}: {
|
||||
shop: Shop
|
||||
updateShop: (shopId: string, patch: Partial<Omit<Shop, "id" | "owner">>) => void
|
||||
}) {
|
||||
const [allowMultiShop, setAllowMultiShop] = useState(shop.allowMultiShop)
|
||||
const [allowIndependentOrders, setAllowIndependentOrders] = useState(shop.allowIndependentOrders)
|
||||
const [dispatchMode, setDispatchMode] = useState<Shop["dispatchMode"]>(shop.dispatchMode)
|
||||
|
||||
@@ -6,7 +6,9 @@ import { type DragEvent, useEffect, useState } from "react"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Switch } from "@/components/ui/switch"
|
||||
import type { ShopSection } from "@/lib/types"
|
||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import type { Shop, ShopSection } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
|
||||
const sectionLabels: Record<ShopSection["type"], string> = {
|
||||
@@ -28,8 +30,31 @@ const sectionDescriptions: Record<ShopSection["type"], string> = {
|
||||
}
|
||||
|
||||
export default function ShopTemplatesPage() {
|
||||
const shop = useShopStore((state) => state.shops[0])
|
||||
const userId = useAuthStore((state) => state.user?.id)
|
||||
const shops = useShopStore((state) => state.shops)
|
||||
const shop = resolveOwnerShop(userId, shops)
|
||||
const updateTemplateSections = useShopStore((state) => state.updateTemplateSections)
|
||||
|
||||
if (!shop) {
|
||||
return <div className="text-sm text-muted-foreground">当前账号没有可管理的店铺</div>
|
||||
}
|
||||
|
||||
return (
|
||||
<ShopTemplatesEditor
|
||||
key={shop.id}
|
||||
shop={shop}
|
||||
updateTemplateSections={updateTemplateSections}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function ShopTemplatesEditor({
|
||||
shop,
|
||||
updateTemplateSections,
|
||||
}: {
|
||||
shop: Shop
|
||||
updateTemplateSections: (shopId: string, sections: ShopSection[]) => void
|
||||
}) {
|
||||
const [sections, setSections] = useState<ShopSection[]>(
|
||||
[...shop.templateConfig.sections].sort((a, b) => a.order - b.order),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user