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 = 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 (