feat(SW-1717): rewrite select-rate to show all variants of rate-cards
This commit is contained in:
committed by
Michael Zetterberg
parent
adde77eaa9
commit
ebaea78fb3
@@ -7,14 +7,9 @@ import { RoomContext } from "@/contexts/Details/Room"
|
||||
import type { RoomProviderProps } from "@/types/providers/details/room"
|
||||
|
||||
export default function RoomProvider({ children, idx }: RoomProviderProps) {
|
||||
const actions = useEnterDetailsStore((state) => ({
|
||||
setStep: state.actions.setStep(idx),
|
||||
updateBedType: state.actions.updateBedType(idx),
|
||||
updateBreakfast: state.actions.updateBreakfast(idx),
|
||||
updateDetails: state.actions.updateDetails(idx),
|
||||
}))
|
||||
const { activeRoom, currentStep, isComplete, room, steps } =
|
||||
const { actions, activeRoom, currentStep, isComplete, room, steps } =
|
||||
useEnterDetailsStore((state) => ({
|
||||
actions: state.rooms[idx].actions,
|
||||
activeRoom: state.activeRoom,
|
||||
currentStep: state.rooms[idx].currentStep,
|
||||
isComplete: state.rooms[idx].isComplete,
|
||||
|
||||
@@ -51,9 +51,9 @@ export default function EnterDetailsProvider({
|
||||
bedType:
|
||||
room.bedTypes?.length === 1
|
||||
? {
|
||||
roomTypeCode: room.bedTypes[0].value,
|
||||
description: room.bedTypes[0].description,
|
||||
}
|
||||
roomTypeCode: room.bedTypes[0].value,
|
||||
description: room.bedTypes[0].description,
|
||||
}
|
||||
: undefined,
|
||||
mustBeGuaranteed: room.mustBeGuaranteed,
|
||||
isFlexRate: room.isFlexRate,
|
||||
@@ -161,9 +161,23 @@ export default function EnterDetailsProvider({
|
||||
)
|
||||
|
||||
const nights = dt(booking.toDate).diff(booking.fromDate, "days")
|
||||
const currency = (filteredOutMissingRooms[0].room.roomRate.publicRate
|
||||
?.localPrice.currency ||
|
||||
filteredOutMissingRooms[0].room.roomRate.memberRate?.localPrice.currency)!
|
||||
|
||||
// We only extract the first room for its currency,
|
||||
// the value is the same for the rest of the rooms
|
||||
const product = filteredOutMissingRooms[0].room.roomRate
|
||||
let currency = CurrencyEnum.Unknown
|
||||
if ("corporateCheque" in product) {
|
||||
currency = CurrencyEnum.CC
|
||||
} else if ("redemption" in product) {
|
||||
currency = CurrencyEnum.POINTS
|
||||
} else if ("voucher" in product) {
|
||||
currency = CurrencyEnum.Voucher
|
||||
} else if ("public" in product && product.public) {
|
||||
currency = product.public.localPrice.currency
|
||||
} else if ("member" in product && product.member) {
|
||||
currency = product.member.localPrice.currency
|
||||
}
|
||||
|
||||
const totalPrice = calcTotalPrice(
|
||||
filteredOutMissingRooms,
|
||||
currency,
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
"use client"
|
||||
import { useEffect } from "react"
|
||||
|
||||
import { trpc } from "@/lib/trpc/client"
|
||||
import { useRatesStore } from "@/stores/select-rate"
|
||||
|
||||
import { RoomContext } from "@/contexts/SelectRate/Room"
|
||||
import useLang from "@/hooks/useLang"
|
||||
|
||||
import { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter"
|
||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
import type { RoomProviderProps } from "@/types/providers/select-rate/room"
|
||||
|
||||
export default function RoomProvider({
|
||||
@@ -11,38 +16,72 @@ export default function RoomProvider({
|
||||
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 lang = useLang()
|
||||
const { activeRoom, booking, roomAvailability, selectedFilter } =
|
||||
useRatesStore((state) => ({
|
||||
activeRoom: state.activeRoom,
|
||||
booking: state.booking,
|
||||
roomAvailability: state.roomsAvailability?.[idx],
|
||||
selectedFilter: state.rooms[idx].selectedFilter,
|
||||
}))
|
||||
const { appendRegularRates, ...actions } = room.actions
|
||||
const roomNr = idx + 1
|
||||
|
||||
const hasRedemptionRates = room.rooms.some((room) => room.redemptions.length)
|
||||
const hasCorporateChequeOrVoucherRates = room.rooms.some((room) =>
|
||||
room.code.some((product) => {
|
||||
if ("corporateCheque" in product) {
|
||||
return product.corporateCheque.rateType === RateTypeEnum.CorporateCheque
|
||||
} else if ("voucher" in product) {
|
||||
return product.voucher.rateType === RateTypeEnum.Voucher
|
||||
}
|
||||
return false
|
||||
})
|
||||
)
|
||||
|
||||
const dontShowRegularRates =
|
||||
hasRedemptionRates || hasCorporateChequeOrVoucherRates
|
||||
|
||||
// Extra query needed to fetch regular rates upon user
|
||||
// selecting to view all rates.
|
||||
// TODO: Setup route to handle singular availability call
|
||||
const { data, isFetched, isFetching } =
|
||||
trpc.hotel.availability.roomsCombinedAvailability.useQuery(
|
||||
{
|
||||
adultsCount: [room.bookingRoom.adults],
|
||||
childArray: room.bookingRoom.childrenInRoom
|
||||
? [room.bookingRoom.childrenInRoom]
|
||||
: undefined,
|
||||
hotelId: booking.hotelId,
|
||||
lang,
|
||||
roomStayEndDate: booking.toDate,
|
||||
roomStayStartDate: booking.fromDate,
|
||||
},
|
||||
{
|
||||
enabled: !!(
|
||||
booking.bookingCode &&
|
||||
selectedFilter === BookingCodeFilterEnum.All &&
|
||||
!dontShowRegularRates
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (isFetched && !isFetching && data?.length) {
|
||||
const regularRates = data[0]
|
||||
if ("roomConfigurations" in regularRates) {
|
||||
appendRegularRates(regularRates.roomConfigurations)
|
||||
}
|
||||
}
|
||||
}, [appendRegularRates, data, isFetched, isFetching])
|
||||
|
||||
return (
|
||||
<RoomContext.Provider
|
||||
value={{
|
||||
...room,
|
||||
actions: {
|
||||
closeSection,
|
||||
modifyRate,
|
||||
selectFilter,
|
||||
selectRate,
|
||||
selectRateRedemption,
|
||||
selectRateCheque,
|
||||
selectRateVoucher,
|
||||
},
|
||||
actions,
|
||||
isActiveRoom: activeRoom === idx,
|
||||
isFetchingAdditionalRate: isFetched ? false : isFetching,
|
||||
isMainRoom: roomNr === 1,
|
||||
roomAvailability,
|
||||
roomNr,
|
||||
|
||||
Reference in New Issue
Block a user