feat: add my benefits page
This commit is contained in:
32
app/[lang]/(live)/(protected)/my-pages/benefits/page.tsx
Normal file
32
app/[lang]/(live)/(protected)/my-pages/benefits/page.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
import Title from "@/components/MyPages/Title"
|
||||
import { request } from "@/lib/graphql/request"
|
||||
import GetBenefitsPage from "@/lib/graphql/Query/BenefitPage.graphql"
|
||||
import type { GetBenefitsPageData } from "@/types/requests/benefitPage"
|
||||
import { LangParams, PageArgs } from "@/types/params"
|
||||
import { serverClient } from "@/lib/trpc/server"
|
||||
|
||||
export default async function BenefitsPage({ params }: PageArgs<LangParams>) {
|
||||
const contentResponse = await request<GetBenefitsPageData>(GetBenefitsPage, {
|
||||
locale: params.lang,
|
||||
url: "/my-pages/benefits",
|
||||
})
|
||||
|
||||
const benefitsData = await serverClient().user.get()
|
||||
|
||||
if (!contentResponse.data.all_my_page?.total) {
|
||||
console.log("#### DATA ####")
|
||||
console.log(contentResponse.data)
|
||||
throw new Error("Not found")
|
||||
}
|
||||
|
||||
const contentData = contentResponse.data.all_my_page.items[0]
|
||||
|
||||
return (
|
||||
<main>
|
||||
<div>
|
||||
<Title>{contentData.title}</Title>
|
||||
</div>
|
||||
Benefits!
|
||||
</main>
|
||||
)
|
||||
}
|
||||
62
lib/graphql/Query/BenefitPage.graphql
Normal file
62
lib/graphql/Query/BenefitPage.graphql
Normal file
@@ -0,0 +1,62 @@
|
||||
#import "../Fragments/Image.graphql"
|
||||
fragment Preamble on MyPage {
|
||||
preamble {
|
||||
text {
|
||||
json
|
||||
embedded_itemsConnection(limit: 30) {
|
||||
edges {
|
||||
node {
|
||||
__typename
|
||||
...Image
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fragment Breadcrumbs on MyPage {
|
||||
breadcrumbs {
|
||||
parents {
|
||||
href
|
||||
title
|
||||
}
|
||||
title
|
||||
}
|
||||
}
|
||||
|
||||
query GetBenefitsPage($locale: String!, $url: String!) {
|
||||
all_my_page(where: { code_defined_route: $url, locale: $locale }) {
|
||||
items {
|
||||
blocks {
|
||||
... on MyPageBlocksShortcuts {
|
||||
__typename
|
||||
shortcuts {
|
||||
external_link {
|
||||
href
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
... on MyPageBlocksNextLevelBlock {
|
||||
__typename
|
||||
next_level_block {
|
||||
subtitle
|
||||
title
|
||||
}
|
||||
}
|
||||
... on MyPageBlocksPersonalBenefitsBlock {
|
||||
__typename
|
||||
personal_benefits_block {
|
||||
is_visible
|
||||
}
|
||||
}
|
||||
}
|
||||
...Breadcrumbs
|
||||
...Preamble
|
||||
title
|
||||
url
|
||||
}
|
||||
total
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@
|
||||
#import "../Fragments/Blocks/List.graphql"
|
||||
#import "../Fragments/Blocks/Puff.graphql"
|
||||
#import "../Fragments/Blocks/Text.graphql"
|
||||
#import "../Fragments/Breadcrumbs.graphql"
|
||||
#import "../Fragments/CurrentBlocksPage/Breadcrumbs.graphql"
|
||||
#import "../Fragments/Hero.graphql"
|
||||
#import "../Fragments/Preamble.graphql"
|
||||
#import "../Fragments/CurrentBlocksPage/Preamble.graphql"
|
||||
|
||||
query GetCurrentBlockPage($locale: String!, $url: String!) {
|
||||
all_current_blocks_page(limit: 1, locale: $locale, where: { url: $url }) {
|
||||
|
||||
@@ -66,6 +66,26 @@ const nextConfig = {
|
||||
{ source: profile.fi, destination: "/fi/my-pages/profile" },
|
||||
{ source: profile.no, destination: "/no/my-pages/profile" },
|
||||
{ source: profile.sv, destination: "/sv/my-pages/profile" },
|
||||
{
|
||||
source: `/da/${benefitsPageNames.da}`,
|
||||
destination: "/da/my-pages/benefits",
|
||||
},
|
||||
{
|
||||
source: `/de/${benefitsPageNames.de}`,
|
||||
destination: "/de/my-pages/benefits",
|
||||
},
|
||||
{
|
||||
source: `/fi/${benefitsPageNames.fi}`,
|
||||
destination: "/fi/my-pages/benefits",
|
||||
},
|
||||
{
|
||||
source: `/no/${benefitsPageNames.no}`,
|
||||
destination: "/no/my-pages/benefits",
|
||||
},
|
||||
{
|
||||
source: `/sv/${benefitsPageNames.sv}`,
|
||||
destination: "/sv/my-pages/benefits",
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
|
||||
57
types/requests/benefitPage.ts
Normal file
57
types/requests/benefitPage.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { Preamble } from "./preamble"
|
||||
import type { AllRequestResponse } from "./utils/all"
|
||||
import type { MyPageBlocksEnum, Typename } from "./utils/typename"
|
||||
|
||||
type Shortcuts = {
|
||||
title: string
|
||||
subtitle: string
|
||||
external_link: {
|
||||
href: string
|
||||
title: string
|
||||
}
|
||||
}
|
||||
|
||||
type PersonalBenefitsBlock = {
|
||||
is_visible: boolean
|
||||
}
|
||||
|
||||
type NextLevelBlock = {
|
||||
title: string
|
||||
subtitle: string
|
||||
}
|
||||
|
||||
export type Blocks =
|
||||
| Typename<NextLevelBlock, MyPageBlocksEnum.MyPageBlocksNextLevelBlock>
|
||||
| Typename<
|
||||
PersonalBenefitsBlock,
|
||||
MyPageBlocksEnum.MyPageBlocksPersonalBenefitsBlock
|
||||
>
|
||||
| Typename<Shortcuts, MyPageBlocksEnum.MyPageBlocksShortcuts>
|
||||
|
||||
export type Breadcrumb = {
|
||||
href: string
|
||||
title: string
|
||||
}
|
||||
|
||||
export type Breadcrumbs = {
|
||||
parents: Breadcrumb[]
|
||||
title: string
|
||||
}
|
||||
|
||||
export type BenefitPage = {
|
||||
content: Blocks[]
|
||||
breadcrumbs: Breadcrumbs
|
||||
code_defined_route: string
|
||||
preamble: Preamble
|
||||
system: {
|
||||
created_at: string
|
||||
uid: string
|
||||
updated_at: string
|
||||
}
|
||||
title: string
|
||||
url: string
|
||||
}
|
||||
|
||||
export type GetBenefitsPageData = {
|
||||
all_my_page: AllRequestResponse<BenefitPage>
|
||||
}
|
||||
@@ -16,3 +16,10 @@ export type BlocksTypename = keyof typeof BlocksTypenameEnum
|
||||
export type Typename<T, K> = T & {
|
||||
__typename: K
|
||||
}
|
||||
|
||||
export enum MyPageBlocksEnum {
|
||||
MyPageBlocksNextLevelBlock = "MyPageBlocksNextLevelBlock",
|
||||
MyPageBlocksPersonalBenefitsBlock = "MyPageBlocksPersonalBenefitsBlock",
|
||||
MyPageBlocksShortcuts = "MyPageBlocksShortcuts",
|
||||
}
|
||||
export type MyPageBlocksTypename = keyof typeof MyPageBlocksEnum
|
||||
|
||||
Reference in New Issue
Block a user