chore: Cleanup booking-flow after migration * Remove unused types * Clean up exports, types, unused files etc in booking-flow Approved-by: Joakim Jäderberg
58 lines
1.7 KiB
TypeScript
58 lines
1.7 KiB
TypeScript
import { cache } from "react"
|
|
|
|
import { serverClient } from "../trpc"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
import type { HotelInput } from "@scandic-hotels/trpc/types/hotel"
|
|
|
|
const getSiteConfig = cache(async function getMemoizedSiteConfig(lang: Lang) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.base.siteConfig({ lang })
|
|
})
|
|
|
|
const getPageSettings = cache(async function getMemoizedPageSettings(
|
|
lang: Lang
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.pageSettings.get({ lang })
|
|
})
|
|
|
|
export const isBookingWidgetHidden = cache(
|
|
async function isMemoizedBookingWidgetHidden(lang: Lang) {
|
|
const [pageSettingsResult, siteConfigResults] = await Promise.allSettled([
|
|
getPageSettings(lang),
|
|
getSiteConfig(lang),
|
|
])
|
|
|
|
const pageSettings =
|
|
pageSettingsResult.status === "fulfilled"
|
|
? pageSettingsResult.value
|
|
: null
|
|
const siteConfig =
|
|
siteConfigResults.status === "fulfilled" ? siteConfigResults.value : null
|
|
|
|
const hideFromPageSettings =
|
|
pageSettings?.page.settings.hide_booking_widget ?? false
|
|
const hideFromSiteConfig = siteConfig?.bookingWidgetDisabled ?? false
|
|
|
|
return hideFromPageSettings || hideFromSiteConfig
|
|
}
|
|
)
|
|
|
|
export const getPageSettingsBookingCode = cache(
|
|
async function getMemoizedPageSettingsBookingCode(lang: Lang) {
|
|
const pageSettings = await getPageSettings(lang)
|
|
return pageSettings?.page.settings.booking_code ?? ""
|
|
}
|
|
)
|
|
|
|
export const getHotel = cache(async function getMemoizedHotelData(
|
|
input: HotelInput
|
|
) {
|
|
if (!input.isCardOnlyPayment) {
|
|
input.isCardOnlyPayment = false
|
|
}
|
|
const caller = await serverClient()
|
|
return caller.hotel.get(input)
|
|
})
|