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
+48
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>
}
+33 -30
View File
@@ -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<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 =
| Typename<SidebarContent, SidebarTypenameEnum.LoyaltyPageSidebarContent>
| 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<ContentPageLink, LinkedPageConnection.ContentPage>
| Typename<LoyaltyPageLink, ContentBlocks.LoyaltyPageContentLoyaltyLevels>
| Typename<AccountPageLink, ContentBlocks.LoyaltyPageContentLoyaltyLevels>
type CardGrid = {
card_grid: {
heading: string
subheading: string
cards: {
referenceConnection: {
edges: {
node: LinkedPage
}
}
referenceConnection: Edges<PageLink>
heading: string
subheading: string
}