From d7b87585b978e723efcdc4183cdd9ade6d0df985 Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Tue, 2 Jul 2024 13:11:06 +0200 Subject: [PATCH] fix: get joinloyalty button from contentstack --- .../Loyalty/Sidebar/JoinLoyalty/index.tsx | 21 ++++++-- lib/graphql/Query/LoyaltyPage.graphql | 35 +++++++++++++ .../contentstack/loyaltyPage/output.ts | 22 ++++++++ .../routers/contentstack/loyaltyPage/query.ts | 50 +++++++++++++------ .../routers/contentstack/loyaltyPage/utils.ts | 14 +++++- 5 files changed, 119 insertions(+), 23 deletions(-) diff --git a/components/Loyalty/Sidebar/JoinLoyalty/index.tsx b/components/Loyalty/Sidebar/JoinLoyalty/index.tsx index 481f984a7..e940aab0f 100644 --- a/components/Loyalty/Sidebar/JoinLoyalty/index.tsx +++ b/components/Loyalty/Sidebar/JoinLoyalty/index.tsx @@ -34,11 +34,22 @@ export default async function JoinLoyaltyContact({ {block.preamble ? {block.preamble} : null} - + {block.button ? ( + + ) : null}
{formatMessage({ id: "Already a friend?" })} { + switch (item.__typename) { + case SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact: + return { + ...item, + join_loyalty_contact: { + ...item.join_loyalty_contact, + button: makeButtonObject(item.join_loyalty_contact.button), + }, + } + default: + return item + } + }) + : null + const loyaltyPage = { heading: response.data.loyalty_page.heading, system: response.data.loyalty_page.system, blocks, - sidebar: response.data.loyalty_page.sidebar, + sidebar, } const validatedLoyaltyPage = diff --git a/server/routers/contentstack/loyaltyPage/utils.ts b/server/routers/contentstack/loyaltyPage/utils.ts index 409ebadef..95e251075 100644 --- a/server/routers/contentstack/loyaltyPage/utils.ts +++ b/server/routers/contentstack/loyaltyPage/utils.ts @@ -3,6 +3,7 @@ import { LoyaltyPageRefsDataRaw } from "./output" import { LoyaltyBlocksTypenameEnum, LoyaltyCardsGridEnum, + SidebarTypenameEnum, } from "@/types/components/loyalty/enums" import type { Edges } from "@/types/requests/utils/edges" import type { NodeRefs } from "@/types/requests/utils/refs" @@ -59,8 +60,17 @@ export function getConnections(refs: LoyaltyPageRefsDataRaw) { } if (refs.loyalty_page.sidebar) { refs.loyalty_page.sidebar?.forEach((item) => { - if (item.content.content.embedded_itemsConnection.edges.length) { - connections.push(item.content.content.embedded_itemsConnection) + switch (item.__typename) { + case SidebarTypenameEnum.LoyaltyPageSidebarContent: + if (item.content.content.embedded_itemsConnection.edges.length) { + connections.push(item.content.content.embedded_itemsConnection) + } + break + case SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact: + if (item.join_loyalty_contact.button?.linkConnection) { + connections.push(item.join_loyalty_contact.button.linkConnection) + } + break } }) }