Feat/SW-1449 destination page * feat(SW-1449): Added destination country page * feat(SW-1449): added destination city page Approved-by: Fredrik Thorsson Approved-by: Matilda Landström
112 lines
3.4 KiB
TypeScript
112 lines
3.4 KiB
TypeScript
import {
|
|
GetAccountPageSettings,
|
|
GetCollectionPageSettings,
|
|
GetContentPageSettings,
|
|
GetCurrentBlocksPageSettings,
|
|
GetDestinationCityPageSettings,
|
|
GetDestinationCountryPageSettings,
|
|
GetDestinationOverviewPageSettings,
|
|
GetHotelPageSettings,
|
|
GetLoyaltyPageSettings,
|
|
} from "@/lib/graphql/Query/BookingWidgetToggle.graphql"
|
|
import { request } from "@/lib/graphql/request"
|
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
|
|
|
import { generateTag } from "@/utils/generateTag"
|
|
|
|
import {
|
|
validateBookingWidgetToggleSchema,
|
|
type ValidateBookingWidgetToggleType,
|
|
} from "./output"
|
|
import { affix as bookingwidgetAffix } from "./utils"
|
|
|
|
import type { ValueOf } from "next/dist/shared/lib/constants"
|
|
|
|
import { PageContentTypeEnum } from "@/types/requests/contentType"
|
|
|
|
export const bookingwidgetQueryRouter = router({
|
|
toggle: router({
|
|
get: contentstackBaseProcedure.query(async ({ ctx }) => {
|
|
const failedResponse = { hideBookingWidget: false }
|
|
const { contentType, uid, lang } = ctx
|
|
|
|
// This condition is to handle 404 page case and booking flow
|
|
if (!contentType || !uid) {
|
|
console.log("No proper params defined: ", contentType, uid)
|
|
return failedResponse
|
|
}
|
|
let GetPageSettings = ""
|
|
const contentTypeCMS = <ValueOf<typeof PageContentTypeEnum>>(
|
|
contentType.replaceAll("-", "_")
|
|
)
|
|
|
|
switch (contentTypeCMS) {
|
|
case PageContentTypeEnum.accountPage:
|
|
GetPageSettings = GetAccountPageSettings
|
|
break
|
|
case PageContentTypeEnum.loyaltyPage:
|
|
GetPageSettings = GetLoyaltyPageSettings
|
|
break
|
|
case PageContentTypeEnum.collectionPage:
|
|
GetPageSettings = GetCollectionPageSettings
|
|
break
|
|
case PageContentTypeEnum.contentPage:
|
|
GetPageSettings = GetContentPageSettings
|
|
break
|
|
case PageContentTypeEnum.destinationOverviewPage:
|
|
GetPageSettings = GetDestinationOverviewPageSettings
|
|
break
|
|
case PageContentTypeEnum.destinationCountryPage:
|
|
GetPageSettings = GetDestinationCountryPageSettings
|
|
break
|
|
case PageContentTypeEnum.destinationCityPage:
|
|
GetPageSettings = GetDestinationCityPageSettings
|
|
break
|
|
case PageContentTypeEnum.hotelPage:
|
|
GetPageSettings = GetHotelPageSettings
|
|
break
|
|
case PageContentTypeEnum.currentBlocksPage:
|
|
GetPageSettings = GetCurrentBlocksPageSettings
|
|
break
|
|
}
|
|
|
|
if (!GetPageSettings) {
|
|
console.error("No proper Content type defined: ", contentType)
|
|
return failedResponse
|
|
}
|
|
|
|
const response = await request<ValidateBookingWidgetToggleType>(
|
|
GetPageSettings,
|
|
{
|
|
uid: uid,
|
|
locale: lang,
|
|
},
|
|
{
|
|
cache: "force-cache",
|
|
next: {
|
|
tags: [generateTag(lang, uid, bookingwidgetAffix)],
|
|
},
|
|
}
|
|
)
|
|
|
|
const bookingWidgetToggleData =
|
|
validateBookingWidgetToggleSchema.safeParse(response.data)
|
|
if (!bookingWidgetToggleData.success) {
|
|
console.error(
|
|
"Flag hide_booking_widget fetch error: ",
|
|
bookingWidgetToggleData.error
|
|
)
|
|
return failedResponse
|
|
}
|
|
|
|
const hideBookingWidget =
|
|
!!bookingWidgetToggleData.data[contentTypeCMS]?.page_settings
|
|
?.hide_booking_widget
|
|
|
|
return {
|
|
hideBookingWidget,
|
|
}
|
|
}),
|
|
}),
|
|
})
|