fix(dashboard): scope owner and service views by resolved shop
This commit is contained in:
@@ -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),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user