Feat/SW-2273 campaign page accordion block
Approved-by: Matilda Landström
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import AccordionSection from "@/components/Blocks/Accordion"
|
||||
import CarouselCards from "@/components/Blocks/CarouselCards"
|
||||
import Essentials from "@/components/Blocks/Essentials"
|
||||
|
||||
@@ -18,6 +19,14 @@ export default function Blocks({ blocks }: BlocksProps) {
|
||||
key={block.carousel_cards.heading}
|
||||
/>
|
||||
)
|
||||
case BlocksEnums.block.Accordion:
|
||||
return (
|
||||
<AccordionSection
|
||||
accordion={block.accordion.accordions}
|
||||
title={block.accordion.title}
|
||||
key={block.accordion.title}
|
||||
/>
|
||||
)
|
||||
default:
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -379,3 +379,104 @@ fragment SpecificAccordion_DestinationCountryPageRefs on DestinationCountryPageB
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment Accordion_CampaignPage on CampaignPageBlocksAccordion {
|
||||
__typename
|
||||
accordion {
|
||||
title
|
||||
accordions {
|
||||
__typename
|
||||
...GlobalAccordion_CampaignPage
|
||||
...SpecificAccordion_CampaignPage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment GlobalAccordion_CampaignPage on CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion {
|
||||
__typename
|
||||
global_accordion {
|
||||
global_accordionConnection {
|
||||
edges {
|
||||
node {
|
||||
...AccordionBlock
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment SpecificAccordion_CampaignPage on CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion {
|
||||
__typename
|
||||
specific_accordion {
|
||||
questions {
|
||||
question
|
||||
answer {
|
||||
json
|
||||
embedded_itemsConnection {
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
...SysAsset
|
||||
...AccountPageLink
|
||||
...CollectionPageLink
|
||||
...ContentPageLink
|
||||
...DestinationCityPageLink
|
||||
...DestinationCountryPageLink
|
||||
...DestinationOverviewPageLink
|
||||
...HotelPageLink
|
||||
...LoyaltyPageLink
|
||||
...StartPageLink
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment Accordion_CampaignPageRefs on CampaignPageBlocksAccordion {
|
||||
accordion {
|
||||
accordions {
|
||||
__typename
|
||||
...GlobalAccordion_CampaignPageRefs
|
||||
...SpecificAccordion_CampaignPageRefs
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment GlobalAccordion_CampaignPageRefs on CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion {
|
||||
global_accordion {
|
||||
global_accordionConnection {
|
||||
edges {
|
||||
node {
|
||||
...AccordionBlockRefs
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment SpecificAccordion_CampaignPageRefs on CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion {
|
||||
specific_accordion {
|
||||
questions {
|
||||
answer {
|
||||
embedded_itemsConnection {
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
...AccountPageRef
|
||||
...CollectionPageRef
|
||||
...ContentPageRef
|
||||
...DestinationCityPageRef
|
||||
...DestinationCountryPageRef
|
||||
...DestinationOverviewPageRef
|
||||
...HotelPageRef
|
||||
...LoyaltyPageRef
|
||||
...StartPageRef
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#import "../../Fragments/System.graphql"
|
||||
|
||||
#import "../../Fragments/Blocks/Accordion.graphql"
|
||||
#import "../../Fragments/Blocks/Essentials.graphql"
|
||||
#import "../../Fragments/Blocks/CarouselCards.graphql"
|
||||
|
||||
@@ -17,6 +19,7 @@ query GetCampaignPage($locale: String!, $uid: String!) {
|
||||
__typename
|
||||
...Essentials_CampaignPage
|
||||
...CarouselCards_CampaignPage
|
||||
...Accordion_CampaignPage
|
||||
}
|
||||
system {
|
||||
...System
|
||||
@@ -34,6 +37,7 @@ query GetCampaignPageRefs($locale: String!, $uid: String!) {
|
||||
blocks {
|
||||
__typename
|
||||
...CarouselCards_CampaignPageRefs
|
||||
...Accordion_CampaignPageRefs
|
||||
}
|
||||
system {
|
||||
...System
|
||||
|
||||
@@ -2,6 +2,10 @@ import { z } from "zod"
|
||||
|
||||
import { discriminatedUnionArray } from "@/lib/discriminatedUnion"
|
||||
|
||||
import {
|
||||
accordionRefsSchema,
|
||||
accordionSchema,
|
||||
} from "../schemas/blocks/accordion"
|
||||
import {
|
||||
carouselCardsRefsSchema,
|
||||
carouselCardsSchema,
|
||||
@@ -23,9 +27,16 @@ const campaignPageCarouselCards = z
|
||||
})
|
||||
.merge(carouselCardsSchema)
|
||||
|
||||
export const campaignPageAccordion = z
|
||||
.object({
|
||||
__typename: z.literal(CampaignPageEnum.ContentStack.blocks.Accordion),
|
||||
})
|
||||
.merge(accordionSchema)
|
||||
|
||||
export const blocksSchema = z.discriminatedUnion("__typename", [
|
||||
campaignPageEssentials,
|
||||
campaignPageCarouselCards,
|
||||
campaignPageAccordion,
|
||||
])
|
||||
|
||||
export const campaignPageSchema = z.object({
|
||||
@@ -59,8 +70,15 @@ const campaignPageCarouselCardsRef = z
|
||||
})
|
||||
.merge(carouselCardsRefsSchema)
|
||||
|
||||
const campaignPageAccordionRefs = z
|
||||
.object({
|
||||
__typename: z.literal(CampaignPageEnum.ContentStack.blocks.Accordion),
|
||||
})
|
||||
.merge(accordionRefsSchema)
|
||||
|
||||
const campaignPageBlockRefsItem = z.discriminatedUnion("__typename", [
|
||||
campaignPageCarouselCardsRef,
|
||||
campaignPageAccordionRefs,
|
||||
])
|
||||
|
||||
export const campaignPageRefsSchema = z.object({
|
||||
|
||||
@@ -30,6 +30,12 @@ export function getConnections({ campaign_page }: CampaignPageRefs) {
|
||||
})
|
||||
break
|
||||
}
|
||||
case CampaignPageEnum.ContentStack.blocks.Accordion: {
|
||||
if (block.accordion.length) {
|
||||
connections.push(...block.accordion)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,6 +36,8 @@ export const accordionItemsSchema = z.array(
|
||||
export type Accordion = z.infer<typeof accordionSchema>
|
||||
|
||||
enum AccordionEnum {
|
||||
CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion = "CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion",
|
||||
CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion = "CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion",
|
||||
ContentPageBlocksAccordionBlockAccordionsGlobalAccordion = "ContentPageBlocksAccordionBlockAccordionsGlobalAccordion",
|
||||
ContentPageBlocksAccordionBlockAccordionsSpecificAccordion = "ContentPageBlocksAccordionBlockAccordionsSpecificAccordion",
|
||||
DestinationCityPageBlocksAccordionBlockAccordionsGlobalAccordion = "DestinationCityPageBlocksAccordionBlockAccordionsGlobalAccordion",
|
||||
@@ -81,6 +83,7 @@ export const accordionSchema = z.object({
|
||||
...data,
|
||||
accordions: data.accordions.flatMap((acc) => {
|
||||
switch (acc.__typename) {
|
||||
case AccordionEnum.CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.ContentPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationCityPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationCountryPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
@@ -91,6 +94,7 @@ export const accordionSchema = z.object({
|
||||
}
|
||||
) || []
|
||||
)
|
||||
case AccordionEnum.CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.ContentPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationCityPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationCountryPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
@@ -157,6 +161,7 @@ export const accordionRefsSchema = z.object({
|
||||
.transform((data) => {
|
||||
return data.accordions.flatMap((accordion) => {
|
||||
switch (accordion.__typename) {
|
||||
case AccordionEnum.CampaignPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.ContentPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationCityPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
case AccordionEnum.DestinationCountryPageBlocksAccordionBlockAccordionsGlobalAccordion:
|
||||
@@ -171,7 +176,7 @@ export const accordionRefsSchema = z.object({
|
||||
}
|
||||
) || []
|
||||
)
|
||||
case AccordionEnum.ContentPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.CampaignPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationCityPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
case AccordionEnum.DestinationCountryPageBlocksAccordionBlockAccordionsSpecificAccordion:
|
||||
return (
|
||||
@@ -181,6 +186,8 @@ export const accordionRefsSchema = z.object({
|
||||
)
|
||||
) || []
|
||||
)
|
||||
default:
|
||||
return []
|
||||
}
|
||||
})
|
||||
}),
|
||||
|
||||
@@ -3,6 +3,7 @@ export namespace CampaignPageEnum {
|
||||
export const enum blocks {
|
||||
Essentials = "CampaignPageBlocksEssentials",
|
||||
CarouselCards = "CampaignPageBlocksCarouselCards",
|
||||
Accordion = "CampaignPageBlocksAccordion",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user