Files
web/components/MyPages/AccountPage/Webview/Content.tsx
Matilda Landström 801a041404 Merged in feat/best-friend-hero (pull request #338)
Feat(SW-170): Update overview hero

Approved-by: Christel Westerberg
2024-07-12 06:45:44 +00:00

114 lines
4.1 KiB
TypeScript

import JsonToHtml from "@/components/JsonToHtml"
import Overview from "@/components/MyPages/Blocks/Overview"
import Shortcuts from "@/components/MyPages/Blocks/Shortcuts"
import { removeMultipleSlashes } from "@/utils/url"
import { modWebviewLink } from "@/utils/webviews"
import CurrentBenefitsBlock from "../../Blocks/Benefits/CurrentLevel"
import NextLevelBenefitsBlock from "../../Blocks/Benefits/NextLevel"
import CurrentPointsBalance from "../../Blocks/Points/CurrentPointsBalance"
import EarnAndBurn from "../../Blocks/Points/EarnAndBurn"
import PointsOverview from "../../Blocks/Points/Overview"
import {
AccountPageContentProps,
ContentProps,
} from "@/types/components/myPages/myPage/accountPage"
import {
ContentEntries,
DynamicContentComponents,
} from "@/types/components/myPages/myPage/enums"
function DynamicComponent({ component, props }: AccountPageContentProps) {
switch (component) {
case DynamicContentComponents.membership_overview:
return <Overview {...props} />
case DynamicContentComponents.points_overview:
return <PointsOverview {...props} />
case DynamicContentComponents.current_benefits:
return <CurrentBenefitsBlock {...props} />
case DynamicContentComponents.next_benefits:
return <NextLevelBenefitsBlock {...props} />
case DynamicContentComponents.my_points:
return <CurrentPointsBalance {...props} />
case DynamicContentComponents.expiring_points:
// TODO: Add once available
// return <ExpiringPoints />
return null
case DynamicContentComponents.earn_and_burn:
return <EarnAndBurn {...props} />
default:
return null
}
}
export default function Content({ lang, content }: ContentProps) {
return (
<>
{content.map((item, idx) => {
switch (item.__typename) {
case ContentEntries.AccountPageContentDynamicContent:
const link = item.dynamic_content.link.linkConnection.edges.length
? {
href:
item.dynamic_content.link.linkConnection.edges[0].node
.original_url ||
modWebviewLink(
removeMultipleSlashes(
`/${item.dynamic_content.link.linkConnection.edges[0].node.system.locale}/${item.dynamic_content.link.linkConnection.edges[0].node.url}`
),
item.dynamic_content.link.linkConnection.edges[0].node
.system.locale
),
text: item.dynamic_content.link.link_text,
}
: null
const componentProps = {
lang,
title: item.dynamic_content.title,
// TODO: rename preamble to subtitle in Contentstack?
subtitle: item.dynamic_content.preamble,
...(link && { link }),
}
return (
<DynamicComponent
key={`${item.dynamic_content.title}-${idx}`}
component={item.dynamic_content.component}
props={componentProps}
/>
)
case ContentEntries.AccountPageContentShortcuts:
const shortcuts = item.shortcuts.shortcuts.map((shortcut) => {
return {
...shortcut,
url: modWebviewLink(shortcut.url, lang),
}
})
return (
<Shortcuts
key={`${item.shortcuts.title}-${idx}`}
shortcuts={shortcuts}
subtitle={item.shortcuts.preamble}
title={item.shortcuts.title}
/>
)
case ContentEntries.AccountPageContentTextContent:
return (
<section key={`${item.__typename}-${idx}`}>
<JsonToHtml
embeds={
item.text_content.content.embedded_itemsConnection.edges
}
nodes={item.text_content.content.json.children}
/>
</section>
)
default:
return null
}
})}
</>
)
}