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