Merged in feat/sw-2873-move-selecthotel-to-booking-flow (pull request #2727)

feat(SW-2873): Move select-hotel to booking flow

* crude setup of select-hotel in partner-sas

* wip

* Fix linting

* restructure tracking files

* Remove dependency on trpc in tracking hooks

* Move pageview tracking to common

* Fix some lint and import issues

* Add AlternativeHotelsPage

* Add SelectHotelMapPage

* Add AlternativeHotelsMapPage

* remove next dependency in tracking store

* Remove dependency on react in tracking hooks

* move isSameBooking to booking-flow

* Inject searchParamsComparator into tracking store

* Move useTrackHardNavigation to common

* Move useTrackSoftNavigation to common

* Add TrackingSDK to partner-sas

* call serverclient in layout

* Remove unused css

* Update types

* Move HotelPin type

* Fix todos

* Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow

* Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow

* Fix component


Approved-by: Joakim Jäderberg
This commit is contained in:
Anton Gunnarsson
2025-09-01 08:37:00 +00:00
parent 93a90bef9d
commit 87402a2092
157 changed files with 2026 additions and 1376 deletions

View File

@@ -48,33 +48,6 @@ export function extractGuestFromUser(user: NonNullable<SafeUser>) {
}
}
export function checkIsSameBooking(
prev: (SelectRateBooking | BookingWidgetSearchData) & { errorCode?: string },
next: (SelectRateBooking | BookingWidgetSearchData) & { errorCode?: string }
) {
const { rooms: prevRooms, errorCode: prevErrorCode, ...prevBooking } = prev
const prevRoomsWithoutRateCodes = prevRooms?.map(
({ adults, childrenInRoom }) => ({ adults, childrenInRoom })
)
const { rooms: nextRooms, errorCode: nextErrorCode, ...nextBooking } = next
const nextRoomsWithoutRateCodes = nextRooms?.map(
({ adults, childrenInRoom }) => ({ adults, childrenInRoom })
)
return isEqual(
{
...prevBooking,
rooms: prevRoomsWithoutRateCodes,
},
{
...nextBooking,
rooms: nextRoomsWithoutRateCodes,
}
)
}
export function add(...nums: (number | string | undefined)[]) {
return nums.reduce((total: number, num) => {
if (typeof num === "undefined") {

View File

@@ -1,29 +0,0 @@
import { create } from "zustand"
interface HotelFilterState {
activeFilters: string[]
toggleFilter: (filterId: string) => void
setFilters: (filters: string[]) => void
resultCount: number
unfilteredResultCount: number
setResultCount: (count: number, unfilteredCount: number) => void
}
export const useHotelFilterStore = create<HotelFilterState>((set) => ({
activeFilters: [],
setFilters: (filters) => set({ activeFilters: filters }),
toggleFilter: (filterId: string) =>
set((state) => {
const isActive = state.activeFilters.includes(filterId)
const newFilters = isActive
? state.activeFilters.filter((id) => id !== filterId)
: [...state.activeFilters, filterId]
return { activeFilters: newFilters }
}),
resultCount: 0,
unfilteredResultCount: 0,
setResultCount: (count, unfilteredCount) =>
set({ resultCount: count, unfilteredResultCount: unfilteredCount }),
}))

View File

@@ -1,43 +0,0 @@
import { create } from "zustand"
interface HotelsMapState {
activeHotel: string | null
hoveredHotel: string | null
hoverTimeout: number | null
activate: (hotel: string | null) => void
deactivate: () => void
engage: (hotel: string | null) => void
disengage: () => void
disengageAfterDelay: () => void
}
export const useHotelsMapStore = create<HotelsMapState>((set, get) => ({
activeHotel: null,
hoveredHotel: null,
hoverTimeout: null,
activate: (hotel) => set({ activeHotel: hotel }),
deactivate: () => set({ activeHotel: null }),
engage: (hotel) => {
const state = get()
if (state.hoverTimeout) {
window.clearTimeout(state.hoverTimeout)
}
if (hotel && state.activeHotel) {
set({ activeHotel: null })
}
set({ hoveredHotel: hotel })
},
disengage: () => {
set({ hoveredHotel: null })
},
disengageAfterDelay: () => {
const timeoutId = window.setTimeout(() => {
set({ hoveredHotel: null, activeHotel: null, hoverTimeout: null })
}, 3000)
set({ hoverTimeout: timeoutId })
},
}))

View File

@@ -1,17 +0,0 @@
"use client"
import { create } from "zustand"
interface RouterTransitionState {
isTransitioning: boolean
startRouterTransition: () => void
stopRouterTransition: () => void
}
const useRouterTransitionStore = create<RouterTransitionState>((set) => ({
isTransitioning: false,
startRouterTransition: () => set(() => ({ isTransitioning: true })),
stopRouterTransition: () => set(() => ({ isTransitioning: false })),
}))
export default useRouterTransitionStore

View File

@@ -1,103 +0,0 @@
"use client"
import { create } from "zustand"
import {
parseBookingWidgetSearchParams,
searchParamsToRecord,
} from "@scandic-hotels/booking-flow/utils/url"
import { checkIsSameBooking } from "./enter-details/helpers"
import type { ReadonlyURLSearchParams } from "next/navigation"
interface TrackingStoreState {
initialStartTime: number
setInitialPageLoadTime: (time: number) => void
getPageLoadTime: () => number
currentParams: ReadonlyURLSearchParams | null
previousParams: ReadonlyURLSearchParams | null
currentPath: string | null
previousPath: string | null
currentLang: string | null
previousLang: string | null
updateRouteInfo: (
path: string,
lang: string,
params: ReadonlyURLSearchParams
) => void
hasPathOrLangChanged: () => boolean
hasBookingFlowParamsChanged: () => boolean
}
const useTrackingStore = create<TrackingStoreState>((set, get) => ({
initialStartTime: Date.now(),
setInitialPageLoadTime: (time) => set({ initialStartTime: time }),
getPageLoadTime: () => {
const { initialStartTime } = get()
return (Date.now() - initialStartTime) / 1000
},
currentParams: null,
previousParams: null,
currentPath: null,
previousPath: null,
currentLang: null,
previousLang: null,
updateRouteInfo: (path, lang, params) =>
set((state) => {
if (!path || !lang) return state
if (!state.currentPath || !state.currentLang) {
return {
currentParams: params,
currentPath: path,
currentLang: lang,
previousParams: null,
previousPath: null,
previousLang: null,
}
}
return {
previousParams: state.currentParams,
previousPath: state.currentPath,
previousLang: state.currentLang,
currentParams: params,
currentPath: path,
currentLang: lang,
}
}),
hasPathOrLangChanged: () => {
const { currentPath, previousPath, currentLang, previousLang } = get()
if (!previousPath || !previousLang) return false
return currentPath !== previousPath || currentLang !== previousLang
},
hasBookingFlowParamsChanged: () => {
const { currentPath, currentParams, previousParams } = get()
if (!previousParams || !currentParams) return false
if (!currentPath?.match(/^\/(da|de|en|fi|no|sv)\/(hotelreservation)/))
return false
const previousParamsObject = parseBookingWidgetSearchParams(
searchParamsToRecord(previousParams)
)
const currentParamsObject = parseBookingWidgetSearchParams(
searchParamsToRecord(currentParams)
)
if (!previousParamsObject && !currentParamsObject) return false
if (!previousParamsObject || !currentParamsObject) return true
const isSameBooking = checkIsSameBooking(
previousParamsObject,
currentParamsObject
)
return !isSameBooking
},
}))
export default useTrackingStore