Feat/SW-2272 campaign cards block
Approved-by: Matilda Landström
This commit is contained in:
@@ -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 (
|
||||
<Essentials key={block.essentials.title} content={block.essentials} />
|
||||
)
|
||||
case BlocksEnums.block.CarouselCards:
|
||||
return (
|
||||
<CarouselCards
|
||||
carousel_cards={block.carousel_cards}
|
||||
key={block.carousel_cards.heading}
|
||||
/>
|
||||
)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -2,6 +2,7 @@ export namespace CampaignPageEnum {
|
||||
export namespace ContentStack {
|
||||
export const enum blocks {
|
||||
Essentials = "CampaignPageBlocksEssentials",
|
||||
CarouselCards = "CampaignPageBlocksCarouselCards",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user