Merged in fix/SW-3001-select-hotel-booking-code- (pull request #2576)
Fix/SW-3001 select hotel booking code * fix(SW-3001): Fixed booking code filter store to reset to default state when new search triggered, Removed state as using useState resets the value on every filter change * fix: Route tracking parsing error in select-hotel page * fix(SW-3001): Optimized code Approved-by: Matilda Landström
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
selectHotel,
|
selectHotel,
|
||||||
selectHotelMap,
|
selectHotelMap,
|
||||||
} from "@/constants/routes/hotelReservation"
|
} from "@/constants/routes/hotelReservation"
|
||||||
|
import { useBookingCodeFilterStore } from "@/stores/bookingCode-filter"
|
||||||
|
|
||||||
import useLang from "@/hooks/useLang"
|
import useLang from "@/hooks/useLang"
|
||||||
import { trackBookingSearchClick } from "@/utils/tracking/booking"
|
import { trackBookingSearchClick } from "@/utils/tracking/booking"
|
||||||
@@ -27,6 +28,7 @@ import type {
|
|||||||
BookingWidgetType,
|
BookingWidgetType,
|
||||||
} from "@/types/components/bookingWidget"
|
} from "@/types/components/bookingWidget"
|
||||||
import type { BookingWidgetFormProps } from "@/types/components/form/bookingwidget"
|
import type { BookingWidgetFormProps } from "@/types/components/form/bookingwidget"
|
||||||
|
import { BookingCodeFilterEnum } from "@/types/enums/bookingCodeFilter"
|
||||||
|
|
||||||
const formId = "booking-widget"
|
const formId = "booking-widget"
|
||||||
|
|
||||||
@@ -35,6 +37,9 @@ export default function Form({ type, onClose }: BookingWidgetFormProps) {
|
|||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const lang = useLang()
|
const lang = useLang()
|
||||||
const [isPending, startTransition] = useTransition()
|
const [isPending, startTransition] = useTransition()
|
||||||
|
const setBookingCodeFilter = useBookingCodeFilterStore(
|
||||||
|
(state) => state.setFilter
|
||||||
|
)
|
||||||
|
|
||||||
const classNames = bookingWidgetVariants({
|
const classNames = bookingWidgetVariants({
|
||||||
type,
|
type,
|
||||||
@@ -67,13 +72,19 @@ export default function Form({ type, onClose }: BookingWidgetFormProps) {
|
|||||||
startTransition(() => {
|
startTransition(() => {
|
||||||
router.push(`${bookingFlowPage}?${bookingWidgetParams.toString()}`)
|
router.push(`${bookingFlowPage}?${bookingWidgetParams.toString()}`)
|
||||||
})
|
})
|
||||||
if (!data.bookingCode?.value) {
|
|
||||||
|
if (data.bookingCode?.value) {
|
||||||
|
// Reset the booking code filter if changed by user to "All rates"
|
||||||
|
setBookingCodeFilter(BookingCodeFilterEnum.Discounted)
|
||||||
|
|
||||||
|
if (data.bookingCode.remember) {
|
||||||
|
localStorage.setItem("bookingCode", JSON.stringify(data.bookingCode))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
setValue("bookingCode.remember", false, {
|
setValue("bookingCode.remember", false, {
|
||||||
shouldDirty: true,
|
shouldDirty: true,
|
||||||
})
|
})
|
||||||
localStorage.removeItem("bookingCode")
|
localStorage.removeItem("bookingCode")
|
||||||
} else if (data.bookingCode?.remember) {
|
|
||||||
localStorage.setItem("bookingCode", JSON.stringify(data.bookingCode))
|
|
||||||
}
|
}
|
||||||
reset(data)
|
reset(data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,7 @@ export default function BookingCodeFilter() {
|
|||||||
const activeCodeFilter = useBookingCodeFilterStore(
|
const activeCodeFilter = useBookingCodeFilterStore(
|
||||||
(state) => state.activeCodeFilter
|
(state) => state.activeCodeFilter
|
||||||
)
|
)
|
||||||
const [filter, setFilter] = useState<BookingCodeFilterEnum>(
|
const setFilter = useBookingCodeFilterStore((state) => state.setFilter)
|
||||||
BookingCodeFilterEnum.Discounted
|
|
||||||
)
|
|
||||||
|
|
||||||
const setStoreFilter = useBookingCodeFilterStore((state) => state.setFilter)
|
|
||||||
|
|
||||||
const displayAsPopover = useMediaQuery("(min-width: 768px)")
|
const displayAsPopover = useMediaQuery("(min-width: 768px)")
|
||||||
|
|
||||||
@@ -56,7 +52,6 @@ export default function BookingCodeFilter() {
|
|||||||
|
|
||||||
function updateFilter(selectedFilter: string) {
|
function updateFilter(selectedFilter: string) {
|
||||||
setFilter(selectedFilter as BookingCodeFilterEnum)
|
setFilter(selectedFilter as BookingCodeFilterEnum)
|
||||||
setStoreFilter(filter)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// To fix the hyderation error
|
// To fix the hyderation error
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import type {
|
|||||||
VoucherProduct,
|
VoucherProduct,
|
||||||
} from "@scandic-hotels/trpc/types/roomAvailability"
|
} from "@scandic-hotels/trpc/types/roomAvailability"
|
||||||
|
|
||||||
|
import type { BookingWidgetSearchData } from "@/types/components/bookingWidget"
|
||||||
import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast"
|
import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast"
|
||||||
import { type RoomRate } from "@/types/components/hotelReservation/enterDetails/details"
|
import { type RoomRate } from "@/types/components/hotelReservation/enterDetails/details"
|
||||||
import type { Price } from "@/types/components/hotelReservation/price"
|
import type { Price } from "@/types/components/hotelReservation/price"
|
||||||
@@ -48,18 +49,18 @@ export function extractGuestFromUser(user: NonNullable<SafeUser>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function checkIsSameBooking(
|
export function checkIsSameBooking(
|
||||||
prev: SelectRateBooking & { errorCode?: string },
|
prev: (SelectRateBooking | BookingWidgetSearchData) & { errorCode?: string },
|
||||||
next: SelectRateBooking & { errorCode?: string }
|
next: (SelectRateBooking | BookingWidgetSearchData) & { errorCode?: string }
|
||||||
) {
|
) {
|
||||||
const { rooms: prevRooms, errorCode: prevErrorCode, ...prevBooking } = prev
|
const { rooms: prevRooms, errorCode: prevErrorCode, ...prevBooking } = prev
|
||||||
|
|
||||||
const prevRoomsWithoutRateCodes = prevRooms?.map(
|
const prevRoomsWithoutRateCodes = prevRooms?.map(
|
||||||
({ rateCode, counterRateCode, roomTypeCode, bookingCode, ...room }) => room
|
({ adults, childrenInRoom }) => ({ adults, childrenInRoom })
|
||||||
)
|
)
|
||||||
const { rooms: nextRooms, errorCode: nextErrorCode, ...nextBooking } = next
|
const { rooms: nextRooms, errorCode: nextErrorCode, ...nextBooking } = next
|
||||||
|
|
||||||
const nextRoomsWithoutRateCodes = nextRooms?.map(
|
const nextRoomsWithoutRateCodes = nextRooms?.map(
|
||||||
({ rateCode, counterRateCode, roomTypeCode, bookingCode, ...room }) => room
|
({ adults, childrenInRoom }) => ({ adults, childrenInRoom })
|
||||||
)
|
)
|
||||||
|
|
||||||
return isEqual(
|
return isEqual(
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import { create } from "zustand"
|
import { create } from "zustand"
|
||||||
|
|
||||||
import { parseSelectRateSearchParams, searchParamsToRecord } from "@/utils/url"
|
import {
|
||||||
|
parseBookingWidgetSearchParams,
|
||||||
|
searchParamsToRecord,
|
||||||
|
} from "@/utils/url"
|
||||||
|
|
||||||
import { checkIsSameBooking } from "./enter-details/helpers"
|
import { checkIsSameBooking } from "./enter-details/helpers"
|
||||||
|
|
||||||
@@ -79,10 +82,10 @@ 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 = parseSelectRateSearchParams(
|
const previousParamsObject = parseBookingWidgetSearchParams(
|
||||||
searchParamsToRecord(previousParams)
|
searchParamsToRecord(previousParams)
|
||||||
)
|
)
|
||||||
const currentParamsObject = parseSelectRateSearchParams(
|
const currentParamsObject = parseBookingWidgetSearchParams(
|
||||||
searchParamsToRecord(currentParams)
|
searchParamsToRecord(currentParams)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user