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}`) }