feat: SW-449 Optimized code

This commit is contained in:
Hrishikesh Vaipurkar
2024-10-16 13:11:10 +02:00
parent 446b4269d7
commit 524c907757

View File

@@ -33,33 +33,28 @@ export default function Form({ locations, type }: BookingWidgetFormProps) {
const bookingFlowPage =
locationData.type == "cities" ? selectHotel[lang] : selectRate[lang]
const bookingWidgetParams = new URLSearchParams(data.date)
const locationParam =
locationData.type == "cities"
? "city=" + locationData.name
: "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
}, "")
if (locationData.type == "cities")
bookingWidgetParams.set("city", locationData.name)
else bookingWidgetParams.set("hotel", locationData.operaId || "")
router.push(
bookingFlowPage + "?" + locationParam + "&" + dateParam + roomsParam
)
data.rooms.forEach((room, index) => {
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 (