feat: create blocks component for loyalty

This commit is contained in:
Christel Westerberg
2024-04-22 09:54:24 +02:00
parent 3a0c8610dc
commit fc0e5aed02
17 changed files with 193 additions and 149 deletions

View File

@@ -1,12 +1,13 @@
import Title from "@/components/Title"
import MaxWidth from "@/components/MaxWidth"
import { serverClient } from "@/lib/trpc/server"
import { LangParams, PageArgs, UriParams } from "@/types/params"
import { notFound } from "next/navigation" import { notFound } from "next/navigation"
import { serverClient } from "@/lib/trpc/server"
import MaxWidth from "@/components/MaxWidth"
import Sidebar from "@/components/Loyalty/Sidebar"
import { Blocks } from "@/components/Loyalty/Blocks"
import type { LangParams, PageArgs, UriParams } from "@/types/params"
import styles from "./page.module.css" import styles from "./page.module.css"
import Sidebar from "@/components/Loyalty/Sidebar"
export default async function LoyaltyPage({ export default async function LoyaltyPage({
params, params,
@@ -32,8 +33,7 @@ export default async function LoyaltyPage({
: null} : null}
</aside> </aside>
<section className={styles.blocks}> <section className={styles.blocks}>
<Title as="h3">{loyaltyPage.title}</Title> <Blocks blocks={loyaltyPage.blocks} />
<Content content={loyaltyPage.content} />
</section> </section>
</MaxWidth> </MaxWidth>
) )
@@ -41,7 +41,3 @@ export default async function LoyaltyPage({
return notFound() return notFound()
} }
} }
function Content(content: any) {
return <></>
}

View File

@@ -0,0 +1,26 @@
import JsonToHtml from "@/components/JsonToHtml"
import {
Blocks as BlocksType,
LoyaltyBlocksTypenameEnum,
} from "@/types/requests/loyaltyPage"
export function Blocks({ blocks }: { blocks: BlocksType[] }) {
return blocks.map((block) => {
switch (block.__typename) {
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksCardGrid:
return <p>Cards</p>
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent:
return (
<JsonToHtml
nodes={block.content.json.children}
embeds={block.content.embedded_itemsConnection.edges}
/>
)
case LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent:
return <p>Dynamic</p>
default:
return null
}
})
}

View File

