From 2c7d72c540ca6fa7e1e87ab755fee6279c9d1284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20J=C3=A4derberg?= Date: Fri, 7 Mar 2025 13:37:15 +0000 Subject: [PATCH] Merged in fix/switch-to-useQuery-over-useSuspenseQuery (pull request #1495) fix: switch to using useQuery over useSuspenseQuery for booking widget * fix: switch to using useQuery over useSuspenseQuery for booking widget Approved-by: Linus Flood --- .../components/BookingWidget/Client.tsx | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/apps/scandic-web/components/BookingWidget/Client.tsx b/apps/scandic-web/components/BookingWidget/Client.tsx index 09cf4d697..ef7c99cab 100644 --- a/apps/scandic-web/components/BookingWidget/Client.tsx +++ b/apps/scandic-web/components/BookingWidget/Client.tsx @@ -41,7 +41,13 @@ export default function BookingWidgetClient({ const [isOpen, setIsOpen] = useState(false) const bookingWidgetRef = useRef(null) const lang = useLang() - const [locations] = trpc.hotel.locations.get.useSuspenseQuery({ lang }) + const { + data: locations, + isLoading, + isSuccess, + } = trpc.hotel.locations.get.useQuery({ + lang, + }) useStickyPosition({ ref: bookingWidgetRef, @@ -72,9 +78,9 @@ export default function BookingWidgetClient({ let selectedLocation: Location | null = null if (params.hotelId) { - selectedLocation = getLocationObj(locations, params.hotelId) + selectedLocation = getLocationObj(locations ?? [], params.hotelId) } else if (params.city) { - selectedLocation = getLocationObj(locations, params.city) + selectedLocation = getLocationObj(locations ?? [], params.city) } const selectedBookingCode = params.bookingCode ?? "" @@ -173,6 +179,15 @@ export default function BookingWidgetClient({ } }, [methods, selectedBookingCode]) + if (isLoading) { + return + } + + if (!isSuccess || !locations) { + // TODO: handle error cases + return null + } + return (