Merged in fix/SW-3442-tracking-event-lowestroomprice- (pull request #2797)
fix(SW-3442): Fixed lowest price tracking and other lint issues * fix(SW-3442): Fixed lowest price tracking and other lint issues Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -36,6 +36,7 @@ import { includeRoomInfo } from "./includeRoomInfo"
|
||||
import { isRateSelected as isRateSelected_Inner } from "./isRateSelected"
|
||||
|
||||
import type { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
|
||||
import type { PriceProduct } from "@scandic-hotels/trpc/types/roomAvailability"
|
||||
|
||||
import type { SelectRateBooking } from "../../types/components/selectRate/selectRate"
|
||||
import type { Price } from "../../types/price"
|
||||
@@ -380,6 +381,8 @@ export function SelectRateProvider({
|
||||
roomIndex,
|
||||
roomAvailabilityWithAdjustedRoomCount
|
||||
),
|
||||
getLowestRoomPrice: () =>
|
||||
getLowestRoomPrice(roomAvailabilityWithAdjustedRoomCount),
|
||||
isRateSelected,
|
||||
getPackagesForRoom,
|
||||
bookingCodeFilter,
|
||||
@@ -520,6 +523,28 @@ function calculateNumberOfNights(
|
||||
return dt(toDate).diff(dt(fromDate), "day")
|
||||
}
|
||||
|
||||
function getLowestRoomPrice(
|
||||
roomAvailability: (AvailabilityWithRoomInfo | null)[][]
|
||||
) {
|
||||
// First room is always cheapest room because sort by price is default
|
||||
const firstRoomAvailability = roomAvailability[0]
|
||||
return firstRoomAvailability
|
||||
.filter((room) => !!room)[0]
|
||||
.products.filter(
|
||||
(product): product is PriceProduct =>
|
||||
!!(
|
||||
("public" in product && product.public) ||
|
||||
("member" in product && product.member)
|
||||
)
|
||||
)
|
||||
.map((product) => ({
|
||||
currency: (product.member?.localPrice.currency ||
|
||||
product.public?.localPrice.currency)!,
|
||||
price: (product.member?.localPrice.pricePerNight ||
|
||||
product.public?.localPrice.pricePerNight)!,
|
||||
}))[0]
|
||||
}
|
||||
|
||||
function getAvailabilityForRoom(
|
||||
roomIndex: number,
|
||||
roomAvailability: (AvailabilityWithRoomInfo | null)[][] | undefined
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { type RouterOutput } from "@scandic-hotels/trpc/client"
|
||||
|
||||
import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency"
|
||||
import type { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
||||
import type { RoomsAvailabilityOutputSchema } from "@scandic-hotels/trpc/routers/hotels/availability/selectRate/rooms/schema"
|
||||
import type { PackageEnum } from "@scandic-hotels/trpc/types/packages"
|
||||
@@ -31,6 +32,11 @@ export type SelectRateContext = {
|
||||
roomIndex: number
|
||||
) => AvailabilityWithRoomInfo[] | undefined
|
||||
|
||||
getLowestRoomPrice: () => {
|
||||
price: number
|
||||
currency: CurrencyEnum
|
||||
}
|
||||
|
||||
getPackagesForRoom: (roomIndex: number) => {
|
||||
selectedPackages: RoomPackage[]
|
||||
availablePackages: (DefaultRoomPackage | RoomPackage)[]
|
||||
|
||||
Reference in New Issue
Block a user