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:
@@ -4,68 +4,29 @@ import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/i
|
||||
|
||||
import { ContentPageEnum } from "../../../types/contentPage"
|
||||
import { discriminatedUnionArray } from "../../../utils/discriminatedUnion"
|
||||
import {
|
||||
accordionRefsSchema,
|
||||
accordionSchema,
|
||||
} from "../schemas/blocks/accordion"
|
||||
import {
|
||||
cardGridRefsSchema,
|
||||
cardsGridSchema,
|
||||
} from "../schemas/blocks/cardsGrid"
|
||||
import {
|
||||
contentRefsSchema as blockContentRefsSchema,
|
||||
contentSchema as blockContentSchema,
|
||||
} from "../schemas/blocks/content"
|
||||
import {
|
||||
dynamicContentRefsSchema,
|
||||
dynamicContentSchema as blockDynamicContentSchema,
|
||||
} from "../schemas/blocks/dynamicContent"
|
||||
import { accordionSchema } from "../schemas/blocks/accordion"
|
||||
import { cardsGridSchema } from "../schemas/blocks/cardsGrid"
|
||||
import { contentSchema as blockContentSchema } from "../schemas/blocks/content"
|
||||
import { dynamicContentSchema as blockDynamicContentSchema } from "../schemas/blocks/dynamicContent"
|
||||
import { contentPageHotelListingSchema } from "../schemas/blocks/hotelListing"
|
||||
import { jotformRefsSchema, jotformSchema } from "../schemas/blocks/jotform"
|
||||
import {
|
||||
shortcutsRefsSchema,
|
||||
shortcutsSchema,
|
||||
} from "../schemas/blocks/shortcuts"
|
||||
import { jotformSchema } from "../schemas/blocks/jotform"
|
||||
import { shortcutsSchema } from "../schemas/blocks/shortcuts"
|
||||
import { tableSchema } from "../schemas/blocks/table"
|
||||
import { textColsRefsSchema, textColsSchema } from "../schemas/blocks/textCols"
|
||||
import { uspGridRefsSchema, uspGridSchema } from "../schemas/blocks/uspGrid"
|
||||
import { videoBlockRefsSchema, videoBlockSchema } from "../schemas/blocks/video"
|
||||
import {
|
||||
videoCardRefsSchema,
|
||||
videoCardSchema,
|
||||
} from "../schemas/blocks/videoCard"
|
||||
import {
|
||||
dynamicContentRefsSchema as headerDynamicContentRefsSchema,
|
||||
dynamicContentSchema as headerDynamicContentSchema,
|
||||
} from "../schemas/headers/dynamicContent"
|
||||
import {
|
||||
linkAndTitleSchema,
|
||||
linkConnectionRefs,
|
||||
} from "../schemas/linkConnection"
|
||||
import { textColsSchema } from "../schemas/blocks/textCols"
|
||||
import { uspGridSchema } from "../schemas/blocks/uspGrid"
|
||||
import { videoBlockSchema } from "../schemas/blocks/video"
|
||||
import { videoCardSchema } from "../schemas/blocks/videoCard"
|
||||
import { dynamicContentSchema as headerDynamicContentSchema } from "../schemas/headers/dynamicContent"
|
||||
import { linkAndTitleSchema } from "../schemas/linkConnection"
|
||||
import { internalOrExternalLinkSchema } from "../schemas/pageLinks"
|
||||
import {
|
||||
contentRefsSchema as sidebarContentRefsSchema,
|
||||
contentSchema as sidebarContentSchema,
|
||||
} from "../schemas/sidebar/content"
|
||||
import { contentSchema as sidebarContentSchema } from "../schemas/sidebar/content"
|
||||
import { dynamicContentSchema as sidebarDynamicContentSchema } from "../schemas/sidebar/dynamicContent"
|
||||
import {
|
||||
joinLoyaltyContactRefsSchema,
|
||||
joinLoyaltyContactSchema,
|
||||
} from "../schemas/sidebar/joinLoyaltyContact"
|
||||
import {
|
||||
quickLinksRefschema,
|
||||
quickLinksSchema,
|
||||
} from "../schemas/sidebar/quickLinks"
|
||||
import {
|
||||
scriptedCardRefschema,
|
||||
scriptedCardsSchema,
|
||||
} from "../schemas/sidebar/scriptedCard"
|
||||
import {
|
||||
teaserCardRefschema,
|
||||
teaserCardsSchema,
|
||||
} from "../schemas/sidebar/teaserCard"
|
||||
import { joinLoyaltyContactSchema } from "../schemas/sidebar/joinLoyaltyContact"
|
||||
import { quickLinksSchema } from "../schemas/sidebar/quickLinks"
|
||||
import { scriptedCardsSchema } from "../schemas/sidebar/scriptedCard"
|
||||
import { teaserCardsSchema } from "../schemas/sidebar/teaserCard"
|
||||
import { systemSchema } from "../schemas/system"
|
||||
import { transformedVideoSchema, videoRefSchema } from "../schemas/video"
|
||||
import { transformedVideoSchema } from "../schemas/video"
|
||||
|
||||
// Block schemas
|
||||
export const contentPageCards = z
|
||||
@@ -250,137 +211,3 @@ export const contentPageSchema = z.object({
|
||||
url: z.string(),
|
||||
}),
|
||||
})
|
||||
|
||||
/** REFS */
|
||||
const contentPageCardsRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.CardsGrid),
|
||||
})
|
||||
.merge(cardGridRefsSchema)
|
||||
|
||||
const contentPageBlockContentRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.Content),
|
||||
})
|
||||
.merge(blockContentRefsSchema)
|
||||
|
||||
const contentPageDynamicContentRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.DynamicContent),
|
||||
})
|
||||
.merge(dynamicContentRefsSchema)
|
||||
|
||||
const contentPageShortcutsRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.Shortcuts),
|
||||
})
|
||||
.merge(shortcutsRefsSchema)
|
||||
|
||||
const contentPageTextColsRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.TextCols),
|
||||
})
|
||||
.merge(textColsRefsSchema)
|
||||
|
||||
const contentPageUspGridRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.UspGrid),
|
||||
})
|
||||
.merge(uspGridRefsSchema)
|
||||
|
||||
const contentPageAccordionRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.Accordion),
|
||||
})
|
||||
.merge(accordionRefsSchema)
|
||||
|
||||
const contentPageVideoCardRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.VideoCard),
|
||||
})
|
||||
.merge(videoCardRefsSchema)
|
||||
|
||||
const contentPageVideoRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.Video),
|
||||
})
|
||||
.merge(videoBlockRefsSchema)
|
||||
|
||||
const contentPageJotformRefs = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.blocks.Jotform),
|
||||
})
|
||||
.merge(jotformRefsSchema)
|
||||
|
||||
const contentPageBlockRefsItem = z.discriminatedUnion("__typename", [
|
||||
contentPageAccordionRefs,
|
||||
contentPageBlockContentRefs,
|
||||
contentPageShortcutsRefs,
|
||||
contentPageCardsRefs,
|
||||
contentPageDynamicContentRefs,
|
||||
contentPageTextColsRefs,
|
||||
contentPageUspGridRefs,
|
||||
contentPageVideoCardRefs,
|
||||
contentPageJotformRefs,
|
||||
contentPageVideoRefs,
|
||||
])
|
||||
|
||||
const contentPageSidebarContentRef = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.Content),
|
||||
})
|
||||
.merge(sidebarContentRefsSchema)
|
||||
|
||||
const contentPageSidebarJoinLoyaltyContactRef = z
|
||||
.object({
|
||||
__typename: z.literal(
|
||||
ContentPageEnum.ContentStack.sidebar.JoinLoyaltyContact
|
||||
),
|
||||
})
|
||||
.merge(joinLoyaltyContactRefsSchema)
|
||||
|
||||
const contentPageSidebarScriptedCardRef = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.ScriptedCard),
|
||||
})
|
||||
.merge(scriptedCardRefschema)
|
||||
|
||||
const contentPageSidebarTeaserCardRef = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.TeaserCard),
|
||||
})
|
||||
.merge(teaserCardRefschema)
|
||||
|
||||
const contentPageSidebarQuickLinksRef = z
|
||||
.object({
|
||||
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.QuickLinks),
|
||||
})
|
||||
.merge(quickLinksRefschema)
|
||||
|
||||
const contentPageSidebarRefsItem = z.discriminatedUnion("__typename", [
|
||||
contentPageSidebarContentRef,
|
||||
contentPageSidebarJoinLoyaltyContactRef,
|
||||
contentPageSidebarScriptedCardRef,
|
||||
contentPageSidebarTeaserCardRef,
|
||||
contentPageSidebarQuickLinksRef,
|
||||
])
|
||||
|
||||
const contentPageHeaderRefs = z.object({
|
||||
navigation_links: z.array(linkConnectionRefs),
|
||||
top_primary_button: linkConnectionRefs.nullable(),
|
||||
dynamic_content: headerDynamicContentRefsSchema.nullish(),
|
||||
})
|
||||
|
||||
export const contentPageRefsSchema = z.object({
|
||||
content_page: z.object({
|
||||
hero_video: videoRefSchema.nullish(),
|
||||
header: contentPageHeaderRefs,
|
||||
blocks: discriminatedUnionArray(
|
||||
contentPageBlockRefsItem.options
|
||||
).nullable(),
|
||||
sidebar: discriminatedUnionArray(
|
||||
contentPageSidebarRefsItem.options
|
||||
).nullable(),
|
||||
system: systemSchema,
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user