feat(SW-1389): refactor page settings
This commit is contained in:
3
lib/graphql/Fragments/PageSettings.graphql
Normal file
3
lib/graphql/Fragments/PageSettings.graphql
Normal file
@@ -0,0 +1,3 @@
|
||||
fragment PageSettings on PageSettings {
|
||||
hide_booking_widget
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
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 GetCollectionPageSettings($uid: String!, $locale: String!) {
|
||||
collection_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 GetDestinationOverviewPageSettings($uid: String!, $locale: String!) {
|
||||
destination_overview_page(uid: $uid, locale: $locale) {
|
||||
page_settings {
|
||||
hide_booking_widget
|
||||
}
|
||||
}
|
||||
}
|
||||
query GetDestinationCountryPageSettings($uid: String!, $locale: String!) {
|
||||
destination_country_page(uid: $uid, locale: $locale) {
|
||||
page_settings {
|
||||
hide_booking_widget
|
||||
}
|
||||
}
|
||||
}
|
||||
query GetDestinationCityPageSettings($uid: String!, $locale: String!) {
|
||||
destination_city_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
|
||||
}
|
||||
}
|
||||
}
|
||||
81
lib/graphql/Query/PageSettings.graphql
Normal file
81
lib/graphql/Query/PageSettings.graphql
Normal file
@@ -0,0 +1,81 @@
|
||||
#import "../Fragments/PageSettings.graphql"
|
||||
|
||||
query GetAccountPageSettings($uid: String!, $locale: String!) {
|
||||
page: account_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetCollectionPageSettings($uid: String!, $locale: String!) {
|
||||
page: collection_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetContentPageSettings($uid: String!, $locale: String!) {
|
||||
page: content_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetCurrentBlocksPageSettings($uid: String!, $locale: String!) {
|
||||
page: current_blocks_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetDestinationCityPageSettings($uid: String!, $locale: String!) {
|
||||
page: destination_city_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetDestinationCountryPageSettings($uid: String!, $locale: String!) {
|
||||
page: destination_country_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetDestinationOverviewPageSettings($uid: String!, $locale: String!) {
|
||||
page: destination_overview_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetHotelPageSettings($uid: String!, $locale: String!) {
|
||||
page: hotel_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetLoyaltyPageSettings($uid: String!, $locale: String!) {
|
||||
page: loyalty_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
query GetStartPageSettings($uid: String!, $locale: String!) {
|
||||
page: start_page(uid: $uid, locale: $locale) {
|
||||
settings: page_settings {
|
||||
...PageSettings
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
import { getLang } from "@/i18n/serverContext"
|
||||
import { cache } from "@/utils/cache"
|
||||
|
||||
import { serverClient } from "../server"
|
||||
@@ -228,3 +229,36 @@ export const getDestinationCityPage = cache(
|
||||
export const getStartPage = cache(async function getMemoizedStartPage() {
|
||||
return serverClient().contentstack.startPage.get()
|
||||
})
|
||||
|
||||
export const getPageSettings = cache(async function getMemoizedPageSettings(
|
||||
lang: Lang
|
||||
) {
|
||||
return serverClient().contentstack.pageSettings.get({ lang })
|
||||
})
|
||||
|
||||
export const isBookingWidgetHidden = cache(
|
||||
async function isMemoizedBookingWidgetHidden() {
|
||||
const lang = getLang()
|
||||
const [pageSettingsResult, siteConfigResults] = await Promise.allSettled([
|
||||
getPageSettings(lang),
|
||||
getSiteConfig(lang),
|
||||
])
|
||||
|
||||
const pageSettings =
|
||||
pageSettingsResult.status === "fulfilled"
|
||||
? pageSettingsResult.value
|
||||
: null
|
||||
const siteConfig =
|
||||
siteConfigResults.status === "fulfilled" ? siteConfigResults.value : null
|
||||
|
||||
if (pageSettings) {
|
||||
return pageSettings.page.settings.hide_booking_widget
|
||||
}
|
||||
|
||||
if (siteConfig) {
|
||||
return siteConfig.bookingWidgetDisabled
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user