feat: connect dashboard shop pages to mutable state
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { create } from "zustand"
|
||||
import { mockPlayers } from "@/lib/mock"
|
||||
import type { Player } from "@/lib/types"
|
||||
|
||||
interface PlayerState {
|
||||
players: Player[]
|
||||
assignToShop: (playerId: string, shopId: string, shopName: string) => void
|
||||
removeFromShop: (playerId: string) => void
|
||||
}
|
||||
|
||||
export const usePlayerStore = create<PlayerState>((set) => ({
|
||||
players: mockPlayers,
|
||||
assignToShop: (playerId, shopId, shopName) =>
|
||||
set((state) => ({
|
||||
players: state.players.map((player) =>
|
||||
player.id === playerId ? { ...player, shopId, shopName } : player,
|
||||
),
|
||||
})),
|
||||
removeFromShop: (playerId) =>
|
||||
set((state) => ({
|
||||
players: state.players.map((player) =>
|
||||
player.id === playerId ? { ...player, shopId: undefined, shopName: undefined } : player,
|
||||
),
|
||||
})),
|
||||
}))
|
||||
@@ -0,0 +1,57 @@
|
||||
import { create } from "zustand"
|
||||
import { mockShops } from "@/lib/mock"
|
||||
import type { Shop, ShopSection } from "@/lib/types"
|
||||
|
||||
interface ShopState {
|
||||
shops: Shop[]
|
||||
updateShop: (shopId: string, patch: Partial<Omit<Shop, "id" | "owner">>) => void
|
||||
updateTemplateSections: (shopId: string, sections: ShopSection[]) => void
|
||||
updateAnnouncement: (shopId: string, index: number, announcement: string) => void
|
||||
addAnnouncement: (shopId: string, announcement: string) => void
|
||||
}
|
||||
|
||||
export const useShopStore = create<ShopState>((set) => ({
|
||||
shops: mockShops,
|
||||
updateShop: (shopId, patch) =>
|
||||
set((state) => ({
|
||||
shops: state.shops.map((shop) => (shop.id === shopId ? { ...shop, ...patch } : shop)),
|
||||
})),
|
||||
updateTemplateSections: (shopId, sections) =>
|
||||
set((state) => ({
|
||||
shops: state.shops.map((shop) =>
|
||||
shop.id === shopId
|
||||
? {
|
||||
...shop,
|
||||
templateConfig: {
|
||||
...shop.templateConfig,
|
||||
sections,
|
||||
},
|
||||
}
|
||||
: shop,
|
||||
),
|
||||
})),
|
||||
updateAnnouncement: (shopId, index, announcement) =>
|
||||
set((state) => ({
|
||||
shops: state.shops.map((shop) =>
|
||||
shop.id === shopId
|
||||
? {
|
||||
...shop,
|
||||
announcements: shop.announcements.map((item, currentIndex) =>
|
||||
currentIndex === index ? announcement : item,
|
||||
),
|
||||
}
|
||||
: shop,
|
||||
),
|
||||
})),
|
||||
addAnnouncement: (shopId, announcement) =>
|
||||
set((state) => ({
|
||||
shops: state.shops.map((shop) =>
|
||||
shop.id === shopId
|
||||
? {
|
||||
...shop,
|
||||
announcements: [...shop.announcements, announcement],
|
||||
}
|
||||
: shop,
|
||||
),
|
||||
})),
|
||||
}))
|
||||
Reference in New Issue
Block a user