Feat/SW-1676 modify contact details my stay anonymous * feat(SW-1676): Modify guest details step 1 * feat(SW-1676) Integration to api to update guest details * feat(SW-1676) Reuse of old modal * feat(SW-1676) updated modify guest * feat(SW-1676) cleanup * feat(SW-1676) updated myStayReturnRoute to sessionStorage Approved-by: Niclas Edenvin
41 lines
857 B
TypeScript
41 lines
857 B
TypeScript
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<MyStayRoomDetailsState>(
|
|
(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,
|
|
}
|
|
})
|
|
},
|
|
})
|
|
)
|