fix(SW-1143): added safeTry
This commit is contained in:
@@ -15,6 +15,7 @@ import Button from "@/components/TempDesignSystem/Button"
|
|||||||
import Link from "@/components/TempDesignSystem/Link"
|
import Link from "@/components/TempDesignSystem/Link"
|
||||||
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
||||||
import { getIntl } from "@/i18n"
|
import { getIntl } from "@/i18n"
|
||||||
|
import { safeTry } from "@/utils/safeTry"
|
||||||
|
|
||||||
import HotelCardListing from "../HotelCardListing"
|
import HotelCardListing from "../HotelCardListing"
|
||||||
import HotelCount from "./HotelCount"
|
import HotelCount from "./HotelCount"
|
||||||
@@ -38,20 +39,23 @@ export default async function SelectHotel({
|
|||||||
|
|
||||||
const intl = await getIntl()
|
const intl = await getIntl()
|
||||||
|
|
||||||
const hotels = await fetchAvailableHotels({
|
const hotelsPromise = safeTry(
|
||||||
|
fetchAvailableHotels({
|
||||||
cityId: city.id,
|
cityId: city.id,
|
||||||
roomStayStartDate: searchParams.fromDate,
|
roomStayStartDate: searchParams.fromDate,
|
||||||
roomStayEndDate: searchParams.toDate,
|
roomStayEndDate: searchParams.toDate,
|
||||||
adults: adultsParams,
|
adults: adultsParams,
|
||||||
children: childrenParams?.toString(),
|
children: childrenParams?.toString(),
|
||||||
})
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const [hotels] = await hotelsPromise
|
||||||
|
|
||||||
const isCityWithCountry = (city: any): city is { country: string } =>
|
const isCityWithCountry = (city: any): city is { country: string } =>
|
||||||
"country" in city
|
"country" in city
|
||||||
|
|
||||||
const validHotels = hotels.filter(
|
const validHotels =
|
||||||
(hotel): hotel is HotelData => hotel !== null
|
hotels?.filter((hotel): hotel is HotelData => hotel !== null) || []
|
||||||
)
|
|
||||||
|
|
||||||
const filterList = getFiltersFromHotels(validHotels)
|
const filterList = getFiltersFromHotels(validHotels)
|
||||||
const breadcrumbs = [
|
const breadcrumbs = [
|
||||||
@@ -76,7 +80,7 @@ export default async function SelectHotel({
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const isAllUnavailable = hotels.every((hotel) => hotel.price === undefined)
|
const isAllUnavailable = hotels?.every((hotel) => hotel.price === undefined)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -95,7 +99,7 @@ export default async function SelectHotel({
|
|||||||
</header>
|
</header>
|
||||||
<main className={styles.main}>
|
<main className={styles.main}>
|
||||||
<div className={styles.sideBar}>
|
<div className={styles.sideBar}>
|
||||||
{hotels.length > 0 ? ( // TODO: Temp fix until API returns hotels that are not available
|
{hotels && hotels.length > 0 ? ( // TODO: Temp fix until API returns hotels that are not available
|
||||||
<Link
|
<Link
|
||||||
className={styles.link}
|
className={styles.link}
|
||||||
color="burgundy"
|
color="burgundy"
|
||||||
|
|||||||
Reference in New Issue
Block a user