fix(services): resolve owner shop from backend

This commit is contained in:
zetaloop
2026-04-25 15:04:48 +08:00
parent 9c7e207dfe
commit 9cff134cf2
3 changed files with 39 additions and 15 deletions
@@ -20,13 +20,12 @@ import {
listPlayers,
updatePlayerService,
} from "@/lib/api"
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
import { toApiError } from "@/lib/errors"
import { GameIcon } from "@/lib/game-icons"
import { useMyShop } from "@/lib/hooks/use-my-shop"
import { notifyInfo, notifySuccess } from "@/lib/toast"
import type { Game, PlayerService } from "@/lib/types"
import { useAuthStore } from "@/store/auth"
import { useShopStore } from "@/store/shops"
import { standardSchemaResolver } from "@hookform/resolvers/standard-schema"
import { ArrowLeft } from "lucide-react"
import Link from "next/link"
@@ -51,11 +50,14 @@ export default function NewServicePage() {
const serviceId = searchParams.get("serviceId")
const userId = useAuthStore((state) => state.user?.id)
const currentRole = useAuthStore((state) => state.currentRole)
const shops = useShopStore((state) => state.shops)
const {
shop: ownerShop,
loading: shopLoading,
error: shopError,
} = useMyShop(currentRole === "owner")
const [players, setPlayers] = useState<Awaited<ReturnType<typeof listPlayers>>>([])
const [editingService, setEditingService] = useState<PlayerService | undefined>(undefined)
const [loadingService, setLoadingService] = useState(Boolean(serviceId))
const ownerShop = resolveOwnerShop(userId, shops)
const scopedPlayerIds =
currentRole === "player"
? userId
@@ -156,10 +158,14 @@ export default function NewServicePage() {
}
}, [])
if (loadingService) {
if (loadingService || (currentRole === "owner" && shopLoading)) {
return <div className="text-sm text-muted-foreground">...</div>
}
if (currentRole === "owner" && shopError) {
return <div className="text-sm text-muted-foreground">{shopError}</div>
}
if (serviceId && (!editingService || !scopedPlayerIdSet.has(editingService.playerId))) {
return <div className="text-sm text-muted-foreground"></div>
}