Merged in feat/book-530-selectrate-tracking (pull request #3128)
feat(BOOK-530): fixed noAvailableRooms tracking on select rate page * feat(BOOK-530): fixed noAvailableRooms tracking on select rate page Approved-by: Bianca Widstam
This commit is contained in:
@@ -6,8 +6,13 @@ import { useIntl } from "react-intl"
|
||||
|
||||
import { AlertTypeEnum } from "@scandic-hotels/common/constants/alert"
|
||||
import { Alert } from "@scandic-hotels/design-system/Alert"
|
||||
import { trackNoAvailability } from "@scandic-hotels/tracking/NoAvailabilityTracking"
|
||||
import { SEARCH_TYPE_REDEMPTION } from "@scandic-hotels/trpc/constants/booking"
|
||||
import { AvailabilityEnum } from "@scandic-hotels/trpc/enums/selectHotel"
|
||||
|
||||
import { useSelectRateContext } from "../../../contexts/SelectRate/SelectRateContext"
|
||||
import useLang from "../../../hooks/useLang"
|
||||
import { mapPackageToLabel } from "../../../utils/getRoomFeatureDescription"
|
||||
import { trackLowestRoomPrice, trackRoomsLoaded } from "../Tracking/tracking"
|
||||
import { RateSummary } from "./RateSummary"
|
||||
import Rooms from "./Rooms"
|
||||
@@ -23,8 +28,10 @@ interface RoomsContainerProps
|
||||
|
||||
export function RoomsContainer({}: RoomsContainerProps) {
|
||||
const intl = useIntl()
|
||||
const lang = useLang()
|
||||
|
||||
const {
|
||||
hotel,
|
||||
availability: { error, isFetching, isError, data: availabilityData },
|
||||
input: { hasError: hasInputError, errorCode, data: inputData },
|
||||
getLowestRoomPrice,
|
||||
@@ -33,7 +40,20 @@ export function RoomsContainer({}: RoomsContainerProps) {
|
||||
const { price: lowestRoomPrice, currency: lowestRoomPriceCurrency } =
|
||||
getLowestRoomPrice() ?? {}
|
||||
const dataAvailable = availabilityData?.length
|
||||
const { hotelId, fromDate, toDate } = inputData?.booking ?? {}
|
||||
const { hotelId, fromDate, toDate, bookingCode, searchType, rooms } =
|
||||
inputData?.booking ?? {}
|
||||
|
||||
const specialRoomType = rooms
|
||||
?.map((room) => {
|
||||
const packages = room.packages
|
||||
?.map((pkg) => {
|
||||
mapPackageToLabel(pkg)
|
||||
})
|
||||
.join(",")
|
||||
|
||||
return packages ?? ""
|
||||
})
|
||||
.join("|")
|
||||
|
||||
useEffect(() => {
|
||||
if (!dataAvailable) return
|
||||
@@ -61,6 +81,48 @@ export function RoomsContainer({}: RoomsContainerProps) {
|
||||
trackRoomsLoaded()
|
||||
}, [isFetching])
|
||||
|
||||
useEffect(() => {
|
||||
if (isFetching || !availabilityData || !toDate || !fromDate) return
|
||||
const shouldTrackNoAvailability = availabilityData.some((room) => {
|
||||
if (!room || "error" in room) return false
|
||||
|
||||
return room.roomConfigurations.every(
|
||||
(roomConfig) => roomConfig.status === AvailabilityEnum.NotAvailable
|
||||
)
|
||||
})
|
||||
if (shouldTrackNoAvailability) {
|
||||
trackNoAvailability({
|
||||
specialRoomType,
|
||||
searchTerm: hotel.data?.additionalData?.name || "",
|
||||
lang,
|
||||
fromDate,
|
||||
toDate,
|
||||
noOfRooms: rooms?.length,
|
||||
searchType: "hotel",
|
||||
hotelId,
|
||||
rewardNight: searchType === SEARCH_TYPE_REDEMPTION ? "yes" : "no",
|
||||
bookingCode,
|
||||
pageId: "select-rate",
|
||||
pageName: "hotelreservation|select-rate",
|
||||
pageType: "bookingroomsandratespage",
|
||||
siteSections: "hotelreservation|select-rate",
|
||||
domain: typeof window !== "undefined" ? window.location.host : "",
|
||||
})
|
||||
}
|
||||
}, [
|
||||
isFetching,
|
||||
availabilityData,
|
||||
bookingCode,
|
||||
hotelId,
|
||||
fromDate,
|
||||
toDate,
|
||||
specialRoomType,
|
||||
hotel.data?.additionalData?.name,
|
||||
rooms?.length,
|
||||
searchType,
|
||||
lang,
|
||||
])
|
||||
|
||||
if (isFetching) {
|
||||
return <RoomsContainerSkeleton />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user