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,
|
||||
),
|
||||
})),
|
||||
}))
|
||||
Reference in New Issue
Block a user