feat(SW-2873): Move select-hotel to booking flow * crude setup of select-hotel in partner-sas * wip * Fix linting * restructure tracking files * Remove dependency on trpc in tracking hooks * Move pageview tracking to common * Fix some lint and import issues * Add AlternativeHotelsPage * Add SelectHotelMapPage * Add AlternativeHotelsMapPage * remove next dependency in tracking store * Remove dependency on react in tracking hooks * move isSameBooking to booking-flow * Inject searchParamsComparator into tracking store * Move useTrackHardNavigation to common * Move useTrackSoftNavigation to common * Add TrackingSDK to partner-sas * call serverclient in layout * Remove unused css * Update types * Move HotelPin type * Fix todos * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Merge branch 'master' into feat/sw-2873-move-selecthotel-to-booking-flow * Fix component Approved-by: Joakim Jäderberg
304 lines
8.5 KiB
TypeScript
304 lines
8.5 KiB
TypeScript
import { redirect } from "next/navigation"
|
|
|
|
import { cache } from "@/utils/cache"
|
|
|
|
import { serverClient } from "../server"
|
|
|
|
import type { Lang } from "@scandic-hotels/common/constants/language"
|
|
import type { GetHotelsByCSFilterInput } from "@scandic-hotels/trpc/routers/hotels/input"
|
|
import type { GetSavedPaymentCardsInput } from "@scandic-hotels/trpc/routers/user/input"
|
|
import type { RoomsAvailabilityExtendedInputSchema } from "@scandic-hotels/trpc/types/availability"
|
|
import type { Country } from "@scandic-hotels/trpc/types/country"
|
|
import type { HotelInput } from "@scandic-hotels/trpc/types/hotel"
|
|
import type {
|
|
AncillaryPackagesInput,
|
|
BreackfastPackagesInput,
|
|
PackagesInput,
|
|
} from "@scandic-hotels/trpc/types/packages"
|
|
|
|
export const getProfile = cache(async function getMemoizedProfile() {
|
|
const caller = await serverClient()
|
|
return caller.user.get()
|
|
})
|
|
|
|
export const getName = cache(async function getMemoizedName() {
|
|
const caller = await serverClient()
|
|
return caller.user.name()
|
|
})
|
|
|
|
export const getProfileSafely = cache(
|
|
async function getMemoizedProfileSafely() {
|
|
const caller = await serverClient()
|
|
return caller.user.getSafely()
|
|
}
|
|
)
|
|
|
|
export const getProfileWithExtendedPartnerData = cache(
|
|
async function getMemoizedProfileWithPartnerData() {
|
|
const caller = await serverClient()
|
|
return caller.user.getWithExtendedPartnerData()
|
|
}
|
|
)
|
|
|
|
export const getSavedPaymentCardsSafely = cache(
|
|
async function getMemoizedSavedPaymentCardsSafely(
|
|
input: GetSavedPaymentCardsInput
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.user.safePaymentCards(input)
|
|
}
|
|
)
|
|
|
|
export const getMembershipLevel = cache(
|
|
async function getMemoizedMembershipLevel() {
|
|
const caller = await serverClient()
|
|
return caller.user.membershipLevel()
|
|
}
|
|
)
|
|
|
|
export const getMembershipLevelSafely = cache(
|
|
async function getMemoizedMembershipLevelSafely() {
|
|
const caller = await serverClient()
|
|
return caller.user.safeMembershipLevel()
|
|
}
|
|
)
|
|
|
|
export const getMembershipCards = cache(
|
|
async function getMemoizedMembershipCards() {
|
|
const caller = await serverClient()
|
|
return caller.user.membershipCards()
|
|
}
|
|
)
|
|
|
|
export const getHotelsByCSFilter = cache(async function getMemoizedHotels(
|
|
input: GetHotelsByCSFilterInput
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.hotels.byCSFilter.get(input)
|
|
})
|
|
|
|
export const getHotel = cache(async function getMemoizedHotelData(
|
|
input: HotelInput
|
|
) {
|
|
if (!input.isCardOnlyPayment) {
|
|
input.isCardOnlyPayment = false
|
|
}
|
|
const caller = await serverClient()
|
|
return caller.hotel.get(input)
|
|
})
|
|
|
|
export const getHotelPage = cache(async function getMemoizedHotelPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.hotelPage.get()
|
|
})
|
|
|
|
export const getFooter = cache(async function getMemoizedFooter() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.base.footer()
|
|
})
|
|
|
|
export const getHeader = cache(async function getMemoizedHeader() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.base.header()
|
|
})
|
|
|
|
export const getCurrentHeader = cache(async function getMemoizedCurrentHeader(
|
|
lang: Lang
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.base.currentHeader({ lang })
|
|
})
|
|
|
|
export const getCurrentFooter = cache(async function getMemoizedCurrentFooter(
|
|
lang: Lang
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.base.currentFooter({ lang })
|
|
})
|
|
|
|
export const getSiteConfig = cache(async function getMemoizedSiteConfig(
|
|
lang: Lang
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.base.siteConfig({ lang })
|
|
})
|
|
|
|
export const getBreakfastPackages = cache(
|
|
async function getMemoizedBreakfastPackages(input: BreackfastPackagesInput) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.packages.breakfast(input)
|
|
}
|
|
)
|
|
|
|
export const getAncillaryPackages = cache(
|
|
async function getMemoizedAncillaryPackages(input: AncillaryPackagesInput) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.packages.ancillary(input)
|
|
}
|
|
)
|
|
|
|
export const getPackages = cache(async function getMemoizedPackages(
|
|
input: PackagesInput
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.packages.get(input)
|
|
})
|
|
|
|
export const getBookingConfirmation = cache(
|
|
async function getMemoizedBookingConfirmation(refId: string) {
|
|
const caller = await serverClient()
|
|
return caller.booking.get({ refId })
|
|
}
|
|
)
|
|
|
|
export const findBooking = cache(async function getMemoizedFindBooking(
|
|
confirmationNumber: string,
|
|
lastName: string,
|
|
firstName: string,
|
|
email: string
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.booking.findBooking({
|
|
confirmationNumber,
|
|
lastName,
|
|
firstName,
|
|
email,
|
|
})
|
|
})
|
|
|
|
export const getLinkedReservations = cache(
|
|
async function getMemoizedLinkedReservations(refId: string) {
|
|
const caller = await serverClient()
|
|
return caller.booking.linkedReservations({
|
|
refId,
|
|
})
|
|
}
|
|
)
|
|
|
|
export const getCurrentRewards = cache(
|
|
async function getMemoizedCurrentRewards() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.rewards.current()
|
|
}
|
|
)
|
|
|
|
export const getMeetingRooms = cache(
|
|
async function getMemoizedMeetingRooms(input: {
|
|
hotelId: string
|
|
language: Lang
|
|
}) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.meetingRooms(input)
|
|
}
|
|
)
|
|
|
|
export const getAdditionalData = cache(
|
|
async function getMemoizedAdditionalData(input: {
|
|
hotelId: string
|
|
language: Lang
|
|
}) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.additionalData(input)
|
|
}
|
|
)
|
|
|
|
export const getDestinationOverviewPage = cache(
|
|
async function getMemoizedDestinationOverviewPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.destinationOverviewPage.get()
|
|
}
|
|
)
|
|
|
|
export const getDestinationsList = cache(
|
|
async function getMemoizedDestinationsList() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.destinationOverviewPage.destinations.get()
|
|
}
|
|
)
|
|
export const getDestinationCountryPage = cache(
|
|
async function getMemoizedDestinationCountryPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.destinationCountryPage.get()
|
|
}
|
|
)
|
|
export const getDestinationCityPagesByCountry = cache(
|
|
async function getMemoizedDestinationCityPagesByCountry(country: Country) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.destinationCountryPage.cityPages({
|
|
country,
|
|
})
|
|
}
|
|
)
|
|
export const getHotelsByCountry = cache(
|
|
async function getMemoizedHotelsByCountry(country: Country) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.hotels.byCountry.get({
|
|
country,
|
|
})
|
|
}
|
|
)
|
|
export const getHotelsByCityIdentifier = cache(
|
|
async function getMemoizedHotelsByCityIdentifier(cityIdentifier: string) {
|
|
const caller = await serverClient()
|
|
return caller.hotel.hotels.byCityIdentifier.get({
|
|
cityIdentifier,
|
|
})
|
|
}
|
|
)
|
|
export const getDestinationsMapData = cache(
|
|
async function getMemoizedDestinationsMapData() {
|
|
const caller = await serverClient()
|
|
return caller.hotel.hotels.getDestinationsMapData()
|
|
}
|
|
)
|
|
export const getDestinationCityPage = cache(
|
|
async function getMemoizedDestinationCityPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.destinationCityPage.get()
|
|
}
|
|
)
|
|
|
|
export const getStartPage = cache(async function getMemoizedStartPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.startPage.get()
|
|
})
|
|
|
|
export const getPageSettings = cache(async function getMemoizedPageSettings(
|
|
lang: Lang
|
|
) {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.pageSettings.get({ lang })
|
|
})
|
|
|
|
export const getJobylonFeed = cache(async function getMemoizedJobylonFeed() {
|
|
const caller = await serverClient()
|
|
return caller.partner.jobylon.feed.get()
|
|
})
|
|
|
|
export const getSelectedRoomsAvailabilityEnterDetails = cache(
|
|
async function getMemoizedSelectedRoomsAvailability(
|
|
input: RoomsAvailabilityExtendedInputSchema
|
|
) {
|
|
const caller = await serverClient()
|
|
const result = await caller.hotel.availability.enterDetails(input)
|
|
|
|
if (typeof result === "string") {
|
|
redirect(result)
|
|
}
|
|
|
|
return result
|
|
}
|
|
)
|
|
|
|
export const getCampaignPage = cache(async function getMemoizedCampaignPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.campaignPage.get()
|
|
})
|
|
|
|
export const getCampaignOverviewPage = cache(
|
|
async function getMemoizedCampaignOverviewPage() {
|
|
const caller = await serverClient()
|
|
return caller.contentstack.campaignOverviewPage.get()
|
|
}
|
|
)
|