feat(SW-187): Added tertiary links data

This commit is contained in:
Pontus Dreij
2024-09-05 10:16:55 +02:00
parent c033f776b6
commit 2a59ad431b
9 changed files with 94 additions and 29 deletions

View File

@@ -21,11 +21,12 @@ function SocialIcon({ iconName }: SocialIconsProps) {
export default async function FooterDetails({ export default async function FooterDetails({
socialMedia, socialMedia,
tertiaryLinks,
}: FooterDetailsProps) { }: FooterDetailsProps) {
const lang = getLang() const lang = getLang()
const { formatMessage } = await getIntl() const { formatMessage } = await getIntl()
const currentYear = new Date().getFullYear() const currentYear = new Date().getFullYear()
const { tertiaryLinks, languageSwitcher } = footer const { languageSwitcher } = footer
return ( return (
<section className={styles.details}> <section className={styles.details}>
<div className={styles.topContainer}> <div className={styles.topContainer}>
@@ -68,18 +69,21 @@ export default async function FooterDetails({
</div> </div>
<div className={styles.navigationContainer}> <div className={styles.navigationContainer}>
<nav className={styles.navigation}> <nav className={styles.navigation}>
{tertiaryLinks.map((link) => ( {tertiaryLinks?.map(
<Footnote asChild textTransform="uppercase" key={link.id}> (link) =>
<Link link.url && (
className={styles.link} <Footnote asChild textTransform="uppercase" key={link.title}>
color="peach50" <Link
href={link.href} className={styles.link}
target="_blank" color="peach50"
> href={link.url}
{link.title} target="_blank"
</Link> >
</Footnote> {link.title}
))} </Link>
</Footnote>
)
)}
</nav> </nav>
<LanguageSwitcher type="desktopFooter" urls={languageSwitcher.urls} /> <LanguageSwitcher type="desktopFooter" urls={languageSwitcher.urls} />
</div> </div>

View File

@@ -19,7 +19,10 @@ export default async function Footer() {
secondaryLinks={footerData.secondaryLinks} secondaryLinks={footerData.secondaryLinks}
appDownloads={footerData.appDownloads} appDownloads={footerData.appDownloads}
/> />
<FooterDetails socialMedia={footerData.socialMedia} /> <FooterDetails
socialMedia={footerData.socialMedia}
tertiaryLinks={footerData.tertiaryLinks}
/>
</footer> </footer>
) )
} }

View File

@@ -0,0 +1,22 @@
#import "../../Refs/LoyaltyPage/LoyaltyPage.graphql"
#import "../../Refs/MyPages/AccountPage.graphql"
#import "../../Refs/ContentPage/ContentPage.graphql"
fragment TertiaryLinksRef on Footer {
__typename
tertiary_links {
pageConnection {
edges {
node {
__typename
...LoyaltyPageRef
...ContentPageRef
...AccountPageRef
}
}
}
}
system {
...System
}
}

View File

@@ -0,0 +1,28 @@
fragment TertiaryLinks on Footer {
tertiary_links {
open_in_new_tab
link {
href
title
}
pageConnection {
edges {
node {
__typename
... on AccountPage {
title
url
}
... on LoyaltyPage {
title
url
}
... on ContentPage {
title
url
}
}
}
}
}
}

View File

@@ -2,8 +2,10 @@
#import "../Fragments/Footer/MainLinks.graphql" #import "../Fragments/Footer/MainLinks.graphql"
#import "../Fragments/Footer/SecondaryLinks.graphql" #import "../Fragments/Footer/SecondaryLinks.graphql"
#import "../Fragments/Footer/SocialMedia.graphql" #import "../Fragments/Footer/SocialMedia.graphql"
#import "../Fragments/Footer/TertiaryLinks.graphql"
#import "../Fragments/Footer/Refs/MainLinks.graphql" #import "../Fragments/Footer/Refs/MainLinks.graphql"
#import "../Fragments/Footer/Refs/SecondaryLinks.graphql" #import "../Fragments/Footer/Refs/SecondaryLinks.graphql"
#import "../Fragments/Footer/Refs/TertiaryLinks.graphql"
#import "../Fragments/Refs/System.graphql" #import "../Fragments/Refs/System.graphql"
query GetFooter($locale: String!) { query GetFooter($locale: String!) {
@@ -13,6 +15,7 @@ query GetFooter($locale: String!) {
...SecondaryLinks ...SecondaryLinks
...AppDownloads ...AppDownloads
...SocialMedia ...SocialMedia
...TertiaryLinks
} }
} }
} }
@@ -22,6 +25,7 @@ query GetFooterRef($locale: String!) {
items { items {
...MainLinksRef ...MainLinksRef
...SecondaryLinksRef ...SecondaryLinksRef
...TertiaryLinksRef
system { system {
...System ...System
} }

View File

@@ -317,6 +317,7 @@ export const validateFooterConfigSchema = z.object({
}) })
), ),
}), }),
tertiary_links: z.array(validateLinkItem),
}) })
), ),
}), }),
@@ -357,6 +358,11 @@ const validateFooterRefConfigSchema = z.object({
), ),
}) })
), ),
tertiary_links: z.array(
z.object({
pageConnection: pageConnectionRefs,
})
),
system: z.object({ system: z.object({
content_type_uid: z.string(), content_type_uid: z.string(),
uid: z.string(), uid: z.string(),

View File

@@ -351,7 +351,7 @@ export const baseQueryRouter = router({
}, },
} }
) )
console.log("responseRef", responseRef)
// There's currently no error handling/validation for the responseRef, should it be added? // There's currently no error handling/validation for the responseRef, should it be added?
getFooterCounter.add(1, { lang: input.lang }) getFooterCounter.add(1, { lang: input.lang })
console.info( console.info(
@@ -431,9 +431,10 @@ export const baseQueryRouter = router({
}) })
) )
console.log( console.log("secondaryLinks", JSON.stringify(secondaryLinks))
"secondaryLinks data",
JSON.stringify(secondaryLinks, null, 4) const tertiaryLinks = transformPageConnectionLinks(
validatedFooterData.tertiary_links
) )
return { return {
@@ -441,6 +442,7 @@ export const baseQueryRouter = router({
appDownloads: validatedFooterData.app_downloads, appDownloads: validatedFooterData.app_downloads,
secondaryLinks: secondaryLinks, secondaryLinks: secondaryLinks,
socialMedia: validatedFooterData.social_media, socialMedia: validatedFooterData.social_media,
tertiaryLinks: tertiaryLinks,
} }
}), }),
}) })

