From b57665ce6237218b7ee3e23b96b749b070e4a86c Mon Sep 17 00:00:00 2001 From: Christel Westerberg Date: Thu, 18 Apr 2024 11:44:52 +0200 Subject: [PATCH] fix: typings for contactConfig --- lib/graphql/Query/LoyaltyPage.graphql | 17 +++++++- middlewares/cmsContent.ts | 16 ++++--- types/requests/contactConfig.ts | 48 ++++++++++++++++++++ types/requests/loyaltyPage.ts | 63 ++++++++++++++------------- 4 files changed, 106 insertions(+), 38 deletions(-) create mode 100644 types/requests/contactConfig.ts diff --git a/lib/graphql/Query/LoyaltyPage.graphql b/lib/graphql/Query/LoyaltyPage.graphql index 5cfb1d59b..e8f884fbc 100644 --- a/lib/graphql/Query/LoyaltyPage.graphql +++ b/lib/graphql/Query/LoyaltyPage.graphql @@ -22,15 +22,28 @@ query GetLoyaltyPage($locale: String!, $url: String!) { edges { node { ... on LoyaltyPage { + system { + locale + uid + } url + title } ... on ContentPage { - web { - url + system { + locale + uid } + url + title } ... on AccountPage { + system { + locale + uid + } url + title } } } diff --git a/middlewares/cmsContent.ts b/middlewares/cmsContent.ts index 097322576..183e4a2f5 100644 --- a/middlewares/cmsContent.ts +++ b/middlewares/cmsContent.ts @@ -10,7 +10,7 @@ export const middleware: NextMiddleware = async (request) => { const { nextUrl } = request const lang = findLang(nextUrl.pathname) - const contentType = "currentContentPage" + const contentType = "loyaltyPage" const pathNameWithoutLang = nextUrl.pathname.replace(`/${lang}`, "") const searchParams = new URLSearchParams(request.nextUrl.searchParams) @@ -23,12 +23,16 @@ export const middleware: NextMiddleware = async (request) => { searchParams.set("uri", pathNameWithoutLang) switch (contentType) { - case "currentContentPage": + // case "currentContentPage": + // return NextResponse.rewrite( + // new URL( + // `/${lang}/current-content-page?${searchParams.toString()}`, + // nextUrl + // ) + // ) + case "loyaltyPage": return NextResponse.rewrite( - new URL( - `/${lang}/current-content-page?${searchParams.toString()}`, - nextUrl - ) + new URL(`/${lang}/loyalty-page?${searchParams.toString()}`, nextUrl) ) default: return NextResponse.next() diff --git a/types/requests/contactConfig.ts b/types/requests/contactConfig.ts new file mode 100644 index 000000000..ba34c2b0e --- /dev/null +++ b/types/requests/contactConfig.ts @@ -0,0 +1,48 @@ +import { AllRequestResponse } from "./utils/all" + +export type ContactConfig = { + items: [ + { + email: { + name: string + address: string + } + email_loyalty: { + name: string + address: string + } + mailing_address: { + zip: string + street: string + name: string + city: string + country: string + } + phone: { + number: string + naem: string + } + phone_loyalty: { + number: string + name: string + } + visiting_address: { + zip: string + country: string + city: string + street: string + } + }, + ] +} +type FlattenKeys = T extends object + ? { + [K in keyof T]-?: `${K & string}.${FlattenKeys}` + }[keyof T] + : "" + +export type ContactField = FlattenKeys + +export type GetContactConfigData = { + all_contact_config: AllRequestResponse +} diff --git a/types/requests/loyaltyPage.ts b/types/requests/loyaltyPage.ts index ea71c3813..6b04dd127 100644 --- a/types/requests/loyaltyPage.ts +++ b/types/requests/loyaltyPage.ts @@ -1,19 +1,48 @@ +import { PageLink } from "./myPages/navigation" import type { AllRequestResponse } from "./utils/all" import type { Typename } from "./utils/typename" +import { Edges } from "./utils/edges" +import type { RTEDocument } from "../rte/node" +import type { Embeds } from "./embeds" +import type { ContactField } from "./contactConfig" enum SidebarTypenameEnum { LoyaltyPageSidebarLoyaltyJoinContact = "LoyaltyPageSidebarLoyaltyJoinContact", LoyaltyPageSidebarContent = "LoyaltyPageSidebarContent", } -type SidebarContent = {} +type SidebarContent = { + content: { + embedded_itemsConnection: Edges + json: RTEDocument + } +} -type JoinContact = {} +type Contact = { + contact: { + contact_fields: ContactField[] + } +} + +type LoyaltyJoinContact = { + loyalty_join_contact: { + title: string + contact: Typename< + Contact, + "LoyaltyPageSidebarLoyaltyJoinContactBlockContactContact" + > + login_button_text: string + body: { + embedded_itemsConnection: Edges + json: RTEDocument + } + } +} export type Sidebar = | Typename | Typename< - JoinContact, + LoyaltyJoinContact, SidebarTypenameEnum.LoyaltyPageSidebarLoyaltyJoinContact > @@ -22,38 +51,12 @@ enum ContentBlocks { LoyaltyPageContentCardGrid = "LoyaltyPageContentCardGrid", } -enum LinkedPageConnection { - LoyaltyPage = "LoyaltyPage", - ContentPage = "ContentPage", - AccountPage = "AccountPage", -} - -type ContentPageLink = { - web: { url: string } -} -type LoyaltyPageLink = { - url: string -} - -type AccountPageLink = { - url: string -} - -type LinkedPage = - | Typename - | Typename - | Typename - type CardGrid = { card_grid: { heading: string subheading: string cards: { - referenceConnection: { - edges: { - node: LinkedPage - } - } + referenceConnection: Edges heading: string subheading: string }