fix: get joinloyalty button from contentstack

This commit is contained in:
Christel Westerberg
2024-07-02 13:11:06 +02:00
parent 1e3bbed6d1
commit d7b87585b9
5 changed files with 119 additions and 23 deletions

View File

@@ -27,6 +27,7 @@ import { InsertResponse } from "@/types/components/imageVaultImage"
import {
LoyaltyBlocksTypenameEnum,
LoyaltyCardsGridEnum,
SidebarTypenameEnum,
} from "@/types/components/loyalty/enums"
function makeImageVaultImage(image: any) {
@@ -36,21 +37,25 @@ function makeImageVaultImage(image: any) {
}
function makeButtonObject(button: any) {
if (!button) return null
const isContenstackLink =
button?.is_contentstack_link || button.linkConnection?.edges?.length
return {
openInNewTab: button.open_in_new_tab,
openInNewTab: button?.open_in_new_tab,
title:
button.cta_text ||
(button.is_contentstack_link && button.linkConnection.edges.length
(isContenstackLink
? button.linkConnection.edges[0].node.title
: button.external_link.title),
href:
button.is_contentstack_link && button.linkConnection.edges.length
? button.linkConnection.edges[0].node.web?.original_url ||
removeMultipleSlashes(
`/${button.linkConnection.edges[0].node.system.locale}/${button.linkConnection.edges[0].node.url}`
)
: button.external_link.href,
isExternal: !button.is_contentstack_link,
href: isContenstackLink
? button.linkConnection.edges[0].node.web?.original_url ||
removeMultipleSlashes(
`/${button.linkConnection.edges[0].node.system.locale}/${button.linkConnection.edges[0].node.url}`
)
: button.external_link.href,
isExternal: !isContenstackLink,
}
}
@@ -155,11 +160,7 @@ export const loyaltyPageQueryRouter = router({
return {
...card,
image: makeImageVaultImage(card.image),
link: makeButtonObject({
...card.link,
is_contentstack_link:
!!card.link.linkConnection.edges.length,
}),
link: makeButtonObject(card.link),
}
case LoyaltyCardsGridEnum.Card:
return {
@@ -185,11 +186,28 @@ export const loyaltyPageQueryRouter = router({
})
: null
const sidebar = response.data.loyalty_page.sidebar
? response.data.loyalty_page.sidebar.map((item: any) => {
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 =