fix(dashboard): scope owner and service views by resolved shop

This commit is contained in:
zetaloop
2026-02-22 17:14:52 +08:00
parent 1f2dc1434b
commit 1dfcd3927d
11 changed files with 269 additions and 70 deletions
@@ -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">