fix: typings for contactConfig

This commit is contained in:
Christel Westerberg
2024-04-18 11:44:52 +02:00
parent c00f7b78eb
commit b57665ce62
4 changed files with 106 additions and 38 deletions

View File

@@ -22,15 +22,28 @@ query GetLoyaltyPage($locale: String!, $url: String!) {
edges { edges {
node { node {
... on LoyaltyPage { ... on LoyaltyPage {
system {
locale
uid
}
url url
title
} }
... on ContentPage { ... on ContentPage {
web { system {
url locale
uid
} }
url
title
} }
... on AccountPage { ... on AccountPage {
system {
locale
uid
}
url url
title
} }
} }
} }

View File

@@ -10,7 +10,7 @@ export const middleware: NextMiddleware = async (request) => {
const { nextUrl } = request const { nextUrl } = request
const lang = findLang(nextUrl.pathname) const lang = findLang(nextUrl.pathname)
const contentType = "currentContentPage" const contentType = "loyaltyPage"
const pathNameWithoutLang = nextUrl.pathname.replace(`/${lang}`, "") const pathNameWithoutLang = nextUrl.pathname.replace(`/${lang}`, "")
const searchParams = new URLSearchParams(request.nextUrl.searchParams) const searchParams = new URLSearchParams(request.nextUrl.searchParams)
@@ -23,12 +23,16 @@ export const middleware: NextMiddleware = async (request) => {
searchParams.set("uri", pathNameWithoutLang) searchParams.set("uri", pathNameWithoutLang)
switch (contentType) { switch (contentType) {
case "currentContentPage": // case "currentContentPage":
// return NextResponse.rewrite(
// new URL(
// `/${lang}/current-content-page?${searchParams.toString()}`,
// nextUrl
// )
// )
case "loyaltyPage":
return NextResponse.rewrite( return NextResponse.rewrite(
new URL( new URL(`/${lang}/loyalty-page?${searchParams.toString()}`, nextUrl)
`/${lang}/current-content-page?${searchParams.toString()}`,
nextUrl
)
) )
default: default:
return NextResponse.next() return NextResponse.next()

View File

@@ -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> = T extends object
? {
[K in keyof T]-?: `${K & string}.${FlattenKeys<T[K]>}`
}[keyof T]
: ""
export type ContactField = FlattenKeys<ContactConfig["items"][0]>
export type GetContactConfigData = {
all_contact_config: AllRequestResponse<ContactConfig>
}

View File

@@ -1,19 +1,48 @@
import { PageLink } from "./myPages/navigation"
import type { AllRequestResponse } from "./utils/all" import type { AllRequestResponse } from "./utils/all"
import type { Typename } from "./utils/typename" 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 { enum SidebarTypenameEnum {
LoyaltyPageSidebarLoyaltyJoinContact = "LoyaltyPageSidebarLoyaltyJoinContact", LoyaltyPageSidebarLoyaltyJoinContact = "LoyaltyPageSidebarLoyaltyJoinContact",
LoyaltyPageSidebarContent = "LoyaltyPageSidebarContent", LoyaltyPageSidebarContent = "LoyaltyPageSidebarContent",
} }
type SidebarContent = {} type SidebarContent = {
content: {
embedded_itemsConnection: Edges<Embeds>
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<Embeds>
json: RTEDocument
}
}
}
export type Sidebar = export type Sidebar =
| Typename<SidebarContent, SidebarTypenameEnum.LoyaltyPageSidebarContent> | Typename<SidebarContent, SidebarTypenameEnum.LoyaltyPageSidebarContent>
| Typename< | Typename<
JoinContact, LoyaltyJoinContact,
SidebarTypenameEnum.LoyaltyPageSidebarLoyaltyJoinContact SidebarTypenameEnum.LoyaltyPageSidebarLoyaltyJoinContact
> >
@@ -22,38 +51,12 @@ enum ContentBlocks {
LoyaltyPageContentCardGrid = "LoyaltyPageContentCardGrid", 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<ContentPageLink, LinkedPageConnection.ContentPage>
| Typename<LoyaltyPageLink, ContentBlocks.LoyaltyPageContentLoyaltyLevels>
| Typename<AccountPageLink, ContentBlocks.LoyaltyPageContentLoyaltyLevels>
type CardGrid = { type CardGrid = {
card_grid: { card_grid: {
heading: string heading: string
subheading: string subheading: string
cards: { cards: {
referenceConnection: { referenceConnection: Edges<PageLink>
edges: {
node: LinkedPage
}
}
heading: string heading: string
subheading: string subheading: string
} }