@@ -1,12 +1,13 @@
import Title from "@/components/Title" import Title from "@/components/Title"
import JsonToHtml from "@/components/JsonToHtml" import Contact from "./Contact"
import Button from "@/components/TempDesignSystem/Button" import Button from "@/components/TempDesignSystem/Button"
import Link from "@/components/TempDesignSystem/Link" import Link from "@/components/TempDesignSystem/Link"
import Image from "@/components/Image"
import styles from "./joinLoyalty.module.css"
import type { JoinLoyaltyContact } from "@/types/requests/loyaltyPage" import type { JoinLoyaltyContact } from "@/types/requests/loyaltyPage"
import styles from "./joinLoyalty.module.css"
export default function JoinLoyaltyContact({ export default function JoinLoyaltyContact({
block, block,
}: { }: {
@@ -15,10 +16,15 @@ export default function JoinLoyaltyContact({
return ( return (
<div className={styles.container}> <div className={styles.container}>
<div className={styles.wrapper}> <div className={styles.wrapper}>
<JsonToHtml {block.title && <Title level="h3">{block.title}</Title>}
embeds={block.body.embedded_itemsConnection.edges} <Image
nodes={block.body.json.children} alt="Scandic Friends"
className={styles.image}
height={65}
src="/_static/icons/scandic-friends.png"
width={203}
/> />
{block.preamble && <p className={styles.preamble}>{block.preamble}</p>}
<Button intent="primary"> <Button intent="primary">
<span>{block.login_button_text}</span> <span>{block.login_button_text}</span>
</Button> </Button>
@@ -29,9 +35,11 @@ export default function JoinLoyaltyContact({
</Link> </Link>
</div> </div>
</div> </div>
<section className={styles.contactContainer}> {block.contact
<Title level="h5">Contact</Title> ? block.contact.map((contact, i) => (
</section> <Contact key={i} contactFields={contact.contact.contact_fields} />
))
: null}
</div> </div>
) )
} }

View File

@@ -13,6 +13,15 @@
padding: 4rem 2rem; padding: 4rem 2rem;
} }
.preamble {
font-family: var(--fira-sans);
font-size: 1.6rem;
font-weight: 400;
line-height: 2.4rem;
text-align: center;
margin: 0;
}
.logoutLink { .logoutLink {
text-decoration: none; text-decoration: none;
color: var(--some-black-color, #2e2e2e); color: var(--some-black-color, #2e2e2e);

View File

@@ -3,8 +3,8 @@ import { serverClient } from "@/lib/trpc/server"
import StayCard from "@/components/MyPages/Blocks/Stays/StayCard" import StayCard from "@/components/MyPages/Blocks/Stays/StayCard"
import EmptyUpcomingStaysBlock from "@/components/MyPages/Blocks/Stays/Upcoming/EmptyUpcomingStays" import EmptyUpcomingStaysBlock from "@/components/MyPages/Blocks/Stays/Upcoming/EmptyUpcomingStays"
import Title from "@/components/MyPages/Title"
import Link from "@/components/TempDesignSystem/Link" import Link from "@/components/TempDesignSystem/Link"
import Title from "@/components/Title"
import styles from "./upcoming.module.css" import styles from "./upcoming.module.css"

View File

@@ -1,4 +1,4 @@
import Title from "@/components/MyPages/Title" import Title from "@/components/Title"
import styles from "./header.module.css" import styles from "./header.module.css"

View File

@@ -1,6 +1,6 @@
import { _ } from "@/lib/translation" import { _ } from "@/lib/translation"
import Title from "@/components/MyPages/Title" import Title from "@/components/Title"
import styles from "./emptyPreviousStays.module.css" import styles from "./emptyPreviousStays.module.css"

View File

@@ -2,8 +2,8 @@ import Link from "next/link"
import { _ } from "@/lib/translation" import { _ } from "@/lib/translation"
import Title from "@/components/MyPages/Title"
import Button from "@/components/TempDesignSystem/Button" import Button from "@/components/TempDesignSystem/Button"
import Title from "@/components/Title"
import styles from "./emptyUpcomingStays.module.css" import styles from "./emptyUpcomingStays.module.css"

View File

@@ -0,0 +1,8 @@
fragment AccountPageLink on AccountPage {
system {
locale
uid
}
title
url
}

View File

@@ -0,0 +1,8 @@
fragment ContentPageLink on ContentPage {
system {
locale
uid
}
url
title
}

View File

@@ -0,0 +1,8 @@
fragment CurrentBlocksPageLink on CurrentBlocksPage {
system {
locale
uid
}
title
url
}

View File

@@ -0,0 +1,8 @@
fragment LoyaltyPageLink on LoyaltyPage {
system {
locale
uid
}
title
url
}

View File

@@ -1,35 +0,0 @@
fragment CurrentBlocksPageLink on CurrentBlocksPage {
system {
locale
uid
}
title
url
}
fragment AccountPageLink on AccountPage {
system {
locale
uid
}
title
url
}
fragment LoyaltyPageLink on LoyaltyPage {
system {
locale
uid
}
title
url
}
fragment ContentPageLink on ContentPage {
system {
locale
uid
}
url
title
}

View File

@@ -1,57 +1,71 @@
#import "../Fragments/Image.graphql" #import "../Fragments/Image.graphql"
#import "../Fragments/PageLink/AccountPageLink.graphql"
#import "../Fragments/PageLink/ContentPageLink.graphql"
#import "../Fragments/PageLink/LoyaltyPageLink.graphql"
query GetLoyaltyPage($locale: String!, $url: String!) { query GetLoyaltyPage($locale: String!, $url: String!) {
all_loyalty_page(where: { url: $url, locale: $locale }) { all_loyalty_page(where: { url: $url, locale: $locale }) {
items { items {
content { blocks {
... on LoyaltyPageContentLoyaltyLevels { ... on LoyaltyPageBlocksDynamicContent {
__typename __typename
loyalty_levels { dynamic_content {
heading title
sub_heading preamble
level_card { component
loyalty_level link {
text
pageConnection {
edges {
node {
...ContentPageLink
...LoyaltyPageLink
} }
} }
} }
... on LoyaltyPageContentCardGrid { }
}
}
... on LoyaltyPageBlocksCardGrid {
__typename __typename
card_grid { card_grid {
heading heading
subheading preamble
cards { cards {
referenceConnection { referenceConnection {
edges { edges {
node { node {
... on LoyaltyPage { __typename
system { ...LoyaltyPageLink
locale ...ContentPageLink
uid ...AccountPageLink
}
url
title
}
... on ContentPage {
system {
locale
uid
}
url
title
}
... on AccountPage {
system {
locale
uid
}
url
title
}
} }
} }
} }
heading heading
subheading preamble
}
}
}
... on LoyaltyPageBlocksContent {
__typename
content {
content {
json
embedded_itemsConnection {
edges {
node {
... on SysAsset {
title
url
dimension {
width
height
}
}
}
}
}
} }
} }
} }
@@ -62,6 +76,7 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
__typename __typename
join_loyalty_contact { join_loyalty_contact {
title title
preamble
contact { contact {
... on LoyaltyPageSidebarJoinLoyaltyContactBlockContactContact { ... on LoyaltyPageSidebarJoinLoyaltyContactBlockContactContact {
__typename __typename
@@ -71,17 +86,6 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
} }
} }
login_button_text login_button_text
body {
json
embedded_itemsConnection(limit: 30) {
edges {
node {
__typename
...Image
}
}
}
}
} }
} }
... on LoyaltyPageSidebarContent { ... on LoyaltyPageSidebarContent {
@@ -92,6 +96,7 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
embedded_itemsConnection { embedded_itemsConnection {
edges { edges {
node { node {
__typename
...Image ...Image
} }
} }
@@ -108,24 +113,6 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
title title
} }
} }
seo_metadata {
description
title
imageConnection {
edges {
node {
file_size
filename
dimension {
height
width
}
url
title
}
}
}
}
} }
system { system {
uid uid

View File

@@ -1,4 +1,6 @@
#import "../Fragments/PageLinks.graphql" #import "../Fragments/PageLink/AccountPageLink.graphql"
#import "../Fragments/PageLink/ContentPageLink.graphql"
#import "../Fragments/PageLink/LoyaltyPageLink.graphql"
query GetNavigationMyPages($locale: String!) { query GetNavigationMyPages($locale: String!) {
all_navigation_my_pages(locale: $locale) { all_navigation_my_pages(locale: $locale) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

View File

@@ -26,18 +26,21 @@ type Contact = {
} }
} }
enum JoinLoyaltyContactTypenameEnum {
LoyaltyPageSidebarJoinLoyaltyContactBlockContactContact = "LoyaltyPageSidebarJoinLoyaltyContactBlockContactContact",
}
type JoinLoyaltyContactEnum = Typename<
Contact,
JoinLoyaltyContactTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContactBlockContactContact
>
export type JoinLoyaltyContact = { export type JoinLoyaltyContact = {
join_loyalty_contact: { join_loyalty_contact: {
title: string title?: string
contact: Typename< preamble?: string
Contact, contact: JoinLoyaltyContactEnum[]
"LoyaltyPageSidebarLoyaltyJoinContactBlockContactContact"
>
login_button_text: string login_button_text: string
body: {
embedded_itemsConnection: Edges<Embeds>
json: RTEDocument
}
} }
} }
@@ -48,36 +51,52 @@ export type Sidebar =
SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact SidebarTypenameEnum.LoyaltyPageSidebarJoinLoyaltyContact
> >
enum ContentBlocks { export enum LoyaltyBlocksTypenameEnum {
LoyaltyPageContentLoyaltyLevels = "LoyaltyPageContentLoyaltyLevels", LoyaltyPageBlocksDynamicContent = "LoyaltyPageBlocksDynamicContent",
LoyaltyPageContentCardGrid = "LoyaltyPageContentCardGrid", LoyaltyPageBlocksCardGrid = "LoyaltyPageBlocksCardGrid",
LoyaltyPageBlocksContent = "LoyaltyPageBlocksContent",
} }
type CardGrid = { type CardGrid = {
card_grid: { card_grid: {
heading: string heading: string
subheading: string preamble: string
cards: { cards: {
referenceConnection: Edges<PageLink> referenceConnection: Edges<PageLink>
heading: string heading: string
subheading: string preamble: string
} }
} }
} }
type LoyaltyLevels = { type Content = {
loyalty_levels: { content: {
heading: string embedded_itemsConnection: Edges<Embeds>
sub_heading?: string json: RTEDocument
level_card: {
loyalty_level: number
}[]
} }
} }
export type Content = type LoyaltyComponent = "loyalty_levels" | "how_it_works" | "overview_table"
| Typename<CardGrid, ContentBlocks.LoyaltyPageContentCardGrid>
| Typename<LoyaltyLevels, ContentBlocks.LoyaltyPageContentLoyaltyLevels> type DynamicContent = {
dynamic_content: {
title: string
preamble?: string
component: LoyaltyComponent
link: {
text?: string
page: Edges<PageLink>
}
}
}
export type Blocks =
| Typename<CardGrid, LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksCardGrid>
| Typename<
DynamicContent,
LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksDynamicContent
>
| Typename<Content, LoyaltyBlocksTypenameEnum.LoyaltyPageBlocksContent>
export type Breadcrumb = { export type Breadcrumb = {
href: string href: string
@@ -91,7 +110,7 @@ export type Breadcrumbs = {
export type LoyaltyPage = { export type LoyaltyPage = {
sidebar: Sidebar[] sidebar: Sidebar[]
content: Content[] blocks: Blocks[]
web: { web: {
breadcrumbs: Breadcrumbs breadcrumbs: Breadcrumbs
} }