feat(SW-1446): add Jump to functionality to Destination Overview Page
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { isDefined } from "@/server/utils"
|
||||
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
import { cache } from "@/utils/cache"
|
||||
|
||||
@@ -268,3 +270,79 @@ export const getPageSettingsBookingCode = cache(
|
||||
export const getJobylonFeed = cache(async function getMemoizedJobylonFeed() {
|
||||
return serverClient().partner.jobylon.feed.get()
|
||||
})
|
||||
|
||||
export const getJumpToData = cache(async function getMemoizedJumpToData() {
|
||||
const lang = getLang()
|
||||
const [locationsResults, urlsResults] = await Promise.allSettled([
|
||||
getLocations(),
|
||||
serverClient().hotel.locations.urls({ lang }),
|
||||
])
|
||||
|
||||
if (
|
||||
locationsResults.status === "fulfilled" &&
|
||||
urlsResults.status === "fulfilled"
|
||||
) {
|
||||
const locations = locationsResults.value
|
||||
const urls = urlsResults.value
|
||||
|
||||
if (!locations || !urls) {
|
||||
return null
|
||||
}
|
||||
|
||||
return locations
|
||||
.map((location) => {
|
||||
const { id, name, type } = location
|
||||
|
||||
const isCity = type === "cities"
|
||||
const isHotel = type === "hotels"
|
||||
|
||||
let url: string | undefined
|
||||
|
||||
if (isCity) {
|
||||
url = urls.cities.find(
|
||||
(c) =>
|
||||
c.id &&
|
||||
location.cityIdentifier &&
|
||||
c.id === location.cityIdentifier
|
||||
)?.url
|
||||
} else if (isHotel) {
|
||||
url = urls.hotels.find(
|
||||
(h) => h.id && location.id && h.id === location.id
|
||||
)?.url
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
return null
|
||||
}
|
||||
|
||||
let description = ""
|
||||
if (isCity) {
|
||||
description = location.country
|
||||
} else if (isHotel) {
|
||||
description = location.relationships.city.name
|
||||
}
|
||||
|
||||
const rankingNames: string[] = [location.name]
|
||||
if (isCity) {
|
||||
if (location.cityIdentifier) {
|
||||
rankingNames.push(location.cityIdentifier)
|
||||
}
|
||||
}
|
||||
|
||||
const rankingKeywords = location.keyWords || []
|
||||
|
||||
return {
|
||||
id,
|
||||
displayName: name,
|
||||
type,
|
||||
description,
|
||||
url,
|
||||
rankingNames: rankingNames.map((v) => v.toLowerCase()),
|
||||
rankingKeywords: rankingKeywords.map((v) => v.toLowerCase()),
|
||||
}
|
||||
})
|
||||
.filter(isDefined)
|
||||
}
|
||||
|
||||
return null
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user