diff --git a/apps/scandic-web/components/ContentType/CampaignPage/Blocks/index.tsx b/apps/scandic-web/components/ContentType/CampaignPage/Blocks/index.tsx index ca1147b66..08cd16d05 100644 --- a/apps/scandic-web/components/ContentType/CampaignPage/Blocks/index.tsx +++ b/apps/scandic-web/components/ContentType/CampaignPage/Blocks/index.tsx @@ -1,3 +1,4 @@ +import CarouselCards from "@/components/Blocks/CarouselCards" import Essentials from "@/components/Blocks/Essentials" import type { BlocksProps } from "@/types/components/blocks" @@ -10,6 +11,13 @@ export default function Blocks({ blocks }: BlocksProps) { return ( ) + case BlocksEnums.block.CarouselCards: + return ( + + ) default: return null } diff --git a/apps/scandic-web/lib/graphql/Fragments/Blocks/CarouselCards.graphql b/apps/scandic-web/lib/graphql/Fragments/Blocks/CarouselCards.graphql index 0030653bd..48772de3c 100644 --- a/apps/scandic-web/lib/graphql/Fragments/Blocks/CarouselCards.graphql +++ b/apps/scandic-web/lib/graphql/Fragments/Blocks/CarouselCards.graphql @@ -91,3 +91,36 @@ fragment CarouselCards_StartPageRefs on StartPageBlocksCarouselCards { } } } + + +fragment CarouselCards_CampaignPage on CampaignPageBlocksCarouselCards { + carousel_cards { + heading + enable_filters + card_groups { + filter_label + filter_identifier + cardConnection { + edges { + node { + ...ContentCardBlock + } + } + } + } + } +} + +fragment CarouselCards_CampaignPageRefs on CampaignPageBlocksCarouselCards { + carousel_cards { + card_groups { + cardConnection { + edges { + node { + ...ContentCardBlockRef + } + } + } + } + } +} diff --git a/apps/scandic-web/lib/graphql/Query/CampaignPage/CampaignPage.graphql b/apps/scandic-web/lib/graphql/Query/CampaignPage/CampaignPage.graphql index 09e39ed5d..2f7de0e73 100644 --- a/apps/scandic-web/lib/graphql/Query/CampaignPage/CampaignPage.graphql +++ b/apps/scandic-web/lib/graphql/Query/CampaignPage/CampaignPage.graphql @@ -1,5 +1,6 @@ #import "../../Fragments/System.graphql" #import "../../Fragments/Blocks/Essentials.graphql" +#import "../../Fragments/Blocks/CarouselCards.graphql" query GetCampaignPage($locale: String!, $uid: String!) { campaign_page(uid: $uid, locale: $locale) { @@ -15,6 +16,7 @@ query GetCampaignPage($locale: String!, $uid: String!) { blocks { __typename ...Essentials_CampaignPage + ...CarouselCards_CampaignPage } system { ...System @@ -29,6 +31,10 @@ query GetCampaignPage($locale: String!, $uid: String!) { query GetCampaignPageRefs($locale: String!, $uid: String!) { campaign_page(locale: $locale, uid: $uid) { + blocks { + __typename + ...CarouselCards_CampaignPageRefs + } system { ...System } diff --git a/apps/scandic-web/server/routers/contentstack/campaignPage/output.ts b/apps/scandic-web/server/routers/contentstack/campaignPage/output.ts index 47723bbb1..403b1b734 100644 --- a/apps/scandic-web/server/routers/contentstack/campaignPage/output.ts +++ b/apps/scandic-web/server/routers/contentstack/campaignPage/output.ts @@ -2,6 +2,10 @@ import { z } from "zod" import { discriminatedUnionArray } from "@/lib/discriminatedUnion" +import { + carouselCardsRefsSchema, + carouselCardsSchema, +} from "../schemas/blocks/carouselCards" import { essentialsBlockSchema } from "../schemas/blocks/essentials" import { systemSchema } from "../schemas/system" @@ -13,8 +17,15 @@ const campaignPageEssentials = z }) .merge(essentialsBlockSchema) +const campaignPageCarouselCards = z + .object({ + __typename: z.literal(CampaignPageEnum.ContentStack.blocks.CarouselCards), + }) + .merge(carouselCardsSchema) + export const blocksSchema = z.discriminatedUnion("__typename", [ campaignPageEssentials, + campaignPageCarouselCards, ]) export const campaignPageSchema = z.object({ @@ -41,8 +52,22 @@ export const campaignPageSchema = z.object({ }), }) +/** REFS */ +const campaignPageCarouselCardsRef = z + .object({ + __typename: z.literal(CampaignPageEnum.ContentStack.blocks.CarouselCards), + }) + .merge(carouselCardsRefsSchema) + +const campaignPageBlockRefsItem = z.discriminatedUnion("__typename", [ + campaignPageCarouselCardsRef, +]) + export const campaignPageRefsSchema = z.object({ campaign_page: z.object({ + blocks: discriminatedUnionArray( + campaignPageBlockRefsItem.options + ).nullable(), system: systemSchema, }), }) diff --git a/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts b/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts index e528bcc76..028b66743 100644 --- a/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts +++ b/apps/scandic-web/server/routers/contentstack/campaignPage/utils.ts @@ -1,5 +1,7 @@ -import { generateTag } from "@/utils/generateTag" +import { generateTag, generateTagsFromSystem } from "@/utils/generateTag" +import { CampaignPageEnum } from "@/types/enums/campaignPage" +import type { System } from "@/types/requests/system" import type { CampaignPageRefs } from "@/types/trpc/routers/contentstack/campaignPage" import type { Lang } from "@/constants/languages" @@ -7,5 +9,30 @@ export function generatePageTags( validatedData: CampaignPageRefs, lang: Lang ): string[] { - return [generateTag(lang, validatedData.campaign_page.system.uid)].flat() + const connections = getConnections(validatedData) + return [ + generateTagsFromSystem(lang, connections), + generateTag(lang, validatedData.campaign_page.system.uid), + ].flat() +} + +export function getConnections({ campaign_page }: CampaignPageRefs) { + const connections: System["system"][] = [campaign_page.system] + + if (campaign_page.blocks) { + campaign_page.blocks.forEach((block) => { + switch (block.__typename) { + case CampaignPageEnum.ContentStack.blocks.CarouselCards: { + block.carousel_cards.card_groups.forEach((group) => { + group.cardConnection.edges.forEach(({ node }) => { + connections.push(node.system) + }) + }) + break + } + } + }) + } + + return connections } diff --git a/apps/scandic-web/server/routers/contentstack/schemas/blocks/carouselCards.ts b/apps/scandic-web/server/routers/contentstack/schemas/blocks/carouselCards.ts index 106042b8a..668d848eb 100644 --- a/apps/scandic-web/server/routers/contentstack/schemas/blocks/carouselCards.ts +++ b/apps/scandic-web/server/routers/contentstack/schemas/blocks/carouselCards.ts @@ -12,7 +12,7 @@ import { BlocksEnums } from "@/types/enums/blocks" const commonFields = { heading: z.string().optional(), - link: buttonSchema.optional(), + link: buttonSchema.nullish(), } as const const carouselCardGroupsFilteredSchema = z @@ -150,6 +150,6 @@ export const carouselCardsRefsSchema = z.object({ }), }) ), - link: linkConnectionRefsSchema.optional(), + link: linkConnectionRefsSchema.nullish(), }), }) diff --git a/apps/scandic-web/types/enums/campaignPage.ts b/apps/scandic-web/types/enums/campaignPage.ts index 062d56888..1e2fdd79f 100644 --- a/apps/scandic-web/types/enums/campaignPage.ts +++ b/apps/scandic-web/types/enums/campaignPage.ts @@ -2,6 +2,7 @@ export namespace CampaignPageEnum { export namespace ContentStack { export const enum blocks { Essentials = "CampaignPageBlocksEssentials", + CarouselCards = "CampaignPageBlocksCarouselCards", } } }