feat(SW-237): Implemented hide booking widget page level flag
This commit is contained in:
@@ -24,10 +24,11 @@ export default async function Header({
|
|||||||
|
|
||||||
const user = await serverClient().user.name()
|
const user = await serverClient().user.name()
|
||||||
|
|
||||||
/**
|
// Get the booking widget show/hide status based on page specific settings
|
||||||
* ToDo: Create logic to get this info from ContentStack based on page
|
const bookingWidgetToggle =
|
||||||
* */
|
await serverClient().contentstack.base.page_settings({
|
||||||
const hideBookingWidget = true
|
lang: getLang(),
|
||||||
|
})
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return null
|
return null
|
||||||
@@ -60,7 +61,9 @@ export default async function Header({
|
|||||||
bookingHref={homeHref}
|
bookingHref={homeHref}
|
||||||
user={user}
|
user={user}
|
||||||
/>
|
/>
|
||||||
{hideBookingWidget ? null : <BookingWidget />}
|
{bookingWidgetToggle && bookingWidgetToggle.hideBookingWidget ? null : (
|
||||||
|
<BookingWidget />
|
||||||
|
)}
|
||||||
</header>
|
</header>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
39
lib/graphql/Query/PageSettings.graphql
Normal file
39
lib/graphql/Query/PageSettings.graphql
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,13 @@ import {
|
|||||||
GetCurrentHeader,
|
GetCurrentHeader,
|
||||||
GetCurrentHeaderRef,
|
GetCurrentHeaderRef,
|
||||||
} from "@/lib/graphql/Query/CurrentHeader.graphql"
|
} 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 { request } from "@/lib/graphql/request"
|
||||||
import { notFound } from "@/server/errors/trpc"
|
import { notFound } from "@/server/errors/trpc"
|
||||||
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
import { contentstackBaseProcedure, router } from "@/server/trpc"
|
||||||
@@ -330,4 +337,58 @@ export const baseQueryRouter = router({
|
|||||||
)
|
)
|
||||||
return validatedFooterConfig.data.all_current_footer.items[0]
|
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,
|
||||||
|
}
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user