feat: add multiroom tracking to booking flow
This commit is contained in:
@@ -1,37 +1,43 @@
|
||||
import type { HotelData } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps"
|
||||
import { SortOrder } from "@/types/components/hotelReservation/selectHotel/hotelSorter"
|
||||
import type { HotelResponse } from "@/components/HotelReservation/SelectHotel/helpers"
|
||||
|
||||
function getPricePerNight(hotel: HotelResponse): number {
|
||||
return (
|
||||
hotel.availability.productType?.member?.localPrice?.pricePerNight ??
|
||||
hotel.availability.productType?.public?.localPrice?.pricePerNight ??
|
||||
Infinity
|
||||
)
|
||||
}
|
||||
|
||||
export function getSortedHotels({
|
||||
hotels,
|
||||
sortBy,
|
||||
bookingCode,
|
||||
}: {
|
||||
hotels: HotelData[]
|
||||
hotels: HotelResponse[]
|
||||
sortBy: string
|
||||
bookingCode: string | null
|
||||
}) {
|
||||
const getPricePerNight = (hotel: HotelData): number =>
|
||||
hotel.price?.member?.localPrice?.pricePerNight ??
|
||||
hotel.price?.public?.localPrice?.pricePerNight ??
|
||||
hotel.price?.redemption?.localPrice?.pointsPerNight ??
|
||||
Infinity
|
||||
const availableHotels = hotels.filter((hotel) => !!hotel?.price)
|
||||
const unAvailableHotels = hotels.filter((hotel) => !hotel?.price)
|
||||
const availableHotels = hotels.filter(
|
||||
(hotel) => !!hotel.availability.productType
|
||||
)
|
||||
const unavailableHotels = hotels.filter(
|
||||
(hotel) => !hotel.availability.productType
|
||||
)
|
||||
|
||||
const sortingStrategies: Record<
|
||||
string,
|
||||
(a: HotelData, b: HotelData) => number
|
||||
(a: HotelResponse, b: HotelResponse) => number
|
||||
> = {
|
||||
[SortOrder.Name]: (a: HotelData, b: HotelData) =>
|
||||
a.hotelData.name.localeCompare(b.hotelData.name),
|
||||
[SortOrder.TripAdvisorRating]: (a: HotelData, b: HotelData) =>
|
||||
(b.hotelData.ratings?.tripAdvisor.rating ?? 0) -
|
||||
(a.hotelData.ratings?.tripAdvisor.rating ?? 0),
|
||||
[SortOrder.Price]: (a: HotelData, b: HotelData) =>
|
||||
[SortOrder.Name]: (a: HotelResponse, b: HotelResponse) =>
|
||||
a.hotel.name.localeCompare(b.hotel.name),
|
||||
[SortOrder.TripAdvisorRating]: (a: HotelResponse, b: HotelResponse) =>
|
||||
(b.hotel.ratings?.tripAdvisor.rating ?? 0) -
|
||||
(a.hotel.ratings?.tripAdvisor.rating ?? 0),
|
||||
[SortOrder.Price]: (a: HotelResponse, b: HotelResponse) =>
|
||||
getPricePerNight(a) - getPricePerNight(b),
|
||||
[SortOrder.Distance]: (a: HotelData, b: HotelData) =>
|
||||
a.hotelData.location.distanceToCentre -
|
||||
b.hotelData.location.distanceToCentre,
|
||||
[SortOrder.Distance]: (a: HotelResponse, b: HotelResponse) =>
|
||||
a.hotel.location.distanceToCentre - b.hotel.location.distanceToCentre,
|
||||
}
|
||||
|
||||
const sortStrategy =
|
||||
@@ -40,21 +46,25 @@ export function getSortedHotels({
|
||||
if (bookingCode) {
|
||||
const bookingCodeHotels = hotels.filter(
|
||||
(hotel) =>
|
||||
(hotel?.price?.public?.rateType?.toLowerCase() !== "regular" ||
|
||||
hotel?.price?.member?.rateType?.toLowerCase() !== "regular") &&
|
||||
!!hotel?.price
|
||||
(hotel.availability.productType?.public?.rateType?.toLowerCase() !==
|
||||
"regular" ||
|
||||
hotel.availability.productType?.member?.rateType?.toLowerCase() !==
|
||||
"regular") &&
|
||||
!!hotel.availability.productType
|
||||
)
|
||||
const regularHotels = hotels.filter(
|
||||
(hotel) => hotel?.price?.public?.rateType?.toLowerCase() === "regular"
|
||||
(hotel) =>
|
||||
hotel.availability.productType?.public?.rateType?.toLowerCase() ===
|
||||
"regular"
|
||||
)
|
||||
|
||||
return [...bookingCodeHotels]
|
||||
return bookingCodeHotels
|
||||
.sort(sortStrategy)
|
||||
.concat([...regularHotels].sort(sortStrategy))
|
||||
.concat([...unAvailableHotels].sort(sortStrategy))
|
||||
.concat(regularHotels.sort(sortStrategy))
|
||||
.concat(unavailableHotels.sort(sortStrategy))
|
||||
}
|
||||
|
||||
return [...availableHotels]
|
||||
return availableHotels
|
||||
.sort(sortStrategy)
|
||||
.concat([...unAvailableHotels].sort(sortStrategy))
|
||||
.concat(unavailableHotels.sort(sortStrategy))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user