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

@@ -24,10 +24,11 @@ export default async function Header({
const user = await serverClient().user.name()
/**
* ToDo: Create logic to get this info from ContentStack based on page
* */
const hideBookingWidget = true
// Get the booking widget show/hide status based on page specific settings
const bookingWidgetToggle =
await serverClient().contentstack.base.page_settings({
lang: getLang(),
})
if (!data) {
return null
@@ -60,7 +61,9 @@ export default async function Header({
bookingHref={homeHref}
user={user}
/>
{hideBookingWidget ? null : <BookingWidget />}
{bookingWidgetToggle && bookingWidgetToggle.hideBookingWidget ? null : (
<BookingWidget />
)}
</header>
)
}

View File

@@ -0,0 +1,39 @@
query GetAccountPageSettings($uid: String!, $locale: String!) {
account_page(uid: $uid, locale: $locale) {
page_settings {
hide_booking_widget
}
}
}
query GetLoyaltyPageSettings($uid: String!, $locale: String!) {
loyalty_page(uid: $uid, locale: $locale) {
page_settings {
hide_booking_widget
}
}
}
query GetContentPageSettings($uid: String!, $locale: String!) {
content_page(uid: $uid, locale: $locale) {
page_settings {
hide_booking_widget
}
}
}
query GetHotelPageSettings($uid: String!, $locale: String!) {
hotel_page(uid: $uid, locale: $locale) {
page_settings {
hide_booking_widget
}
}
}
query GetCurrentBlocksPageSettings($uid: String!, $locale: String!) {
current_blocks_page(uid: $uid, locale: $locale) {
page_settings {
hide_booking_widget
}
}
}

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,
}
}),
})