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">
|
||||
|
||||
Reference in New Issue
Block a user