refactor: url management in hotel reservation flow
This commit is contained in:
@@ -6,6 +6,7 @@ import { useFormContext } from "react-hook-form"
|
||||
import { selectHotel, selectRate } from "@/constants/routes/hotelReservation"
|
||||
|
||||
import useLang from "@/hooks/useLang"
|
||||
import { convertObjToSearchParams } from "@/utils/url"
|
||||
|
||||
import FormContent, { BookingWidgetFormContentSkeleton } from "./FormContent"
|
||||
import { bookingWidgetVariants } from "./variants"
|
||||
@@ -37,26 +38,14 @@ export default function Form({
|
||||
|
||||
const bookingFlowPage =
|
||||
locationData.type == "cities" ? selectHotel(lang) : selectRate(lang)
|
||||
const bookingWidgetParams = new URLSearchParams(data.date)
|
||||
|
||||
if (locationData.type == "cities")
|
||||
bookingWidgetParams.set("city", locationData.name)
|
||||
else bookingWidgetParams.set("hotel", locationData.operaId || "")
|
||||
|
||||
data.rooms.forEach((room, index) => {
|
||||
bookingWidgetParams.set(`room[${index}].adults`, room.adults.toString())
|
||||
|
||||
room.child.forEach((child, childIndex) => {
|
||||
bookingWidgetParams.set(
|
||||
`room[${index}].child[${childIndex}].age`,
|
||||
child.age.toString()
|
||||
)
|
||||
bookingWidgetParams.set(
|
||||
`room[${index}].child[${childIndex}].bed`,
|
||||
child.bed.toString()
|
||||
)
|
||||
})
|
||||
const bookingWidgetParams = convertObjToSearchParams({
|
||||
rooms: data.rooms,
|
||||
...data.date,
|
||||
...(locationData.type == "cities"
|
||||
? { city: locationData.name }
|
||||
: { hotel: locationData.operaId || "" }),
|
||||
})
|
||||
|
||||
onClose()
|
||||
router.push(`${bookingFlowPage}?${bookingWidgetParams.toString()}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user