feat: connect dashboard shop pages to mutable state
This commit is contained in:
@@ -6,8 +6,8 @@ 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 { mockShops } from "@/lib/mock"
|
||||
import type { ShopSection } from "@/lib/types"
|
||||
import { useShopStore } from "@/store/shops"
|
||||
|
||||
const sectionLabels: Record<ShopSection["type"], string> = {
|
||||
banner: "横幅图片",
|
||||
@@ -28,7 +28,8 @@ const sectionDescriptions: Record<ShopSection["type"], string> = {
|
||||
}
|
||||
|
||||
export default function ShopTemplatesPage() {
|
||||
const shop = mockShops[0]
|
||||
const shop = useShopStore((state) => state.shops[0])
|
||||
const updateTemplateSections = useShopStore((state) => state.updateTemplateSections)
|
||||
const [sections, setSections] = useState<ShopSection[]>(
|
||||
[...shop.templateConfig.sections].sort((a, b) => a.order - b.order),
|
||||
)
|
||||
@@ -50,6 +51,10 @@ export default function ShopTemplatesPage() {
|
||||
}
|
||||
}, [showSavedToast])
|
||||
|
||||
useEffect(() => {
|
||||
setSections([...shop.templateConfig.sections].sort((a, b) => a.order - b.order))
|
||||
}, [shop])
|
||||
|
||||
const toggleSection = (type: ShopSection["type"]) => {
|
||||
setSections((prev) => prev.map((s) => (s.type === type ? { ...s, enabled: !s.enabled } : s)))
|
||||
}
|
||||
@@ -91,6 +96,7 @@ export default function ShopTemplatesPage() {
|
||||
}
|
||||
|
||||
const handleSaveTemplate = () => {
|
||||
updateTemplateSections(shop.id, sections)
|
||||
setShowSavedToast(true)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user