Open luca-smartpricing opened 3 months ago
I have the same problem. This is how I solved my use-case:
import {
FieldGroup as BaseFieldGroup,
FormDefinitionBaseFormTypeEnum,
FormDisplayOptions,
HubSpotFormConfiguration,
} from '@hubspot/api-client/lib/codegen/marketing/forms'
export enum FieldType {
SingleLineText = 'single_line_text',
Email = 'email',
Phone = 'phone',
Number = 'number',
MultiLineText = 'multi_line_text',
Dropdown = 'dropdown',
SingleCheckbox = 'single_checkbox',
Radio = 'radio',
MultipleCheckboxes = 'multiple_checkboxes',
}
export type Field = Omit<BaseFieldGroup['fields'][0], 'fieldType'> & {
fieldType: FieldType
}
export type FieldGroup = Omit<BaseFieldGroup, 'fields'> & { fields: Field[] }
export type FormDefinition = {
formType: FormDefinitionBaseFormTypeEnum
id: string
name: string
createdAt: Date
updatedAt: Date
archived: boolean
archivedAt?: Date
fieldGroups: Array<FieldGroup>
configuration: HubSpotFormConfiguration
displayOptions: FormDisplayOptions
legalConsentOptions: any
[key: string]: any // <<<<< fix for Remix unstable_defineLoader types
}
export async function getForm(formId: string) {
try {
const res = await fetch(`https://api.hubapi.com/marketing/v3/forms/${formId}`, {
cache: 'no-cache',
headers: {
Authorization: `Bearer ${HUBSPOT_ACCESS_TOKEN}`,
},
})
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`)
const data = (await res.json()) as FormDefinition
console.log('getForm', JSON.stringify(data, null, 2))
return data
} catch (error) {
if (error instanceof Error) {
console.error(error)
throw new Error(error.message)
} else {
console.error(error)
throw new Error('An unknown error occurred.')
}
}
}
In
FieldGroup.ts
the fields key isfields': Array<DependentFieldDependentField>
. Ok, but if i openDependentFieldDependentField.ts
i can found only one fieldTypefieldType: DependentFieldDependentFieldFieldTypeEnum
As you see fieldType has only one type: payment_link_radio.Where are the other FieldTypeEnum such as
I think it's a typing error