refactor(SW-438): change name to teasercard

This commit is contained in:
Matilda Landström
2024-10-16 10:21:34 +02:00
parent 8eb822da16
commit df17798662
8 changed files with 60 additions and 62 deletions

View File

@@ -29,16 +29,6 @@ export default function Sidebar({ blocks }: SidebarProps) {
/>
</section>
)
case SidebarEnums.blocks.ContentCard:
return (
<TeaserCard
{...block.content_card}
title={block.content_card.heading}
description={block.content_card.body_text}
style={block.content_card.theme}
/>
)
case SidebarEnums.blocks.DynamicContent:
switch (block.dynamic_content.component) {
case DynamicContentEnum.Sidebar.components.my_pages_navigation:
@@ -62,7 +52,15 @@ export default function Sidebar({ blocks }: SidebarProps) {
theme={block.scripted_card.theme ?? "image"}
/>
)
case SidebarEnums.blocks.TeaserCard:
return (
<TeaserCard
{...block.teaser_card}
title={block.teaser_card.heading}
description={block.teaser_card.body_text}
style={block.teaser_card.theme}
/>
)
case SidebarEnums.blocks.QuickLinks:
return <ShortcutsList {...block.shortcuts} />

View File

@@ -9,11 +9,11 @@
#import "../Blocks/TeaserCard.graphql"
#import "../Blocks/Refs/TeaserCard.graphql"
fragment ContentCardSidebar_ContentPage on ContentPageSidebarContentCard {
fragment TeaserCardSidebar_ContentPage on ContentPageSidebarTeaserCard {
__typename
content_card {
teaser_card {
theme
content_cardConnection {
teaser_cardConnection {
edges {
node {
__typename
@@ -24,9 +24,9 @@ fragment ContentCardSidebar_ContentPage on ContentPageSidebarContentCard {
}
}
fragment ContentCardSidebar_ContentPageRefs on ContentPageSidebarContentCard {
content_card {
content_cardConnection {
fragment TeaserCardSidebar_ContentPageRefs on ContentPageSidebarTeaserCard {
teaser_card {
teaser_cardConnection {
edges {
node {
__typename

View File

@@ -13,7 +13,7 @@
#import "../../Fragments/Sidebar/Content.graphql"
#import "../../Fragments/Sidebar/DynamicContent.graphql"
#import "../../Fragments/Sidebar/JoinLoyaltyContact.graphql"
#import "../../Fragments/Sidebar/ContentCard.graphql"
#import "../../Fragments/Sidebar/TeaserCard.graphql"
#import "../../Fragments/Sidebar/ScriptedCard.graphql"
#import "../../Fragments/Sidebar/QuickLinks.graphql"
@@ -31,8 +31,8 @@ query GetContentPage($locale: String!, $uid: String!) {
...ContentSidebar_ContentPage
...DynamicContentSidebar_ContentPage
...JoinLoyaltyContactSidebar_ContentPage
...ContentCardSidebar_ContentPage
...ScriptedCardSidebar_ContentPage
...TeaserCardSidebar_ContentPage
...QuickLinksSidebar_ContentPage
}
system {
@@ -96,9 +96,9 @@ query GetContentPageRefs($locale: String!, $uid: String!) {
sidebar {
__typename
...ContentSidebar_ContentPageRefs
...ContentCardSidebar_ContentPageRefs
...JoinLoyaltyContactSidebar_ContentPageRefs
...ScriptedCardSidebar_ContentPageRefs
...TeaserCardSidebar_ContentPageRefs
...QuickLinksSidebar_ContentPageRefs
}
system {

View File

@@ -34,10 +34,6 @@ import {
contentRefsSchema as sidebarContentRefsSchema,
contentSchema as sidebarContentSchema,
} from "../schemas/sidebar/content"
import {
contentCardRefschema,
contentCardsSchema,
} from "../schemas/sidebar/contentCard"
import { dynamicContentSchema as sidebarDynamicContentSchema } from "../schemas/sidebar/dynamicContent"
import {
joinLoyaltyContactRefsSchema,
@@ -51,6 +47,10 @@ import {
scriptedCardRefschema,
scriptedCardsSchema,
} from "../schemas/sidebar/scriptedCard"
import {
teaserCardRefschema,
teaserCardsSchema,
} from "../schemas/sidebar/teaserCard"
import { systemSchema } from "../schemas/system"
import { ContentPageEnum } from "@/types/enums/contentPage"
@@ -134,30 +134,30 @@ export const contentPageJoinLoyaltyContact = z
})
.merge(joinLoyaltyContactSchema)
export const contentPageSidebarQuicklinks = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.QuickLinks),
})
.merge(quickLinksSchema)
export const contentPageSidebarContentCard = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.ContentCard),
})
.merge(contentCardsSchema)
export const contentPageSidebarScriptedCard = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.ScriptedCard),
})
.merge(scriptedCardsSchema)
export const contentPageSidebarTeaserCard = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.TeaserCard),
})
.merge(teaserCardsSchema)
export const contentPageSidebarQuicklinks = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.QuickLinks),
})
.merge(quickLinksSchema)
export const sidebarSchema = z.discriminatedUnion("__typename", [
contentPageSidebarContent,
contentPageSidebarContentCard,
contentPageSidebarDynamicContent,
contentPageJoinLoyaltyContact,
contentPageSidebarScriptedCard,
contentPageSidebarTeaserCard,
contentPageSidebarQuicklinks,
])
@@ -263,12 +263,6 @@ const contentPageSidebarContentRef = z
})
.merge(sidebarContentRefsSchema)
const contentPageSidebarContentCardRef = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.ContentCard),
})
.merge(contentCardRefschema)
const contentPageSidebarJoinLoyaltyContactRef = z
.object({
__typename: z.literal(
@@ -283,6 +277,12 @@ const contentPageSidebarScriptedCardRef = z
})
.merge(scriptedCardRefschema)
const contentPageSidebarTeaserCardRef = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.TeaserCard),
})
.merge(teaserCardRefschema)
const contentPageSidebarQuickLinksRef = z
.object({
__typename: z.literal(ContentPageEnum.ContentStack.sidebar.QuickLinks),
@@ -291,9 +291,9 @@ const contentPageSidebarQuickLinksRef = z
const contentPageSidebarRefsItem = z.discriminatedUnion("__typename", [
contentPageSidebarContentRef,
contentPageSidebarContentCardRef,
contentPageSidebarJoinLoyaltyContactRef,
contentPageSidebarScriptedCardRef,
contentPageSidebarTeaserCardRef,
contentPageSidebarQuickLinksRef,
])

View File

@@ -171,11 +171,6 @@ export function getConnections({ content_page }: ContentPageRefs) {
connections.push(...block.content)
}
break
case ContentPageEnum.ContentStack.sidebar.ContentCard:
if (block.content_card?.length) {
connections.push(...block.content_card)
}
break
case ContentPageEnum.ContentStack.sidebar.JoinLoyaltyContact:
if (block.join_loyalty_contact?.button) {
connections.push(block.join_loyalty_contact.button)
@@ -186,6 +181,11 @@ export function getConnections({ content_page }: ContentPageRefs) {
connections.push(...block.scripted_card)
}
break
case ContentPageEnum.ContentStack.sidebar.TeaserCard:
if (block.teaser_card?.length) {
connections.push(...block.teaser_card)
}
break
case ContentPageEnum.ContentStack.sidebar.QuickLinks:
if (block.shortcuts.shortcuts.length) {
connections.push(...block.shortcuts.shortcuts)

View File

@@ -9,15 +9,15 @@ import {
import { SidebarEnums } from "@/types/enums/sidebar"
export const contentCardsSchema = z.object({
export const teaserCardsSchema = z.object({
typename: z
.literal(SidebarEnums.blocks.ContentCard)
.literal(SidebarEnums.blocks.TeaserCard)
.optional()
.default(SidebarEnums.blocks.ContentCard),
content_card: z
.default(SidebarEnums.blocks.TeaserCard),
teaser_card: z
.object({
theme: z.enum(["featured", "default"]).nullable().default("default"),
content_cardConnection: z.object({
teaser_cardConnection: z.object({
edges: z.array(
z.object({
node: teaserCardBlockSchema,
@@ -27,16 +27,16 @@ export const contentCardsSchema = z.object({
})
.transform((data) => {
return {
...transformTeaserCardBlock(data.content_cardConnection.edges[0].node),
...transformTeaserCardBlock(data.teaser_cardConnection.edges[0].node),
theme: data.theme,
}
}),
})
export const contentCardRefschema = z.object({
content_card: z
export const teaserCardRefschema = z.object({
teaser_card: z
.object({
content_cardConnection: z.object({
teaser_cardConnection: z.object({
edges: z.array(
z.object({
node: teaserCardBlockRefsSchema,
@@ -46,8 +46,8 @@ export const contentCardRefschema = z.object({
})
.transform((data) => {
let card = null
if (data.content_cardConnection.edges.length) {
card = transformCardBlockRefs(data.content_cardConnection.edges[0].node)
if (data.teaser_cardConnection.edges.length) {
card = transformCardBlockRefs(data.teaser_cardConnection.edges[0].node)
}
return card
}),

View File

@@ -13,10 +13,10 @@ export namespace ContentPageEnum {
export const enum sidebar {
Content = "ContentPageSidebarContent",
ContentCard = "ContentPageSidebarContentCard",
DynamicContent = "ContentPageSidebarDynamicContent",
JoinLoyaltyContact = "ContentPageSidebarJoinLoyaltyContact",
ScriptedCard = "ContentPageSidebarScriptedCard",
TeaserCard = "ContentPageSidebarTeaserCard",
QuickLinks = "ContentPageSidebarShortcuts",
}
}

View File

@@ -1,10 +1,10 @@
export namespace SidebarEnums {
export const enum blocks {
Content = "Content",
ContentCard = "ContentCard",
DynamicContent = "DynamicContent",
JoinLoyaltyContact = "JoinLoyaltyContact",
ScriptedCard = "ScriptedCard",
TeaserCard = "TeaserCard",
QuickLinks = "QuickLinks",
}
}