feat(SW-2873): Move select-hotel to booking flow * crude setup of select-hotel in partner-sas * wip * Fix linting * restructure tracking files * Remove dependency on trpc in tracking hooks * Move pageview tracking to common * Fix some lint and import issues * Add AlternativeHotelsPage * Add SelectHotelMapPage * Add AlternativeHotelsMapPage * remove next dependency in tracking store * Remove dependency on react in tracking hooks * move isSameBooking to booking-flow * Inject searchParamsComparator into tracking store * Move useTrackHardNavigation to common * Move useTrackSoftNavigation to common * Add TrackingSDK to partner-sas * call serverclient in layout * Remove unused css * Update types * Move HotelPin type * Fix todos * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Fix component Approved-by: Joakim Jäderberg
68 lines
2.0 KiB
TypeScript
68 lines
2.0 KiB
TypeScript
import { SortOrder } from "../../misc/sortOrder"
|
|
|
|
import type { HotelResponse } from "../SelectHotel/helpers"
|
|
|
|
function getPricePerNight(hotel: HotelResponse): number {
|
|
return (
|
|
hotel.availability.productType?.member?.localPrice?.pricePerNight ??
|
|
hotel.availability.productType?.public?.localPrice?.pricePerNight ??
|
|
hotel.availability.productType?.redemptions?.find(
|
|
(r) => r?.localPrice.pointsPerStay
|
|
)?.localPrice?.pointsPerStay ??
|
|
Infinity
|
|
)
|
|
}
|
|
|
|
export function getSortedHotels({
|
|
hotels,
|
|
sortBy,
|
|
bookingCode,
|
|
}: {
|
|
hotels: HotelResponse[]
|
|
sortBy: string
|
|
bookingCode: string | null
|
|
}) {
|
|
const availableHotels = hotels.filter(
|
|
(hotel) => !!hotel.availability.productType
|
|
)
|
|
const unavailableHotels = hotels.filter(
|
|
(hotel) => !hotel.availability.productType
|
|
)
|
|
|
|
const sortingStrategies: Record<
|
|
string,
|
|
(a: HotelResponse, b: HotelResponse) => number
|
|
> = {
|
|
[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: HotelResponse, b: HotelResponse) =>
|
|
a.hotel.location.distanceToCentre - b.hotel.location.distanceToCentre,
|
|
}
|
|
|
|
const sortStrategy =
|
|
sortingStrategies[sortBy] ?? sortingStrategies[SortOrder.Distance]
|
|
|
|
if (bookingCode) {
|
|
const bookingCodeRateHotels = availableHotels.filter(
|
|
(hotel) => hotel.availability.bookingCode
|
|
)
|
|
const regularRateHotels = availableHotels.filter(
|
|
(hotel) => !hotel.availability.bookingCode
|
|
)
|
|
|
|
return bookingCodeRateHotels
|
|
.sort(sortStrategy)
|
|
.concat(regularRateHotels.sort(sortStrategy))
|
|
.concat(unavailableHotels.sort(sortStrategy))
|
|
}
|
|
|
|
return availableHotels
|
|
.sort(sortStrategy)
|
|
.concat(unavailableHotels.sort(sortStrategy))
|
|
}
|