74 lines
1.6 KiB
TypeScript
74 lines
1.6 KiB
TypeScript
import { AllRequestResponse } from "./utils/all"
|
|
|
|
export type ContactConfig = {
|
|
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
|
|
name?: string
|
|
}
|
|
phone_loyalty: {
|
|
number?: string
|
|
name?: string
|
|
}
|
|
visiting_address: {
|
|
zip?: string
|
|
country?: string
|
|
city?: string
|
|
street?: string
|
|
}
|
|
}
|
|
|
|
export enum ContactFieldGroupsEnum {
|
|
email = "email",
|
|
email_loyalty = "email_loyalty",
|
|
mailing_address = "mailing_address",
|
|
phone = "phone",
|
|
phone_loyalty = "phone_loyalty",
|
|
visiting_address = "visiting_address",
|
|
}
|
|
|
|
export type ContactFieldGroups = keyof typeof ContactFieldGroupsEnum
|
|
|
|
export type GetContactConfigData = {
|
|
all_contact_config: AllRequestResponse<ContactConfig>
|
|
}
|
|
|
|
// Utility types that extract the possible strings of ContactConfigField,
|
|
// Which is all the dot notated values of ContactConfig (for example: 'email.name')
|
|
type PathsToStringProps<T> = T extends string
|
|
? []
|
|
: {
|
|
[K in Extract<keyof T, string>]: [K, ...PathsToStringProps<T[K]>]
|
|
}[Extract<keyof T, string>]
|
|
|
|
type Join<T extends string[], D extends string> = T extends []
|
|
? never
|
|
: T extends [infer F]
|
|
? F
|
|
: T extends [infer F, ...infer R]
|
|
? F extends string
|
|
? `${F}${D}${Join<Extract<R, string[]>, D>}`
|
|
: never
|
|
: string
|
|
|
|
type ContactConfigField = Join<PathsToStringProps<ContactConfig>, ".">
|
|
|
|
export type ContactFields = {
|
|
display_text?: string
|
|
contact_field: ContactConfigField
|
|
}
|