Files
Linus Flood 5fc93472f4 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
2026-01-27 12:38:36 +00:00

64 lines
1.9 KiB
TypeScript

import { z } from "zod"
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
import { CardsEnum } from "../../../../../types/cardsEnum"
import { systemSchema } from "../../system"
import { getInfoCardThemeFromDeprecatedCardTheme } from "../cardsGrid"
import { buttonSchema } from "../utils/buttonLinkSchema"
const INFO_CARD_WITH_IMAGE_THEMES = [
"one",
"two",
"three",
"primaryInverted",
"primaryStrong",
] as const
export const infoCardWithImageBlockSchema = z.object({
__typename: z.literal(CardsEnum.InfoCardWithImage),
scripted_top_title: z.string().optional(),
heading: z.string().optional().default(""),
body_text: z.string().optional().default(""),
image: transformedImageVaultAssetSchema,
theme: z
.enum(INFO_CARD_WITH_IMAGE_THEMES)
.nullable()
.transform(getInfoCardThemeFromDeprecatedCardTheme),
title: z.string().optional(),
primary_button: buttonSchema.optional().nullable(),
secondary_button: buttonSchema.optional().nullable(),
system: systemSchema,
})
export function transformInfoCardWithImageBlock(
card: typeof infoCardWithImageBlockSchema._type
) {
return {
__typename: card.__typename,
topTitle: card.scripted_top_title,
heading: card.heading,
bodyText: card.body_text,
image: card.image,
theme: card.theme,
title: card.title,
primaryButton: card.primary_button?.href
? {
href: card.primary_button.href,
text: card.primary_button.title,
openInNewTab: card.primary_button.openInNewTab,
isExternal: card.primary_button.isExternal,
}
: undefined,
secondaryButton: card.secondary_button?.href
? {
href: card.secondary_button.href,
text: card.secondary_button.title,
openInNewTab: card.secondary_button.openInNewTab,
isExternal: card.secondary_button.isExternal,
}
: undefined,
system: card.system,
}
}