Merged in feat/enter-details-tracking (pull request #1185)
Feat/enter details tracking * feat: fixed bug in enter details tracking * Sidepeek events, lowestroomPrice and analyticsRateCode * Cleanup and fixed bug * Fixed analyticsratecode * Merge master * merge master * Removed console logs * Added ancillaries tracking to enter details * Added ancillary on confirmation page * Removed console log * Merge branch 'master' into feat/enter-details-tracking * Refactor searchparams * Hard code values for breakfast ancillary Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
"use client"
|
||||
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||
import { useIntl } from "react-intl"
|
||||
|
||||
import { trackLowestRoomPrice } from "@/utils/tracking"
|
||||
|
||||
import RoomFilter from "../RoomFilter"
|
||||
import RoomSelection from "../RoomSelection"
|
||||
import { filterDuplicateRoomTypesByLowestPrice } from "./utils"
|
||||
@@ -28,6 +31,12 @@ export default function Rooms({
|
||||
hotelType,
|
||||
isUserLoggedIn,
|
||||
}: SelectRateProps) {
|
||||
const searchParams = useSearchParams()
|
||||
|
||||
const hotelId = searchParams.get("hotel")
|
||||
const arrivalDate = searchParams.get("fromDate")
|
||||
const departureDate = searchParams.get("toDate")
|
||||
|
||||
const intl = useIntl()
|
||||
|
||||
const visibleRooms: RoomConfiguration[] = useMemo(() => {
|
||||
@@ -177,6 +186,32 @@ export default function Rooms({
|
||||
setSelectedRate(undefined)
|
||||
}, [rateSummary, selectedRate])
|
||||
|
||||
useEffect(() => {
|
||||
const pricesWithCurrencies = rooms.roomConfigurations.flatMap((room) =>
|
||||
room.products.map((product) => ({
|
||||
price: product.productType.public.localPrice.pricePerNight,
|
||||
currency: product.productType.public.localPrice.currency,
|
||||
}))
|
||||
)
|
||||
|
||||
const cheapestPrice = pricesWithCurrencies.reduce(
|
||||
(minPrice, { price }) => Math.min(minPrice, price),
|
||||
Infinity
|
||||
)
|
||||
|
||||
const currency = pricesWithCurrencies.find(
|
||||
({ price }) => price === cheapestPrice
|
||||
)?.currency
|
||||
|
||||
trackLowestRoomPrice({
|
||||
hotelId,
|
||||
arrivalDate,
|
||||
departureDate,
|
||||
lowestPrice: cheapestPrice,
|
||||
currency: currency,
|
||||
})
|
||||
}, [arrivalDate, departureDate, hotelId, rooms.roomConfigurations])
|
||||
|
||||
return (
|
||||
<div className={styles.content}>
|
||||
<RoomFilter
|
||||
|
||||
Reference in New Issue
Block a user