chore: Cleanup booking widget with types and other minor issues
This commit is contained in:
@@ -97,7 +97,7 @@ export default function BookingWidgetClient({
|
||||
const defaultRoomsData: BookingWidgetSchema["rooms"] = params.rooms?.map(
|
||||
(room) => ({
|
||||
adults: room.adults,
|
||||
childrenInRoom: room.childrenInRoom ?? [],
|
||||
childrenInRoom: room.childrenInRoom,
|
||||
})
|
||||
) ?? [
|
||||
{
|
||||
@@ -149,21 +149,18 @@ export default function BookingWidgetClient({
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
const debouncedResizeHandler = debounce(function ([
|
||||
entry,
|
||||
]: ResizeObserverEntry[]) {
|
||||
if (entry.contentRect.width > 1366) {
|
||||
closeMobileSearch()
|
||||
}
|
||||
})
|
||||
const observer = new ResizeObserver(debouncedResizeHandler)
|
||||
const observer = new ResizeObserver(
|
||||
debounce(([entry]) => {
|
||||
if (entry.contentRect.width > 1366) {
|
||||
closeMobileSearch()
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
observer.observe(document.body)
|
||||
|
||||
return () => {
|
||||
if (observer) {
|
||||
observer.unobserve(document.body)
|
||||
}
|
||||
observer.unobserve(document.body)
|
||||
}
|
||||
}, [])
|
||||
|
||||
@@ -176,13 +173,15 @@ export default function BookingWidgetClient({
|
||||
? JSON.parse(sessionStorageSearchData)
|
||||
: undefined
|
||||
|
||||
initialSelectedLocation?.name &&
|
||||
if (initialSelectedLocation?.name) {
|
||||
methods.setValue("search", initialSelectedLocation.name)
|
||||
sessionStorageSearchData &&
|
||||
}
|
||||
if (sessionStorageSearchData) {
|
||||
methods.setValue(
|
||||
"location",
|
||||
encodeURIComponent(sessionStorageSearchData)
|
||||
)
|
||||
}
|
||||
}
|
||||
}, [methods, selectedLocation])
|
||||
|
||||
|
||||
@@ -27,21 +27,23 @@ export default function MobileToggleButton({
|
||||
}: BookingWidgetToggleButtonProps) {
|
||||
const intl = useIntl()
|
||||
const lang = useLang()
|
||||
const d = useWatch({ name: "date" })
|
||||
const location = useWatch({ name: "location" })
|
||||
const rooms: BookingWidgetSchema["rooms"] = useWatch({ name: "rooms" })
|
||||
const date = useWatch<BookingWidgetSchema, "date">({ name: "date" })
|
||||
const location = useWatch<BookingWidgetSchema, "location">({
|
||||
name: "location",
|
||||
})
|
||||
const rooms = useWatch<BookingWidgetSchema, "rooms">({ name: "rooms" })
|
||||
|
||||
const parsedLocation: Location | null =
|
||||
location && isValidJson(location)
|
||||
? JSON.parse(decodeURIComponent(location))
|
||||
: null
|
||||
|
||||
const selectedFromDate = dt(d.fromDate).locale(lang).format("D MMM")
|
||||
const selectedToDate = dt(d.toDate).locale(lang).format("D MMM")
|
||||
const selectedFromDate = dt(date.fromDate).locale(lang).format("D MMM")
|
||||
const selectedToDate = dt(date.toDate).locale(lang).format("D MMM")
|
||||
|
||||
const locationAndDateIsSet = parsedLocation && d
|
||||
const locationAndDateIsSet = parsedLocation && date
|
||||
|
||||
const totalNights = dt(d.toDate).diff(dt(d.fromDate), "days")
|
||||
const totalNights = dt(date.toDate).diff(dt(date.fromDate), "days")
|
||||
const totalRooms = rooms.length
|
||||
const totalAdults = rooms.reduce((acc, room) => {
|
||||
if (room.adults) {
|
||||
|
||||
Reference in New Issue
Block a user