Merged in fix/SW-1353-and-SW-2497-tracking-fixes (pull request #1977)
fix: tracking fixes SW-1353 and SW-2497 * fix: tracking fixes * fix: remove console log and rename variable Approved-by: Michael Zetterberg Approved-by: Arvid Norlin
This commit is contained in:
@@ -14,26 +14,24 @@ import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmat
|
||||
|
||||
export default function Tracking({
|
||||
bookingConfirmation,
|
||||
refId,
|
||||
}: {
|
||||
bookingConfirmation: BookingConfirmation
|
||||
refId: string
|
||||
}) {
|
||||
const lang = useLang()
|
||||
const bookingRooms = useBookingConfirmationStore((state) => state.rooms)
|
||||
|
||||
const [hasLoadedBookingConfirmation] = useState(() => {
|
||||
const [loadedBookingConfirmationRefId] = useState(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
return sessionStorage.getItem("hasLoadedBookingConfirmation")
|
||||
return sessionStorage.getItem("loadedBookingConfirmationRefId")
|
||||
}
|
||||
return null
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
sessionStorage.setItem("hasLoadedBookingConfirmation", "true")
|
||||
|
||||
return () => {
|
||||
sessionStorage.removeItem("hasLoadedBookingConfirmation")
|
||||
}
|
||||
}, [])
|
||||
sessionStorage.setItem("loadedBookingConfirmationRefId", refId)
|
||||
}, [refId])
|
||||
|
||||
if (!bookingRooms.every(Boolean)) {
|
||||
return null
|
||||
@@ -52,9 +50,17 @@ export default function Tracking({
|
||||
return (
|
||||
<TrackingSDK
|
||||
pageData={pageTrackingData}
|
||||
hotelInfo={hasLoadedBookingConfirmation ? undefined : hotelsTrackingData}
|
||||
paymentInfo={hasLoadedBookingConfirmation ? undefined : paymentInfo}
|
||||
ancillaries={hasLoadedBookingConfirmation ? undefined : ancillaries}
|
||||
hotelInfo={
|
||||
loadedBookingConfirmationRefId === refId
|
||||
? undefined
|
||||
: hotelsTrackingData
|
||||
}
|
||||
paymentInfo={
|
||||
loadedBookingConfirmationRefId === refId ? undefined : paymentInfo
|
||||
}
|
||||
ancillaries={
|
||||
loadedBookingConfirmationRefId === refId ? undefined : ancillaries
|
||||
}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ export default async function BookingConfirmation({
|
||||
</SidePanel>
|
||||
</aside>
|
||||
</Confirmation>
|
||||
<Tracking bookingConfirmation={bookingConfirmation} />
|
||||
<Tracking bookingConfirmation={bookingConfirmation} refId={refId} />
|
||||
</BookingConfirmationProvider>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ export function getTracking(
|
||||
.join("|"),
|
||||
country: hotel?.address.country,
|
||||
departureDate: format(departureDate, "yyyy-MM-dd"),
|
||||
discount: rooms.reduce((total, room, idx) => {
|
||||
discount: storedRooms.reduce((total, { room }, idx) => {
|
||||
const isMainRoom = idx === 0
|
||||
if (
|
||||
hasMemberPrice(room.roomRate) &&
|
||||
@@ -184,8 +184,8 @@ export function getTracking(
|
||||
rewardNight: booking.searchType === REDEMPTION ? "yes" : "no",
|
||||
rewardNightAvailability:
|
||||
booking.searchType === REDEMPTION ? "true" : "false",
|
||||
roomPrice: calcTotalRoomPrice(rooms, isMember),
|
||||
totalPrice: calcTotalPrice(rooms, isMember),
|
||||
roomPrice: calcTotalRoomPrice(storedRooms, isMember),
|
||||
totalPrice: calcTotalPrice(storedRooms, isMember),
|
||||
points:
|
||||
// @ts-expect-error - redemption object doesn't exist error
|
||||
rooms.find((room) => "redemption" in room.roomRate)?.roomRate.redemption
|
||||
@@ -286,17 +286,23 @@ function hasBreakfast(entry: RoomEntry): entry is RoomEntry & {
|
||||
)
|
||||
}
|
||||
|
||||
function calcTotalPrice(rooms: Room[], isMember: boolean) {
|
||||
function calcTotalPrice(rooms: RoomState[], isMember: boolean) {
|
||||
const totalRoomPrice = calcTotalRoomPrice(rooms, isMember)
|
||||
const totalPackageSum = rooms.reduce((total, room) => {
|
||||
const packageSum = sumPackages(room.packages)
|
||||
return (total += packageSum.price ?? 0)
|
||||
const totalPackageSum = rooms.reduce((total, { room }) => {
|
||||
if (room.breakfast) {
|
||||
total += Number(room.breakfast.localPrice.totalPrice) * room.adults
|
||||
}
|
||||
if (room.roomFeatures?.length) {
|
||||
const packageSum = sumPackages(room.roomFeatures)
|
||||
total += packageSum.price
|
||||
}
|
||||
return total
|
||||
}, 0)
|
||||
return totalRoomPrice + totalPackageSum
|
||||
}
|
||||
|
||||
function calcTotalRoomPrice(rooms: Room[], isMember: boolean) {
|
||||
return rooms.reduce((total, room, idx) => {
|
||||
function calcTotalRoomPrice(rooms: RoomState[], isMember: boolean) {
|
||||
return rooms.reduce((total, { room }, idx) => {
|
||||
// When it comes special rates, only redemption has additional price and that should be added
|
||||
// other special rates like voucher, corporateCheck should be added as 0 according to Priyanka
|
||||
if ("redemption" in room.roomRate) {
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
"use client"
|
||||
|
||||
import isEqual from "fast-deep-equal"
|
||||
import { create } from "zustand"
|
||||
|
||||
import { convertSearchParamsToObj, searchParamsToRecord } from "@/utils/url"
|
||||
|
||||
import { checkIsSameBooking } from "./enter-details/helpers"
|
||||
|
||||
import type { ReadonlyURLSearchParams } from "next/navigation"
|
||||
|
||||
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
|
||||
|
||||
interface TrackingStoreState {
|
||||
initialStartTime: number
|
||||
setInitialPageLoadTime: (time: number) => void
|
||||
@@ -78,14 +81,20 @@ const useTrackingStore = create<TrackingStoreState>((set, get) => ({
|
||||
if (!currentPath?.match(/^\/(da|de|en|fi|no|sv)\/(hotelreservation)/))
|
||||
return false
|
||||
|
||||
const previousParamsObject = convertSearchParamsToObj(
|
||||
searchParamsToRecord(previousParams)
|
||||
)
|
||||
const currentParamsObject = convertSearchParamsToObj(
|
||||
searchParamsToRecord(currentParams)
|
||||
)
|
||||
const previousParamsObject =
|
||||
convertSearchParamsToObj<SelectRateSearchParams>(
|
||||
searchParamsToRecord(previousParams)
|
||||
)
|
||||
const currentParamsObject =
|
||||
convertSearchParamsToObj<SelectRateSearchParams>(
|
||||
searchParamsToRecord(currentParams)
|
||||
)
|
||||
|
||||
return !isEqual(previousParamsObject, currentParamsObject)
|
||||
const isSameBooking = checkIsSameBooking(
|
||||
previousParamsObject,
|
||||
currentParamsObject
|
||||
)
|
||||
return !isSameBooking
|
||||
},
|
||||
}))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user