Files
web/packages/trpc/lib/routers/contentstack/schemas/blocks/cards/contentCard.ts
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

41 lines
1.1 KiB
TypeScript

import { z } from "zod"
import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault"
import { CardsEnum } from "../../../../../types/cardsEnum"
import { systemSchema } from "../../system"
import { buttonSchema } from "../utils/buttonLinkSchema"
export const contentCardSchema = z.object({
__typename: z.literal(CardsEnum.ContentCard),
title: z.string(),
heading: z.string(),
image: transformedImageVaultAssetSchema,
body_text: z.string(),
promo_text: z.string().optional(),
has_card_link: z.boolean(),
card_link: buttonSchema,
system: systemSchema,
})
export function transformContentCard(card: typeof contentCardSchema._type) {
// Return null if image or image URL is missing
if (!card.image?.url) return null
return {
__typename: card.__typename,
title: card.title,
heading: card.heading,
image: card.image,
bodyText: card.body_text,
promoText: card.promo_text,
link: card.has_card_link
? {
href: card.card_link.href,
openInNewTab: card.card_link.openInNewTab,
isExternal: card.card_link.isExternal,
}
: undefined,
}
}