Feat/SW-1652 confirmation page * feat(SW-1652): handle linkedReservations fetching * fix: add missing translations * feat: add linkedReservation retry functionality * chore: align naming Approved-by: Simon.Emanuelsson
41 lines
1002 B
TypeScript
41 lines
1002 B
TypeScript
import { useContext } from "react"
|
|
import { create, useStore } from "zustand"
|
|
|
|
import { BookingConfirmationContext } from "@/contexts/BookingConfirmation"
|
|
|
|
import type {
|
|
BookingConfirmationState,
|
|
InitialState,
|
|
} from "@/types/stores/booking-confirmation"
|
|
|
|
export function createBookingConfirmationStore(initialState: InitialState) {
|
|
return create<BookingConfirmationState>()((set) => ({
|
|
rooms: initialState.rooms,
|
|
currencyCode: initialState.currencyCode,
|
|
actions: {
|
|
setRoom: (room, idx) => {
|
|
set((state) => {
|
|
const rooms = [...state.rooms]
|
|
rooms[idx] = room
|
|
|
|
return { rooms }
|
|
})
|
|
},
|
|
},
|
|
}))
|
|
}
|
|
|
|
export function useBookingConfirmationStore<T>(
|
|
selector: (store: BookingConfirmationState) => T
|
|
) {
|
|
const store = useContext(BookingConfirmationContext)
|
|
|
|
if (!store) {
|
|
throw new Error(
|
|
"useBookingConfirmationStore must be used within BookingConfirmationProvider"
|
|
)
|
|
}
|
|
|
|
return useStore(store, selector)
|
|
}
|