Files
web/apps/scandic-web/providers/SelectRate/RoomProvider.tsx
Hrishikesh Vaipurkar b0674d07f5 Merged in feat/SW-1308-booking-codes-track-b (pull request #1607)
Feat/SW-1308 booking codes track b

* feat: SW-1308 Booking codes track b

* feat: SW-1308 Booking codes Track B implementation

* feat: SW-1308 Optimized after rebase


Approved-by: Arvid Norlin
2025-03-24 11:23:11 +00:00

56 lines
1.6 KiB
TypeScript

"use client"
import { useRatesStore } from "@/stores/select-rate"
import { RoomContext } from "@/contexts/SelectRate/Room"
import type { RoomProviderProps } from "@/types/providers/select-rate/room"
export default function RoomProvider({
children,
idx,
room,
}: RoomProviderProps) {
const activeRoom = useRatesStore((state) => state.activeRoom)
const closeSection = useRatesStore((state) => state.actions.closeSection(idx))
const modifyRate = useRatesStore((state) => state.actions.modifyRate(idx))
const roomAvailability = useRatesStore(
(state) => state.roomsAvailability?.[idx]
)
const selectFilter = useRatesStore((state) => state.actions.selectFilter(idx))
const selectRate = useRatesStore((state) => state.actions.selectRate(idx))
const selectRateRedemption = useRatesStore((state) =>
state.actions.selectRateRedemption(idx)
)
const selectRateCheque = useRatesStore((state) =>
state.actions.selectRateCheque(idx)
)
const selectRateVoucher = useRatesStore((state) =>
state.actions.selectRateVoucher(idx)
)
const roomNr = idx + 1
return (
<RoomContext.Provider
value={{
...room,
actions: {
closeSection,
modifyRate,
selectFilter,
selectRate,
selectRateRedemption,
selectRateCheque,
selectRateVoucher,
},
isActiveRoom: activeRoom === idx,
isMainRoom: roomNr === 1,
roomAvailability,
roomNr,
totalRooms: room.rooms.length,
}}
>
{children}
</RoomContext.Provider>
)
}