Merged in feat/rework-contentstack (pull request #3493)
Feat(SW-3708): refactor contentstack fetching (removing all refs) and cache invalidation * Remove all REFS * Revalidate correct language * PR fixes * PR fixes * Throw when errors from contentstack api Approved-by: Joakim Jäderberg
This commit is contained in:
@@ -5,112 +5,9 @@ import { logger } from "@scandic-hotels/common/logger"
|
||||
|
||||
import { getValueFromContactConfig } from "../../../utils/contactConfig"
|
||||
|
||||
import type { Edges } from "../../../types/edges"
|
||||
import type { FooterRefDataRaw } from "../../../types/footer"
|
||||
import type { HeaderRefs } from "../../../types/header"
|
||||
import type { NodeRefs } from "../../../types/refs"
|
||||
import type {
|
||||
AlertOutput,
|
||||
GetSiteConfigRefData,
|
||||
GetSitewideCampaignBannerRefData,
|
||||
} from "../../../types/siteConfig"
|
||||
import type { System } from "../schemas/system"
|
||||
import type { AlertOutput } from "../../../types/siteConfig"
|
||||
import type { ContactConfig } from "./output"
|
||||
|
||||
export function getConnections({ header }: HeaderRefs) {
|
||||
const connections: System["system"][] = [header.system]
|
||||
|
||||
if (header.top_link) {
|
||||
if (header.top_link.logged_in?.link) {
|
||||
connections.push(header.top_link.logged_in.link)
|
||||
}
|
||||
if (header.top_link.logged_out?.link) {
|
||||
connections.push(header.top_link.logged_out.link)
|
||||
}
|
||||
}
|
||||
|
||||
if (header.menu_items.length) {
|
||||
header.menu_items.forEach((menuItem) => {
|
||||
if (menuItem.card) {
|
||||
connections.push(...menuItem.card)
|
||||
}
|
||||
if (menuItem.link) {
|
||||
connections.push(menuItem.link)
|
||||
}
|
||||
if (menuItem.see_all_link?.link) {
|
||||
connections.push(menuItem.see_all_link.link)
|
||||
}
|
||||
if (menuItem.submenu.length) {
|
||||
menuItem.submenu.forEach((subMenuItem) => {
|
||||
if (subMenuItem.links.length) {
|
||||
subMenuItem.links.forEach((link) => {
|
||||
if (link?.link) {
|
||||
connections.push(link.link)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
export function getFooterConnections(refs: FooterRefDataRaw) {
|
||||
const connections: Edges<NodeRefs>[] = []
|
||||
const footerData = refs.all_footer.items[0]
|
||||
const mainLinks = footerData.main_links
|
||||
const secondaryLinks = footerData.secondary_links
|
||||
const tertiaryLinks = footerData.tertiary_links
|
||||
if (mainLinks) {
|
||||
mainLinks.forEach(({ pageConnection }) => {
|
||||
connections.push(pageConnection)
|
||||
})
|
||||
}
|
||||
secondaryLinks?.forEach(({ links }) => {
|
||||
if (links) {
|
||||
links.forEach(({ pageConnection }) => {
|
||||
connections.push(pageConnection)
|
||||
})
|
||||
}
|
||||
})
|
||||
if (tertiaryLinks) {
|
||||
tertiaryLinks.forEach(({ pageConnection }) => {
|
||||
connections.push(pageConnection)
|
||||
})
|
||||
}
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
export function getSiteConfigConnections(refs: GetSiteConfigRefData) {
|
||||
const siteConfigData = refs.all_site_config.items[0]
|
||||
const connections: System["system"][] = []
|
||||
|
||||
if (!siteConfigData.sitewide_alert.alert) return connections
|
||||
|
||||
const alertConnection = siteConfigData.sitewide_alert.alert.alertConnection
|
||||
|
||||
alertConnection.edges.forEach(({ node }) => {
|
||||
connections.push(node.system)
|
||||
|
||||
const link = node.link.link
|
||||
if (link) {
|
||||
connections.push(link)
|
||||
}
|
||||
node.sidepeek_content.content.embedded_itemsConnection.edges.forEach(
|
||||
({ node }) => {
|
||||
if (node.system) {
|
||||
connections.push(node.system)
|
||||
}
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
export function getAlertPhoneContactData(
|
||||
alert: AlertOutput,
|
||||
contactConfig: ContactConfig
|
||||
@@ -139,21 +36,3 @@ export const safeUnion = <T extends z.ZodTypeAny>(schema: T) =>
|
||||
return null
|
||||
}
|
||||
}, schema)
|
||||
|
||||
export function getSitewideCampaignBannerConnections(
|
||||
refs: GetSitewideCampaignBannerRefData
|
||||
) {
|
||||
const system = refs.all_sitewide_campaign_banner?.system
|
||||
const banner =
|
||||
refs.all_sitewide_campaign_banner?.bannerConnection.edges[0]?.node
|
||||
const connections: System["system"][] = []
|
||||
|
||||
if (system) {
|
||||
connections.push(system)
|
||||
}
|
||||
if (banner?.system) {
|
||||
connections.push(banner.system)
|
||||
}
|
||||
|
||||
return connections
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user