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:
@@ -14,9 +14,9 @@ import {
|
||||
import { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
|
||||
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
||||
|
||||
import { readPaymentInfoFromSessionStorage } from "../../../components/EnterDetails/Payment/helpers"
|
||||
import { invertedBedTypeMap } from "../../../utils/SelectRate"
|
||||
import { getSpecialRoomType } from "../../../utils/specialRoomType"
|
||||
import { readPaymentInfoFromSessionStorage } from "../../EnterDetails/Payment/helpers"
|
||||
|
||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||
import type { BookingConfirmation } from "@scandic-hotels/trpc/types/bookingConfirmation"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"use client"
|
||||
|
||||
import { useSelectRateContext } from "../../../../../contexts/SelectRate/SelectRateContext"
|
||||
import { RoomListItem } from "./RoomListItem"
|
||||
import { RoomsListSkeleton } from "./RoomsListSkeleton"
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"use client"
|
||||
|
||||
import { TRPCClientError } from "@trpc/client"
|
||||
import { useEffect } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
||||
import { Alert } from "@scandic-hotels/design-system/Alert"
|
||||
|
||||
import { useSelectRateContext } from "../../../contexts/SelectRate/SelectRateContext"
|
||||
import { trackLowestRoomPrice } from "../Tracking/tracking"
|
||||
import { RateSummary } from "./RateSummary"
|
||||
import Rooms from "./Rooms"
|
||||
import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
|
||||
@@ -23,10 +25,26 @@ export function RoomsContainer({}: RoomsContainerProps) {
|
||||
const intl = useIntl()
|
||||
|
||||
const {
|
||||
availability: { error, isFetching, isError },
|
||||
input: { hasError: hasInputError, errorCode },
|
||||
availability: { error, isFetching, isError, data: availabilityData },
|
||||
input: { hasError: hasInputError, errorCode, data: inputData },
|
||||
getLowestRoomPrice,
|
||||
} = useSelectRateContext()
|
||||
|
||||
useEffect(() => {
|
||||
if (availabilityData) {
|
||||
const lowestRoomPrice = getLowestRoomPrice()
|
||||
const booking = inputData?.booking!
|
||||
|
||||
trackLowestRoomPrice({
|
||||
hotelId: booking.hotelId,
|
||||
arrivalDate: booking?.fromDate,
|
||||
departureDate: booking?.toDate,
|
||||
lowestPrice: lowestRoomPrice.price.toString(),
|
||||
currency: lowestRoomPrice.currency,
|
||||
})
|
||||
}
|
||||
}, [availabilityData, inputData, getLowestRoomPrice])
|
||||
|
||||
if (isFetching) {
|
||||
return <RoomsContainerSkeleton />
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
||||
|
||||
import { trackEvent } from "@scandic-hotels/tracking/base"
|
||||
import {
|
||||
type LowestRoomPriceEvent,
|
||||
TrackingChannelEnum,
|
||||
type TrackingSDKHotelInfo,
|
||||
type TrackingSDKPageData,
|
||||
@@ -107,3 +109,18 @@ export function getSelectRateTracking({
|
||||
pageTrackingData,
|
||||
}
|
||||
}
|
||||
|
||||
export function trackLowestRoomPrice(event: LowestRoomPriceEvent) {
|
||||
trackEvent({
|
||||
event: "lowestRoomPrice",
|
||||
hotelInfo: {
|
||||
hotelId: event.hotelId,
|
||||
arrivalDate: event.arrivalDate,
|
||||
departureDate: event.departureDate,
|
||||
},
|
||||
viewItemInfo: {
|
||||
lowestPrice: event.lowestPrice,
|
||||
currency: event.currency,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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