feat: SW-449 Optimized code
This commit is contained in:
@@ -33,33 +33,28 @@ export default function Form({ locations, type }: BookingWidgetFormProps) {
|
|||||||
|
|
||||||
const bookingFlowPage =
|
const bookingFlowPage =
|
||||||
locationData.type == "cities" ? selectHotel[lang] : selectRate[lang]
|
locationData.type == "cities" ? selectHotel[lang] : selectRate[lang]
|
||||||
|
const bookingWidgetParams = new URLSearchParams(data.date)
|
||||||
|
|
||||||
const locationParam =
|
if (locationData.type == "cities")
|
||||||
locationData.type == "cities"
|
bookingWidgetParams.set("city", locationData.name)
|
||||||
? "city=" + locationData.name
|
else bookingWidgetParams.set("hotel", locationData.operaId || "")
|
||||||
: "hotel=" + locationData.operaId
|
|
||||||
const dateParam = new URLSearchParams(data.date).toString()
|
|
||||||
const roomsParam = data.rooms.reduce((result, room, index) => {
|
|
||||||
result = result + `&rooms[${index}].adults=` + room.adults
|
|
||||||
result =
|
|
||||||
result +
|
|
||||||
room.children.reduce((childParams, child, childIndex) => {
|
|
||||||
childParams =
|
|
||||||
childParams +
|
|
||||||
`&rooms[${index}].child[${childIndex}].age=` +
|
|
||||||
child.age
|
|
||||||
childParams =
|
|
||||||
childParams +
|
|
||||||
`&rooms[${index}].child[${childIndex}].bed=` +
|
|
||||||
child.bed
|
|
||||||
return childParams
|
|
||||||
}, "")
|
|
||||||
return result
|
|
||||||
}, "")
|
|
||||||
|
|
||||||
router.push(
|
data.rooms.forEach((room, index) => {
|
||||||
bookingFlowPage + "?" + locationParam + "&" + dateParam + roomsParam
|
bookingWidgetParams.set(`room[${index}].adults`, `${room.adults}`)
|
||||||
)
|
|
||||||
|
room.children.map((child, childIndex) => {
|
||||||
|
bookingWidgetParams.set(
|
||||||
|
`room[${index}].child[${childIndex}].age`,
|
||||||
|
`${child.age}`
|
||||||
|
)
|
||||||
|
bookingWidgetParams.set(
|
||||||
|
`room[${index}].child[${childIndex}].bed`,
|
||||||
|
`${child.bed}`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
router.push(`${bookingFlowPage}?${bookingWidgetParams.toString()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user