Merged in fix/refactor-booking-flow-search-params (pull request #2148)

Fix: refactor booking flow search params

* wip: apply codemod and upgrade swc plugin

* wip: design-system to react 19, fix issues from async (search)params

* Prepare new parse function for booking flow search params

* Prepare serialize function for booking flow search params

* Improve handling of comma separated arrays

* Slightly refactor for readability

* Next abstracts URLSearchParams so handle the abstraction instead

* Refactor booking widget to use new search params parsing

* Rename search param functions

* Refactor select-hotel to use new search param parser

* Use new search params parser in select-rate and details

* Fix hotelId type

* Avoid passing down search params into BookingWidget components

* More updates to use new types instead of SearchParams<T>

* Remove types SelectHotelSearchParams and AlternativeSelectHotelSearchParams

* Fix parseBookingWidgetSearchParams return type

* Add error handling to booking search param parsers

* Fix modifyRateIndex handling in details page

* Clean up

* Refactor booking widget search param serializing to util function

* Move start page booking widget search param parsing to page

* Use new search param serializer in HandleErrorCallback

* Delete convertSearchParamsToObj & convertObjToSearchParams


Approved-by: Michael Zetterberg
This commit is contained in:
Anton Gunnarsson
2025-06-02 13:38:01 +00:00
parent 81887c83ff
commit 03468ad824
49 changed files with 1257 additions and 444 deletions

View File

@@ -9,7 +9,7 @@ import { detailsStorageName } from "."
import { type RoomRate } from "@/types/components/hotelReservation/enterDetails/details"
import type { Price } from "@/types/components/hotelReservation/price"
import type { SelectRateSearchParams } from "@/types/components/hotelReservation/selectRate/selectRate"
import type { SelectRateBooking } from "@/types/components/hotelReservation/selectRate/selectRate"
import { CurrencyEnum } from "@/types/enums/currency"
import type { Package } from "@/types/requests/packages"
import type { PersistedState, RoomState } from "@/types/stores/enter-details"
@@ -28,8 +28,8 @@ export function extractGuestFromUser(user: NonNullable<SafeUser>) {
}
export function checkIsSameBooking(
prev: SelectRateSearchParams & { errorCode?: string },
next: SelectRateSearchParams & { errorCode?: string }
prev: SelectRateBooking & { errorCode?: string },
next: SelectRateBooking & { errorCode?: string }
) {
const { rooms: prevRooms, errorCode: prevErrorCode, ...prevBooking } = prev

View File

@@ -45,10 +45,14 @@ export function findProduct(
}
export function findProductInRoom(
rateCode: string,
rateCode: string | undefined,
room: RoomConfiguration,
counterRateCode = ""
) {
if (!rateCode) {
return null
}
if (room.campaign.length) {
const campaignProduct = room.campaign.find((product) =>
findProduct(rateCode, product, counterRateCode)
@@ -84,14 +88,19 @@ export function findProductInRoom(
}
export function findSelectedRate(
rateCode: string,
counterRateCode: string,
roomTypeCode: string,
rateCode: string | undefined,
counterRateCode: string | undefined,
roomTypeCode: string | undefined,
rooms: RoomConfiguration[] | AvailabilityError
) {
if (!Array.isArray(rooms)) {
return null
}
if (!rateCode) {
return null
}
return rooms.find((room) => {
if (room.roomTypeCode !== roomTypeCode) {
return false

View File

@@ -2,14 +2,12 @@
import { create } from "zustand"
import { convertSearchParamsToObj, searchParamsToRecord } from "@/utils/url"
import { parseSelectRateSearchParams, 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
@@ -81,14 +79,15 @@ const useTrackingStore = create<TrackingStoreState>((set, get) => ({
if (!currentPath?.match(/^\/(da|de|en|fi|no|sv)\/(hotelreservation)/))
return false
const previousParamsObject =
convertSearchParamsToObj<SelectRateSearchParams>(
searchParamsToRecord(previousParams)
)
const currentParamsObject =
convertSearchParamsToObj<SelectRateSearchParams>(
searchParamsToRecord(currentParams)
)
const previousParamsObject = parseSelectRateSearchParams(
searchParamsToRecord(previousParams)
)
const currentParamsObject = parseSelectRateSearchParams(
searchParamsToRecord(currentParams)
)
if (!previousParamsObject && !currentParamsObject) return false
if (!previousParamsObject || !currentParamsObject) return true
const isSameBooking = checkIsSameBooking(
previousParamsObject,