fix(services): resolve owner shop from backend
This commit is contained in:
@@ -12,12 +12,11 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { deletePlayerService, listPlayers, listServices } from "@/lib/api"
|
||||
import { resolveOwnerShop } from "@/lib/domain/resolve-current-shop"
|
||||
import { toApiError } from "@/lib/errors"
|
||||
import { useMyShop } from "@/lib/hooks/use-my-shop"
|
||||
import { notifyInfo, notifySuccess } from "@/lib/toast"
|
||||
import type { Player, PlayerService } from "@/lib/types"
|
||||
import { useAuthStore } from "@/store/auth"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
import { Edit, Plus, Trash2 } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||
@@ -25,11 +24,14 @@ import { useCallback, useEffect, useMemo, useState } from "react"
|
||||
export default function ServicesPage() {
|
||||
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<Player[]>([])
|
||||
const [services, setServices] = useState<PlayerService[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const ownerShop = resolveOwnerShop(userId, shops)
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
try {
|
||||
@@ -124,12 +126,18 @@ export default function ServicesPage() {
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{loading ? (
|
||||
{loading || (currentRole === "owner" && shopLoading) ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-sm text-muted-foreground">
|
||||
加载中...
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : currentRole === "owner" && shopError ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-sm text-muted-foreground">
|
||||
{shopError}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : scopedServices.length === 0 ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={6} className="text-center text-sm text-muted-foreground">
|
||||
|
||||
Reference in New Issue
Block a user