Files
web/components/Loyalty/Sidebar/index.tsx
Michael Zetterberg bc84122a40 fix(SW-236): properly handle expired token in webviews
Trying out a new pattern for errors in data fetching.

Next.js is not a fan of throwing errors. Instead it recommends returning
different shapes for each state. Ref:
https://nextjs.org/docs/app/building-your-application/routing/error-handling#handling-expected-errors-from-server-components

It requires some more detailing and a bit more refactoring in non webview part,
but it is a start. This webview specific implementation should not break web.
2024-08-13 16:54:33 +02:00

63 lines
1.9 KiB
TypeScript

import JsonToHtml from "@/components/JsonToHtml"
import SidebarMyPages from "@/components/MyPages/Sidebar"
import JoinLoyaltyContact from "./JoinLoyalty"
import styles from "./sidebar.module.css"
import {
LoyaltySidebarDynamicComponentEnum,
SidebarTypenameEnum,
} from "@/types/components/loyalty/enums"
import { SidebarProps } from "@/types/components/loyalty/sidebar"
import { LangParams } from "@/types/params"
export default function SidebarLoyalty({
blocks,
lang,
}: SidebarProps & LangParams) {
return (
<aside className={styles.aside}>
{blocks.map((block, idx) => {
switch (block.__typename) {
case SidebarTypenameEnum.LoyaltyPageSidebarContent:
return (
<section
className={styles.content}
key={`${block.__typename}-${idx}`}
>
<JsonToHtml
embeds={block.content.content.embedded_itemsConnection.edges}
nodes={block.content.content.json.children}
/>
</section>
)
case SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact:
return (
<JoinLoyaltyContact
block={block.join_loyalty_contact}
key={`${block.__typename}-${idx}`}
lang={lang}
/>
)
case SidebarTypenameEnum.LoyaltyPageSidebarDynamicContent:
switch (block.dynamic_content.component) {
case LoyaltySidebarDynamicComponentEnum.my_pages_navigation:
return (
<SidebarMyPages
key={`${block.__typename}-${idx}`}
lang={lang}
/>
)
default:
return null
}
default:
return null
}
})}
</aside>
)
}