Merged in feat/SW-1652-confirmation-page (pull request #1483)
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
This commit is contained in:
40
apps/scandic-web/stores/booking-confirmation/index.ts
Normal file
40
apps/scandic-web/stores/booking-confirmation/index.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user