diff --git a/app/[lang]/(live)/(protected)/my-pages/benefits/benefits.module.css b/app/[lang]/(live)/(protected)/my-pages/benefits/benefits.module.css new file mode 100644 index 000000000..e69de29bb diff --git a/app/[lang]/(live)/(protected)/my-pages/benefits/page.tsx b/app/[lang]/(live)/(protected)/my-pages/benefits/page.tsx new file mode 100644 index 000000000..bfbc7be34 --- /dev/null +++ b/app/[lang]/(live)/(protected)/my-pages/benefits/page.tsx @@ -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) { + const contentResponse = await request(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 ( +
+
+ {contentData.title} +
+ Benefits! +
+ ) +} diff --git a/lib/graphql/Fragments/Breadcrumbs.graphql b/lib/graphql/Fragments/CurrentBlocksPage/Breadcrumbs.graphql similarity index 100% rename from lib/graphql/Fragments/Breadcrumbs.graphql rename to lib/graphql/Fragments/CurrentBlocksPage/Breadcrumbs.graphql diff --git a/lib/graphql/Fragments/PageLinks.graphql b/lib/graphql/Fragments/CurrentBlocksPage/PageLinks.graphql similarity index 100% rename from lib/graphql/Fragments/PageLinks.graphql rename to lib/graphql/Fragments/CurrentBlocksPage/PageLinks.graphql diff --git a/lib/graphql/Fragments/Preamble.graphql b/lib/graphql/Fragments/CurrentBlocksPage/Preamble.graphql similarity index 100% rename from lib/graphql/Fragments/Preamble.graphql rename to lib/graphql/Fragments/CurrentBlocksPage/Preamble.graphql diff --git a/lib/graphql/Query/BenefitPage.graphql b/lib/graphql/Query/BenefitPage.graphql new file mode 100644 index 000000000..6e666be1a --- /dev/null +++ b/lib/graphql/Query/BenefitPage.graphql @@ -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 + } +} diff --git a/lib/graphql/Query/CurrentBlockPage.graphql b/lib/graphql/Query/CurrentBlockPage.graphql index b275b328f..dcab7ed98 100644 --- a/lib/graphql/Query/CurrentBlockPage.graphql +++ b/lib/graphql/Query/CurrentBlockPage.graphql @@ -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 }) { diff --git a/next.config.js b/next.config.js index 2ee608830..a44696790 100644 --- a/next.config.js +++ b/next.config.js @@ -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", + }, ], } }, diff --git a/types/requests/benefitPage.ts b/types/requests/benefitPage.ts new file mode 100644 index 000000000..713d1ef69 --- /dev/null +++ b/types/requests/benefitPage.ts @@ -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 + | Typename< + PersonalBenefitsBlock, + MyPageBlocksEnum.MyPageBlocksPersonalBenefitsBlock + > + | Typename + +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 +} diff --git a/types/requests/utils/typename.ts b/types/requests/utils/typename.ts index 5c59848bf..10840abf6 100644 --- a/types/requests/utils/typename.ts +++ b/types/requests/utils/typename.ts @@ -16,3 +16,10 @@ export type BlocksTypename = keyof typeof BlocksTypenameEnum export type Typename = T & { __typename: K } + +export enum MyPageBlocksEnum { + MyPageBlocksNextLevelBlock = "MyPageBlocksNextLevelBlock", + MyPageBlocksPersonalBenefitsBlock = "MyPageBlocksPersonalBenefitsBlock", + MyPageBlocksShortcuts = "MyPageBlocksShortcuts", +} +export type MyPageBlocksTypename = keyof typeof MyPageBlocksEnum