import { create } from "zustand" interface RoomDetails { id: string roomName: string isCancelable: boolean } interface MyStayRoomDetailsState { rooms: RoomDetails[] // Add a single room's details addRoomDetails: (room: RoomDetails) => void } export const useMyStayRoomDetailsStore = create( (set) => ({ rooms: [], addRoomDetails: (room) => { set((state) => { // Check if room with this ID already exists const existingIndex = state.rooms.findIndex((r) => r.id === room.id) let newRooms = [...state.rooms] if (existingIndex >= 0) { // Update existing room newRooms[existingIndex] = room } else { // Add new room newRooms.push(room) } return { rooms: newRooms, } }) }, }) )