Merged in fix/remove-cities-without-hotels (pull request #1493)

fix: remove cities that don't have a city page

* fix: remove cities that don't have a city page


Approved-by: Erik Tiekstra
This commit is contained in:
Matilda Landström
2025-03-07 07:00:35 +00:00
parent 4db75057f2
commit 7ce2ee2922
2 changed files with 21 additions and 7 deletions

View File

@@ -34,7 +34,10 @@ import {
getDestinationOverviewPageSuccessCounter, getDestinationOverviewPageSuccessCounter,
} from "./telemetry" } from "./telemetry"
import type { DestinationsData } from "@/types/components/destinationOverviewPage/destinationsList/destinationsData" import type {
Cities,
DestinationsData,
} from "@/types/components/destinationOverviewPage/destinationsList/destinationsData"
import { import {
TrackingChannelEnum, TrackingChannelEnum,
type TrackingSDKPageData, type TrackingSDKPageData,
@@ -258,16 +261,25 @@ export const destinationOverviewPageQueryRouter = router({
(cityPage) => cityPage.city === city.cityIdentifier (cityPage) => cityPage.city === city.cityIdentifier
) )
if (!cityPage) {
return null
}
return { return {
id: city.id, id: city.id,
name: city.name, name: city.name,
hotelIds: hotels, hotelIds: hotels,
hotelCount: hotels?.length ?? 0, hotelCount: hotels?.length ?? 0,
url: cityPage?.url, url: cityPage.url,
} }
}) })
) )
const activeCitiesWithHotelCount: Cities =
citiesWithHotelCount.filter(
(city): city is Cities[number] => !!city
)
const countryPage = countryPages.find( const countryPage = countryPages.find(
(countryPage) => countryPage.country === country (countryPage) => countryPage.country === country
) )
@@ -275,11 +287,11 @@ export const destinationOverviewPageQueryRouter = router({
return { return {
country, country,
countryUrl: countryPage?.url, countryUrl: countryPage?.url,
numberOfHotels: citiesWithHotelCount.reduce( numberOfHotels: activeCitiesWithHotelCount.reduce(
(acc, city) => acc + city.hotelCount, (acc, city) => acc + city.hotelCount,
0 0
), ),
cities: citiesWithHotelCount, cities: activeCitiesWithHotelCount,
} }
}) })
) )

View File

@@ -5,12 +5,14 @@ export type DestinationsData = {
cities: { cities: {
id: string id: string
name: string name: string
hotelIds: string[] | null hotelIds: string[]
hotelCount: number hotelCount: number
url: string | undefined url: string
}[] }[]
}[] }[]
export type Cities = DestinationsData[number]["cities"]
export type HotelsSectionProps = { export type HotelsSectionProps = {
destinations: DestinationsData destinations: DestinationsData
} }
@@ -23,5 +25,5 @@ export type DestinationProps = {
country: string country: string
countryUrl: string | undefined countryUrl: string | undefined
numberOfHotels: number numberOfHotels: number
cities: DestinationsData[number]["cities"] cities: Cities
} }