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
@@ -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),
)