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 Essentials from "@/components/Blocks/Essentials"
|
||||||
|
|
||||||
import type { BlocksProps } from "@/types/components/blocks"
|
import type { BlocksProps } from "@/types/components/blocks"
|
||||||
@@ -10,6 +11,13 @@ export default function Blocks({ blocks }: BlocksProps) {
|
|||||||
return (
|
return (
|
||||||
<Essentials key={block.essentials.title} content={block.essentials} />
|
<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:
|
default:
|
||||||
return null
|
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/System.graphql"
|
||||||
#import "../../Fragments/Blocks/Essentials.graphql"
|
#import "../../Fragments/Blocks/Essentials.graphql"
|
||||||
|
#import "../../Fragments/Blocks/CarouselCards.graphql"
|
||||||
|
|
||||||
query GetCampaignPage($locale: String!, $uid: String!) {
|
query GetCampaignPage($locale: String!, $uid: String!) {
|
||||||
campaign_page(uid: $uid, locale: $locale) {
|
campaign_page(uid: $uid, locale: $locale) {
|
||||||
@@ -15,6 +16,7 @@ query GetCampaignPage($locale: String!, $uid: String!) {
|
|||||||
blocks {
|
blocks {
|
||||||
__typename
|
__typename
|
||||||
...Essentials_CampaignPage
|
...Essentials_CampaignPage
|
||||||
|
...CarouselCards_CampaignPage
|
||||||
}
|
}
|
||||||
system {
|
system {
|
||||||
...System
|
...System
|
||||||
@@ -29,6 +31,10 @@ query GetCampaignPage($locale: String!, $uid: String!) {
|
|||||||
|
|
||||||
query GetCampaignPageRefs($locale: String!, $uid: String!) {
|
query GetCampaignPageRefs($locale: String!, $uid: String!) {
|
||||||
campaign_page(locale: $locale, uid: $uid) {
|
campaign_page(locale: $locale, uid: $uid) {
|
||||||
|
blocks {
|
||||||
|
__typename
|
||||||
|
...CarouselCards_CampaignPageRefs
|
||||||
|
}
|
||||||
system {
|
system {
|
||||||
...System
|
...System
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ import { z } from "zod"
|
|||||||
|
|
||||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||||
|
|
||||||
|
import {
|
||||||
|
carouselCardsRefsSchema,
|
||||||
|
carouselCardsSchema,
|
||||||
|
} from "../schemas/blocks/carouselCards"
|
||||||
import { essentialsBlockSchema } from "../schemas/blocks/essentials"
|
import { essentialsBlockSchema } from "../schemas/blocks/essentials"
|
||||||
import { systemSchema } from "../schemas/system"
|
import { systemSchema } from "../schemas/system"
|
||||||
|
|
||||||
@@ -13,8 +17,15 @@ const campaignPageEssentials = z
|
|||||||
})
|
})
|
||||||
.merge(essentialsBlockSchema)
|
.merge(essentialsBlockSchema)
|
||||||
|
|
||||||
|
const campaignPageCarouselCards = z
|
||||||
|
.object({
|
||||||
|
__typename: z.literal(CampaignPageEnum.ContentStack.blocks.CarouselCards),
|
||||||
|
})
|
||||||
|
.merge(carouselCardsSchema)
|
||||||
|
|
||||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||||
campaignPageEssentials,
|
campaignPageEssentials,
|
||||||
|
campaignPageCarouselCards,
|
||||||
])
|
])
|
||||||
|
|
||||||
export const campaignPageSchema = z.object({
|
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({
|
export const campaignPageRefsSchema = z.object({
|
||||||
campaign_page: z.object({
|
campaign_page: z.object({
|
||||||
|
blocks: discriminatedUnionArray(
|
||||||
|
campaignPageBlockRefsItem.options
|
||||||
|
).nullable(),
|
||||||
system: systemSchema,
|
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 { CampaignPageRefs } from "@/types/trpc/routers/contentstack/campaignPage"
|
||||||
import type { Lang } from "@/constants/languages"
|
import type { Lang } from "@/constants/languages"
|
||||||
|
|
||||||
@@ -7,5 +9,30 @@ export function generatePageTags(
|
|||||||
validatedData: CampaignPageRefs,
|
validatedData: CampaignPageRefs,
|
||||||
lang: Lang
|
lang: Lang
|
||||||
): string[] {
|
): 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 = {
|
const commonFields = {
|
||||||
heading: z.string().optional(),
|
heading: z.string().optional(),
|
||||||
link: buttonSchema.optional(),
|
link: buttonSchema.nullish(),
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
const carouselCardGroupsFilteredSchema = z
|
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 namespace ContentStack {
|
||||||
export const enum blocks {
|
export const enum blocks {
|
||||||
Essentials = "CampaignPageBlocksEssentials",
|
Essentials = "CampaignPageBlocksEssentials",
|
||||||
|
CarouselCards = "CampaignPageBlocksCarouselCards",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user