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
This commit is contained in:
@@ -43,6 +43,13 @@ export default function HotelCardListing({
|
||||
const sortBy = searchParams.get("sort") ?? DEFAULT_SORT
|
||||
|
||||
const bookingCode = searchParams.get("bookingCode")
|
||||
// Special rates (corporate cheque, voucher and reward nights) will not have regular rate hotels availability
|
||||
const isSpecialRate = hotelData.find(
|
||||
(hotel) =>
|
||||
hotel.availability.productType?.bonusCheque ||
|
||||
hotel.availability.productType?.voucher ||
|
||||
hotel.availability.productType?.redemptions
|
||||
)
|
||||
const activeCodeFilter = useBookingCodeFilterStore(
|
||||
(state) => state.activeCodeFilter
|
||||
)
|
||||
@@ -51,21 +58,26 @@ export default function HotelCardListing({
|
||||
const sortedHotels = getSortedHotels({
|
||||
hotels: hotelData,
|
||||
sortBy,
|
||||
bookingCode,
|
||||
bookingCode: isSpecialRate ? null : bookingCode,
|
||||
})
|
||||
const updatedHotelsList = bookingCode
|
||||
? sortedHotels.filter(
|
||||
(hotel) =>
|
||||
!hotel.availability.productType ||
|
||||
activeCodeFilter === BookingCodeFilterEnum.All ||
|
||||
(activeCodeFilter === BookingCodeFilterEnum.Discounted &&
|
||||
hotel.availability.productType.public?.rateType !==
|
||||
RateTypeEnum.Regular) ||
|
||||
(activeCodeFilter === BookingCodeFilterEnum.Regular &&
|
||||
hotel.availability.productType.public?.rateType ===
|
||||
RateTypeEnum.Regular)
|
||||
)
|
||||
: sortedHotels
|
||||
const updatedHotelsList =
|
||||
bookingCode && !isSpecialRate
|
||||
? sortedHotels.filter(
|
||||
(hotel) =>
|
||||
!hotel.availability.productType ||
|
||||
activeCodeFilter === BookingCodeFilterEnum.All ||
|
||||
(activeCodeFilter === BookingCodeFilterEnum.Discounted &&
|
||||
hotel.availability.productType.public?.rateType !==
|
||||
RateTypeEnum.Regular &&
|
||||
hotel.availability.productType.member?.rateType !==
|
||||
RateTypeEnum.Regular) ||
|
||||
(activeCodeFilter === BookingCodeFilterEnum.Regular &&
|
||||
(hotel.availability.productType.public?.rateType ===
|
||||
RateTypeEnum.Regular ||
|
||||
hotel.availability.productType.member?.rateType ===
|
||||
RateTypeEnum.Regular))
|
||||
)
|
||||
: sortedHotels
|
||||
|
||||
if (!activeFilters.length) {
|
||||
return updatedHotelsList
|
||||
@@ -78,7 +90,14 @@ export default function HotelCardListing({
|
||||
)
|
||||
)
|
||||
)
|
||||
}, [activeCodeFilter, activeFilters, bookingCode, hotelData, sortBy])
|
||||
}, [
|
||||
activeCodeFilter,
|
||||
activeFilters,
|
||||
bookingCode,
|
||||
hotelData,
|
||||
sortBy,
|
||||
isSpecialRate,
|
||||
])
|
||||
|
||||
useEffect(() => {
|
||||
setResultCount(hotels.length)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SortOrder } from "@/types/components/hotelReservation/selectHotel/hotelSorter"
|
||||
import { RateTypeEnum } from "@/types/enums/rateType"
|
||||
import type { HotelResponse } from "@/components/HotelReservation/SelectHotel/helpers"
|
||||
|
||||
function getPricePerNight(hotel: HotelResponse): number {
|
||||
@@ -47,23 +48,21 @@ export function getSortedHotels({
|
||||
sortingStrategies[sortBy] ?? sortingStrategies[SortOrder.Distance]
|
||||
|
||||
if (bookingCode) {
|
||||
const bookingCodeHotels = hotels.filter(
|
||||
const bookingCodeRateHotels = availableHotels.filter(
|
||||
(hotel) =>
|
||||
(hotel.availability.productType?.public?.rateType?.toLowerCase() !==
|
||||
"regular" ||
|
||||
hotel.availability.productType?.member?.rateType?.toLowerCase() !==
|
||||
"regular") &&
|
||||
(hotel.availability.productType?.public?.rateType !== RateTypeEnum.Regular &&
|
||||
hotel.availability.productType?.member?.rateType !== RateTypeEnum.Regular) &&
|
||||
!!hotel.availability.productType
|
||||
)
|
||||
const regularHotels = hotels.filter(
|
||||
const regularRateHotels = availableHotels.filter(
|
||||
(hotel) =>
|
||||
hotel.availability.productType?.public?.rateType?.toLowerCase() ===
|
||||
"regular"
|
||||
hotel.availability.productType?.public?.rateType === RateTypeEnum.Regular ||
|
||||
hotel?.availability.productType?.member?.rateType === RateTypeEnum.Regular
|
||||
)
|
||||
|
||||
return bookingCodeHotels
|
||||
return bookingCodeRateHotels
|
||||
.sort(sortStrategy)
|
||||
.concat(regularHotels.sort(sortStrategy))
|
||||
.concat(regularRateHotels.sort(sortStrategy))
|
||||
.concat(unavailableHotels.sort(sortStrategy))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user