Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type: DependentFieldDependentField #488

Open
luca-smartpricing opened this issue Jun 3, 2024 · 1 comment
Open

Type: DependentFieldDependentField #488

luca-smartpricing opened this issue Jun 3, 2024 · 1 comment

Comments

@luca-smartpricing
Copy link

In FieldGroup.ts the fields key is fields': Array<DependentFieldDependentField>. Ok, but if i open DependentFieldDependentField.ts i can found only one fieldType fieldType: DependentFieldDependentFieldFieldTypeEnum
As you see fieldType has only one type: payment_link_radio.

declare enum DependentFieldDependentFieldFieldTypeEnum {
    PaymentLinkRadio = "payment_link_radio"
}

Where are the other FieldTypeEnum such as

  • number
  • phone
  • single_checkbox

I think it's a typing error

Screenshot 2024-06-03 alle 17 55 37
@BojanHribernik
Copy link

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.')
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants