From 93e1c740a1917ddbcf1f9ebb31f047b6886a2e1d Mon Sep 17 00:00:00 2001 From: Bianca Widstam Date: Wed, 8 Jan 2025 07:47:06 +0000 Subject: [PATCH] Merged in fix/SW-1334-filter-option-navigation (pull request #1144) fix(SW-1334): filter option saved when navigation back * fix(SW-1334): filter option saved when navigation back Approved-by: Niclas Edenvin --- .../SelectRate/RoomSelection/index.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/components/HotelReservation/SelectRate/RoomSelection/index.tsx b/components/HotelReservation/SelectRate/RoomSelection/index.tsx index ddab2f3f3..ffd712563 100644 --- a/components/HotelReservation/SelectRate/RoomSelection/index.tsx +++ b/components/HotelReservation/SelectRate/RoomSelection/index.tsx @@ -1,5 +1,5 @@ "use client" -import { useRouter, useSearchParams } from "next/navigation" +import { usePathname, useRouter, useSearchParams } from "next/navigation" import { useCallback, useEffect, useMemo, useRef } from "react" import { debounce } from "@/utils/debounce" @@ -28,6 +28,7 @@ export default function RoomSelection({ hotelType, }: RoomSelectionProps) { const router = useRouter() + const pathname = usePathname() const searchParams = useSearchParams() const isUserLoggedIn = !!user const roomRefs = useRef([]) @@ -109,9 +110,9 @@ export default function RoomSelection({ rateSummary.member.rateCode ) } - if (selectedPackages.length > 0) { - params.set(`room[${index}].packages`, selectedPackages.join(",")) - } + selectedPackages.length > 0 + ? params.set(`room[${index}].packages`, selectedPackages.join(",")) + : params.delete(`room[${index}].packages`) }) return params @@ -119,6 +120,12 @@ export default function RoomSelection({ function handleSubmit(e: React.FormEvent) { e.preventDefault() + + window.history.replaceState( + null, + "", + `${pathname}?${queryParams.toString()}` + ) router.push(`select-bed?${queryParams}`) }