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 { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
|
||||||
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
||||||
|
|
||||||
import { readPaymentInfoFromSessionStorage } from "../../../components/EnterDetails/Payment/helpers"
|
|
||||||
import { invertedBedTypeMap } from "../../../utils/SelectRate"
|
import { invertedBedTypeMap } from "../../../utils/SelectRate"
|
||||||
import { getSpecialRoomType } from "../../../utils/specialRoomType"
|
import { getSpecialRoomType } from "../../../utils/specialRoomType"
|
||||||
|
import { readPaymentInfoFromSessionStorage } from "../../EnterDetails/Payment/helpers"
|
||||||
|
|
||||||
import type { Lang } from "@scandic-hotels/common/constants/language"
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
||||||
import type { BookingConfirmation } from "@scandic-hotels/trpc/types/bookingConfirmation"
|
import type { BookingConfirmation } from "@scandic-hotels/trpc/types/bookingConfirmation"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { useSelectRateContext } from "../../../../../contexts/SelectRate/SelectRateContext"
|
import { useSelectRateContext } from "../../../../../contexts/SelectRate/SelectRateContext"
|
||||||
import { RoomListItem } from "./RoomListItem"
|
import { RoomListItem } from "./RoomListItem"
|
||||||
import { RoomsListSkeleton } from "./RoomsListSkeleton"
|
import { RoomsListSkeleton } from "./RoomsListSkeleton"
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
|
||||||
import { TRPCClientError } from "@trpc/client"
|
import { TRPCClientError } from "@trpc/client"
|
||||||
|
import { useEffect } from "react"
|
||||||
import { useIntl } from "react-intl"
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
||||||
import { Alert } from "@scandic-hotels/design-system/Alert"
|
import { Alert } from "@scandic-hotels/design-system/Alert"
|
||||||
|
|
||||||
import { useSelectRateContext } from "../../../contexts/SelectRate/SelectRateContext"
|
import { useSelectRateContext } from "../../../contexts/SelectRate/SelectRateContext"
|
||||||
|
import { trackLowestRoomPrice } from "../Tracking/tracking"
|
||||||
import { RateSummary } from "./RateSummary"
|
import { RateSummary } from "./RateSummary"
|
||||||
import Rooms from "./Rooms"
|
import Rooms from "./Rooms"
|
||||||
import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
|
import { RoomsContainerSkeleton } from "./RoomsContainerSkeleton"
|
||||||
@@ -23,10 +25,26 @@ export function RoomsContainer({}: RoomsContainerProps) {
|
|||||||
const intl = useIntl()
|
const intl = useIntl()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
availability: { error, isFetching, isError },
|
availability: { error, isFetching, isError, data: availabilityData },
|
||||||
input: { hasError: hasInputError, errorCode },
|
input: { hasError: hasInputError, errorCode, data: inputData },
|
||||||
|
getLowestRoomPrice,
|
||||||
} = useSelectRateContext()
|
} = 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) {
|
if (isFetching) {
|
||||||
return <RoomsContainerSkeleton />
|
return <RoomsContainerSkeleton />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
import { differenceInCalendarDays, format, isWeekend } from "date-fns"
|
||||||
|
|
||||||
|
import { trackEvent } from "@scandic-hotels/tracking/base"
|
||||||
import {
|
import {
|
||||||
|
type LowestRoomPriceEvent,
|
||||||
TrackingChannelEnum,
|
TrackingChannelEnum,
|
||||||
type TrackingSDKHotelInfo,
|
type TrackingSDKHotelInfo,
|
||||||
type TrackingSDKPageData,
|
type TrackingSDKPageData,
|
||||||
@@ -107,3 +109,18 @@ export function getSelectRateTracking({
|
|||||||
pageTrackingData,
|
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 { isRateSelected as isRateSelected_Inner } from "./isRateSelected"
|
||||||
|
|
||||||
import type { BreakfastPackageEnum } from "@scandic-hotels/trpc/enums/breakfast"
|
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 { SelectRateBooking } from "../../types/components/selectRate/selectRate"
|
||||||
import type { Price } from "../../types/price"
|
import type { Price } from "../../types/price"
|
||||||
@@ -380,6 +381,8 @@ export function SelectRateProvider({
|
|||||||
roomIndex,
|
roomIndex,
|
||||||
roomAvailabilityWithAdjustedRoomCount
|
roomAvailabilityWithAdjustedRoomCount
|
||||||
),
|
),
|
||||||
|
getLowestRoomPrice: () =>
|
||||||
|
getLowestRoomPrice(roomAvailabilityWithAdjustedRoomCount),
|
||||||
isRateSelected,
|
isRateSelected,
|
||||||
getPackagesForRoom,
|
getPackagesForRoom,
|
||||||
bookingCodeFilter,
|
bookingCodeFilter,
|
||||||
@@ -520,6 +523,28 @@ function calculateNumberOfNights(
|
|||||||
return dt(toDate).diff(dt(fromDate), "day")
|
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(
|
function getAvailabilityForRoom(
|
||||||
roomIndex: number,
|
roomIndex: number,
|
||||||
roomAvailability: (AvailabilityWithRoomInfo | null)[][] | undefined
|
roomAvailability: (AvailabilityWithRoomInfo | null)[][] | undefined
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { type RouterOutput } from "@scandic-hotels/trpc/client"
|
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 { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter"
|
||||||
import type { RoomsAvailabilityOutputSchema } from "@scandic-hotels/trpc/routers/hotels/availability/selectRate/rooms/schema"
|
import type { RoomsAvailabilityOutputSchema } from "@scandic-hotels/trpc/routers/hotels/availability/selectRate/rooms/schema"
|
||||||
import type { PackageEnum } from "@scandic-hotels/trpc/types/packages"
|
import type { PackageEnum } from "@scandic-hotels/trpc/types/packages"
|
||||||
@@ -31,6 +32,11 @@ export type SelectRateContext = {
|
|||||||
roomIndex: number
|
roomIndex: number
|
||||||
) => AvailabilityWithRoomInfo[] | undefined
|
) => AvailabilityWithRoomInfo[] | undefined
|
||||||
|
|
||||||
|
getLowestRoomPrice: () => {
|
||||||
|
price: number
|
||||||
|
currency: CurrencyEnum
|
||||||
|
}
|
||||||
|
|
||||||
getPackagesForRoom: (roomIndex: number) => {
|
getPackagesForRoom: (roomIndex: number) => {
|
||||||
selectedPackages: RoomPackage[]
|
selectedPackages: RoomPackage[]
|
||||||
availablePackages: (DefaultRoomPackage | RoomPackage)[]
|
availablePackages: (DefaultRoomPackage | RoomPackage)[]
|
||||||
|
|||||||
Reference in New Issue
Block a user