View File

@@ -1,7 +1,6 @@
import type { FooterLinkItem } from "./output" import type { FooterLinkItem } from "./output"
export function transformPageConnectionLinks(links: FooterLinkItem[]) { export function transformPageConnectionLinks(links: FooterLinkItem[]) {
console.log("linksdata", links[0].pageConnection?.edges)
if (!links) return [] if (!links) return []
return links.flatMap((link) => { return links.flatMap((link) => {
if (link.pageConnection?.edges.length) { if (link.pageConnection?.edges.length) {

View File

@@ -1,20 +1,16 @@
export type FooterMainNav = { export type FooterLink = {
url: string
title: string
}
export type FooterMainNavProps = {
mainLinks: FooterMainNav[]
}
export type FooterSecondaryNav = {
isExternal: boolean isExternal: boolean
openInNewTab: boolean openInNewTab: boolean
title: string title: string
url: string url: string
} }
export type FooterMainNavProps = {
mainLinks: FooterLink[]
}
type FooterSecondaryNavGroup = { type FooterSecondaryNavGroup = {
title: string title: string
links: FooterSecondaryNav[] links: FooterLink[]
} }
type FooterLinkWithType = { type FooterLinkWithType = {
href?: href?:
@@ -42,6 +38,7 @@ export type FooterSecondaryNavProps = {
export type FooterDetailsProps = { export type FooterDetailsProps = {
socialMedia?: FooterSocialMedia socialMedia?: FooterSocialMedia
tertiaryLinks?: FooterLink[]
} }
export type FooterNavigationProps = FooterMainNavProps & FooterSecondaryNavProps export type FooterNavigationProps = FooterMainNavProps & FooterSecondaryNavProps