chore: Cleanup booking widget with types and other minor issues

This commit is contained in:
Christian Andolf
2025-04-02 10:06:28 +02:00
parent 3c810d67a2
commit 14f9b68365
9 changed files with 92 additions and 98 deletions
@@ -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])