feat(SW-237): Implemented hide booking widget page level flag

This commit is contained in:
Hrishikesh Vaipurkar
2024-08-07 22:45:05 +02:00
parent 84985737b6
commit 25f2e8f360
3 changed files with 108 additions and 5 deletions

View File

@@ -9,6 +9,13 @@ import {
GetCurrentHeader,
GetCurrentHeaderRef,
} from "@/lib/graphql/Query/CurrentHeader.graphql"
import {
GetAccountPageSettings,
GetContentPageSettings,
GetCurrentBlocksPageSettings,
GetHotelPageSettings,
GetLoyaltyPageSettings,
} from "@/lib/graphql/Query/PageSettings.graphql"
import { request } from "@/lib/graphql/request"
import { notFound } from "@/server/errors/trpc"
import { contentstackBaseProcedure, router } from "@/server/trpc"
@@ -330,4 +337,58 @@ export const baseQueryRouter = router({
)
return validatedFooterConfig.data.all_current_footer.items[0]
}),
page_settings: contentstackBaseProcedure
.input(langInput)
.query(async ({ ctx }) => {
const failedResponse = { hideBookingWidget: false }
const { contentType, uid, lang } = ctx
// This condition is to handle 404 page case
if (!contentType || !uid) {
console.log("No proper params defined: ", contentType, uid)
return failedResponse
}
let GetPageSettings = ""
let pageType = contentType.replaceAll("-", "_")
switch (contentType) {
case "account-page":
GetPageSettings = GetAccountPageSettings
break
case "loyalty-page":
GetPageSettings = GetLoyaltyPageSettings
break
case "content-page":
GetPageSettings = GetContentPageSettings
break
case "hotel-page":
GetPageSettings = GetHotelPageSettings
break
case "current-blocks-page":
GetPageSettings = GetCurrentBlocksPageSettings
break
}
if (!GetPageSettings) {
console.error("No proper Page type defined: ", contentType)
return failedResponse
}
const response = await request<any>(GetPageSettings, {
uid: uid,
locale: lang,
})
if (!response.data) {
console.error("Flag hide_booking_widget fetch error: ", response)
return failedResponse
}
const hideBookingWidget =
!!response.data[pageType]?.page_settings?.hide_booking_widget
return {
hideBookingWidget: hideBookingWidget,
}
}),
})