Feat/SW-1813 * feat(SW-1652): handle linkedReservations fetching * feat: add linkedReservation retry functionality * chore: align naming * feat(SW-1813): Add booking confirmation PriceDetailsModal Approved-by: Simon.Emanuelsson
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
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,
|
|
bookingCode: initialState.bookingCode,
|
|
currencyCode: initialState.currencyCode,
|
|
fromDate: initialState.fromDate,
|
|
toDate: initialState.toDate,
|
|
vat: initialState.vat,
|
|
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)
|
|
}
|