@hashicorp/react-components 1.1.8 → 1.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/package.json +4 -8
  2. package/src/components/nav-panel/components/flight-icon/index.tsx +51 -0
  3. package/src/components/nav-panel/components/flight-icon/style.module.css +3 -0
  4. package/src/components/nav-panel/components/link-list/index.tsx +15 -9
  5. package/src/components/nav-panel/components/link-list/style.module.css +10 -10
  6. package/src/components/nav-panel/components/panel/column/style.module.css +3 -3
  7. package/src/components/nav-panel/components/panel/root/style.module.css +6 -6
  8. package/src/components/nav-panel/components/promo/index.tsx +15 -9
  9. package/src/components/nav-panel/components/promo/style.module.css +27 -13
  10. package/src/components/nav-panel/components/text/index.tsx +34 -0
  11. package/src/components/nav-panel/product-panel/index.tsx +39 -14
  12. package/src/components/nav-panel/product-panel/style.module.css +78 -37
  13. package/src/components/nav-panel/standard-panel/index.tsx +3 -0
  14. package/src/components/nav-panel/standard-panel/style.module.css +2 -2
  15. package/src/lib/get-localized-link-props/index.test.ts +30 -0
  16. package/src/lib/get-localized-link-props/index.ts +45 -0
  17. package/src/lib/parse-url/index.test.ts +40 -1
  18. package/src/lib/parse-url/index.ts +75 -9
  19. package/src/lib/send-posthog-event/index.ts +22 -0
  20. package/src/lib/supported-locales/index.ts +1 -0
  21. package/src/lib/track-nav-click-event/index.ts +4 -4
  22. package/src/lib/v/index.ts +4 -5
  23. package/src/components/actions/index.tsx +0 -107
  24. package/src/components/actions/style.module.css +0 -28
  25. package/src/components/actions/types.ts +0 -73
  26. package/src/components/call-to-action/index.tsx +0 -205
  27. package/src/components/call-to-action/styles/variant-centered.module.css +0 -93
  28. package/src/components/call-to-action/styles/variant-compact-grid.module.css +0 -88
  29. package/src/components/call-to-action/styles/variant-compact.module.css +0 -91
  30. package/src/components/call-to-action/styles/variant-links.module.css +0 -85
  31. package/src/components/card/README.md +0 -11
  32. package/src/components/card/card.tsx +0 -45
  33. package/src/components/card/index.test.tsx +0 -69
  34. package/src/components/card/index.tsx +0 -14
  35. package/src/components/card/newsroom-card/index.test.tsx +0 -39
  36. package/src/components/card/newsroom-card/index.tsx +0 -37
  37. package/src/components/card/newsroom-card/style.module.css +0 -12
  38. package/src/components/card/partner-card/index.test.tsx +0 -57
  39. package/src/components/card/partner-card/index.tsx +0 -69
  40. package/src/components/card/partner-card/style.module.css +0 -24
  41. package/src/components/card/person-card/index.test.tsx +0 -71
  42. package/src/components/card/person-card/index.tsx +0 -93
  43. package/src/components/card/person-card/style.module.css +0 -33
  44. package/src/components/card/primitives.tsx +0 -176
  45. package/src/components/card/promo-card/index.tsx +0 -51
  46. package/src/components/card/resource-card/index.test.tsx +0 -48
  47. package/src/components/card/resource-card/index.tsx +0 -37
  48. package/src/components/card/style.module.css +0 -145
  49. package/src/components/card/types.ts +0 -66
  50. package/src/components/card/unified-card/index.tsx +0 -64
  51. package/src/components/consent-manager/README.md +0 -73
  52. package/src/components/consent-manager/components/banner/banner.module.css +0 -23
  53. package/src/components/consent-manager/components/banner/banner.test.tsx +0 -31
  54. package/src/components/consent-manager/components/banner/banner.tsx +0 -73
  55. package/src/components/consent-manager/components/dialog/dialog.module.css +0 -145
  56. package/src/components/consent-manager/components/dialog/dialog.test.tsx +0 -194
  57. package/src/components/consent-manager/components/dialog/dialog.tsx +0 -339
  58. package/src/components/consent-manager/img/icn_close.tsx +0 -19
  59. package/src/components/consent-manager/index.test.tsx +0 -334
  60. package/src/components/consent-manager/index.tsx +0 -186
  61. package/src/components/consent-manager/loader/README.md +0 -29
  62. package/src/components/consent-manager/loader/categories.ts +0 -22
  63. package/src/components/consent-manager/loader/index.tsx +0 -94
  64. package/src/components/consent-manager/loader/presets/enterprise.ts +0 -12
  65. package/src/components/consent-manager/loader/presets/oss.ts +0 -10
  66. package/src/components/consent-manager/loader/services.ts +0 -45
  67. package/src/components/consent-manager/scripts/custom.tsx +0 -59
  68. package/src/components/consent-manager/scripts/segment.tsx +0 -87
  69. package/src/components/consent-manager/style.module.css +0 -9
  70. package/src/components/consent-manager/types.ts +0 -55
  71. package/src/components/consent-manager/util/cookies.test.ts +0 -75
  72. package/src/components/consent-manager/util/cookies.ts +0 -70
  73. package/src/components/consent-manager/util/integrations.test.ts +0 -115
  74. package/src/components/consent-manager/util/integrations.ts +0 -110
  75. package/src/components/intro/index.tsx +0 -82
  76. package/src/components/intro/style.module.css +0 -67
  77. package/src/components/intro/types.ts +0 -44
  78. package/src/components/marketo-form/CHANGELOG.md +0 -122
  79. package/src/components/marketo-form/README.md +0 -1
  80. package/src/components/marketo-form/contexts/FormMetadata.ts +0 -11
  81. package/src/components/marketo-form/docs.mdx +0 -197
  82. package/src/components/marketo-form/fixtures/index.ts +0 -185
  83. package/src/components/marketo-form/form/index.tsx +0 -369
  84. package/src/components/marketo-form/index.test.tsx +0 -320
  85. package/src/components/marketo-form/index.ts +0 -11
  86. package/src/components/marketo-form/package.original.json +0 -30
  87. package/src/components/marketo-form/partials/error-message/index.tsx +0 -12
  88. package/src/components/marketo-form/partials/error-message/style.module.css +0 -13
  89. package/src/components/marketo-form/partials/field/index.tsx +0 -90
  90. package/src/components/marketo-form/partials/field-wrapper/index.tsx +0 -26
  91. package/src/components/marketo-form/partials/fields/checkbox-field/index.tsx +0 -32
  92. package/src/components/marketo-form/partials/fields/email-field/index.tsx +0 -35
  93. package/src/components/marketo-form/partials/fields/form-page-url-field/index.tsx +0 -21
  94. package/src/components/marketo-form/partials/fields/hidden-field/index.tsx +0 -37
  95. package/src/components/marketo-form/partials/fields/htmltext-field/index.tsx +0 -21
  96. package/src/components/marketo-form/partials/fields/htmltext-field/style.module.css +0 -18
  97. package/src/components/marketo-form/partials/fields/name-field/index.tsx +0 -19
  98. package/src/components/marketo-form/partials/fields/name-field/style.module.css +0 -13
  99. package/src/components/marketo-form/partials/fields/radio-buttons-field/index.tsx +0 -48
  100. package/src/components/marketo-form/partials/fields/select-field/index.tsx +0 -39
  101. package/src/components/marketo-form/partials/fields/select-field/style.module.css +0 -5
  102. package/src/components/marketo-form/partials/fields/telephone-field/index.tsx +0 -30
  103. package/src/components/marketo-form/partials/fields/text-field/index.tsx +0 -30
  104. package/src/components/marketo-form/partials/fields/textarea-field/index.tsx +0 -29
  105. package/src/components/marketo-form/partials/label/index.tsx +0 -24
  106. package/src/components/marketo-form/partials/label/style.module.css +0 -12
  107. package/src/components/marketo-form/partials/visibility-rule/index.tsx +0 -84
  108. package/src/components/marketo-form/props.js +0 -66
  109. package/src/components/marketo-form/server/api-routes.ts +0 -109
  110. package/src/components/marketo-form/server/client.ts +0 -98
  111. package/src/components/marketo-form/server/index.ts +0 -8
  112. package/src/components/marketo-form/types.ts +0 -268
  113. package/src/components/marketo-form/utils.test.tsx +0 -103
  114. package/src/components/marketo-form/utils.ts +0 -449
  115. package/src/components/next-steps/index.tsx +0 -137
  116. package/src/components/next-steps/style.module.css +0 -270
  117. package/src/components/next-steps/types.ts +0 -63
  118. package/src/components/product-badge/index.test.tsx +0 -11
  119. package/src/components/product-badge/index.tsx +0 -42
  120. package/src/components/product-badge/style.module.css +0 -76
  121. package/src/components/products-used/index.tsx +0 -84
  122. package/src/components/products-used/style.module.css +0 -87
  123. package/src/components/products-used/types.ts +0 -31
  124. package/src/components/related-content/index.test.tsx +0 -74
  125. package/src/components/related-content/index.tsx +0 -56
  126. package/src/components/related-content/style.module.css +0 -89
  127. package/src/components/related-content/types.ts +0 -21
  128. package/src/components/subnav/helpers/areBasePathsMatching.ts +0 -13
  129. package/src/components/subnav/helpers/traverse/index.ts +0 -42
  130. package/src/components/subnav/helpers/useHeightRef.ts +0 -42
  131. package/src/components/subnav/helpers/useNavRef.ts +0 -30
  132. package/src/components/subnav/helpers/useOverflowRef.ts +0 -85
  133. package/src/components/subnav/helpers/useStuckRef.ts +0 -51
  134. package/src/components/subnav/index.tsx +0 -199
  135. package/src/components/subnav/partials/CtaLinks/github-stars-link/formatStarCount/index.test.ts +0 -26
  136. package/src/components/subnav/partials/CtaLinks/github-stars-link/formatStarCount/index.ts +0 -22
  137. package/src/components/subnav/partials/CtaLinks/github-stars-link/index.tsx +0 -87
  138. package/src/components/subnav/partials/CtaLinks/github-stars-link/parseGithubUrl/index.test.ts +0 -29
  139. package/src/components/subnav/partials/CtaLinks/github-stars-link/parseGithubUrl/index.ts +0 -32
  140. package/src/components/subnav/partials/CtaLinks/github-stars-link/style.module.css +0 -85
  141. package/src/components/subnav/partials/CtaLinks/icons/github-logo.js +0 -20
  142. package/src/components/subnav/partials/CtaLinks/icons/github.svg.js +0 -7
  143. package/src/components/subnav/partials/CtaLinks/icons/star.js +0 -20
  144. package/src/components/subnav/partials/CtaLinks/index.tsx +0 -130
  145. package/src/components/subnav/partials/CtaLinks/style.module.css +0 -45
  146. package/src/components/subnav/partials/DropdownTrigger/index.tsx +0 -35
  147. package/src/components/subnav/partials/DropdownTrigger/style.module.css +0 -36
  148. package/src/components/subnav/partials/MenuItemsDefault/index.tsx +0 -151
  149. package/src/components/subnav/partials/MenuItemsDefault/style.module.css +0 -91
  150. package/src/components/subnav/partials/MenuItemsOverflow/index.tsx +0 -139
  151. package/src/components/subnav/partials/MenuItemsOverflow/style.module.css +0 -82
  152. package/src/components/subnav/partials/TitleLink/index.tsx +0 -113
  153. package/src/components/subnav/partials/TitleLink/mktg-logos/all-community-product-logos_on-dark.ts +0 -9
  154. package/src/components/subnav/partials/TitleLink/mktg-logos/all-community-product-logos_on-light.ts +0 -9
  155. package/src/components/subnav/partials/TitleLink/mktg-logos/all-primary-logos_on-dark.ts +0 -23
  156. package/src/components/subnav/partials/TitleLink/mktg-logos/all-primary-logos_on-light.ts +0 -23
  157. package/src/components/subnav/partials/TitleLink/style.module.css +0 -43
  158. package/src/components/subnav/partials/nav-item-text/index.tsx +0 -37
  159. package/src/components/subnav/partials/nav-item-text/style.module.css +0 -15
  160. package/src/components/subnav/style.module.css +0 -68
  161. package/src/components/subnav/subnav-consts.ts +0 -1
  162. package/src/components/subnav/theme.module.css +0 -50
@@ -1,84 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { useMemo } from 'react'
7
- import { useFormContext } from 'react-hook-form'
8
- import Field from '../field'
9
- import type {
10
- MarketoFormField,
11
- MarketoFormComponents,
12
- VisibilityRule as VisibilityRuleType,
13
- } from '../../types'
14
-
15
- function ruleApplies(rule: VisibilityRuleType, value: any): boolean {
16
- switch (rule.operator) {
17
- case 'is':
18
- return (
19
- rule.values.includes(value) ||
20
- (value === false && rule.values.includes('no')) ||
21
- (value === true && rule.values.includes('yes'))
22
- )
23
- case 'isNot':
24
- return !rule.values.includes(value)
25
- case 'isEmpty':
26
- return value === null || typeof value === 'undefined' || value === ''
27
- default:
28
- return false
29
- }
30
- }
31
-
32
- const FieldWithVisibilityRule = ({
33
- field,
34
- components,
35
- }: {
36
- field: MarketoFormField
37
- components?: MarketoFormComponents
38
- }) => {
39
- const { watch } = useFormContext()
40
-
41
- // Currently we only support the first defined rule.
42
- const value = watch(field.visibilityRules!.rules![0].subjectField)
43
-
44
- const hasMatchingRule = useMemo(() => {
45
- return field.visibilityRules!.rules!.some((rule) =>
46
- ruleApplies(rule, value)
47
- )
48
- }, [field, value])
49
-
50
- if (
51
- hasMatchingRule &&
52
- (field.visibilityRules!.ruleType === 'show' ||
53
- field.visibilityRules!.ruleType === 'hide')
54
- ) {
55
- return field.visibilityRules!.ruleType === 'show' ? (
56
- <Field field={field} components={components} />
57
- ) : null
58
- }
59
-
60
- // If the ruleType is show, that means the field is hidden by default.
61
- return field.visibilityRules!.ruleType === 'show' ? null : (
62
- <Field field={field} components={components} />
63
- )
64
- }
65
-
66
- const VisibilityRule = ({
67
- field,
68
- components,
69
- }: {
70
- field: MarketoFormField
71
- components?: MarketoFormComponents
72
- }) => {
73
- if (
74
- field.visibilityRules &&
75
- (field.visibilityRules.ruleType === 'show' ||
76
- field.visibilityRules.ruleType === 'hide')
77
- ) {
78
- return <FieldWithVisibilityRule field={field} components={components} />
79
- }
80
-
81
- return <Field field={field} components={components} />
82
- }
83
-
84
- export default VisibilityRule
@@ -1,66 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- module.exports = {
7
- formId: {
8
- type: 'number',
9
- required: true,
10
- description:
11
- 'The numeric ID of the Marketo form that this component is rendering.',
12
- },
13
- marketoForm: {
14
- type: 'object',
15
- required: true,
16
- description:
17
- 'The API response containing the fields of the form this component should render.',
18
- },
19
- groups: {
20
- type: 'object',
21
- description:
22
- 'Mapping of fields that should be rendered with a single component.',
23
- },
24
- components: {
25
- type: 'object',
26
- description: 'Custom components to use instead of the built-in components',
27
- properties: {
28
- text: {
29
- type: 'React.ComponentType',
30
- description: 'Component to use for text fields',
31
- },
32
- email: {
33
- type: 'React.ComponentType',
34
- description: 'Component to use for email fields',
35
- },
36
- select: {
37
- type: 'React.ComponentType',
38
- description: 'Component to use for select fields',
39
- },
40
- checkbox: {
41
- type: 'React.ComponentType',
42
- description: 'Component to use for checkbox fields',
43
- },
44
- hidden: {
45
- type: 'React.ComponentType',
46
- description: 'Component to use for hidden fields',
47
- },
48
- },
49
- },
50
- submitTitle: {
51
- type: 'string',
52
- description: 'Title to use for the submit button',
53
- },
54
- className: {
55
- type: 'string',
56
- description: 'Additional classNames passed to the form element.',
57
- },
58
- onSubmitSuccess: {
59
- type: 'function',
60
- description: 'Callback function invoked on submission success',
61
- },
62
- onSubmitFailure: {
63
- type: 'function',
64
- description: 'Callback function invoked on submission failure',
65
- },
66
- }
@@ -1,109 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import * as client from './client'
7
- import { includesSkippedRecords } from '../utils'
8
- import type { SubmissionFilter, MarketoSubmissionResponse } from '../types'
9
- import type { NextApiRequest, NextApiResponse } from 'next'
10
-
11
- async function notifyError(body: unknown, err: unknown) {
12
- if (process.env.MARKETO_ERROR_ZAPIER_WEBHOOK) {
13
- try {
14
- await fetch(process.env.MARKETO_ERROR_ZAPIER_WEBHOOK, {
15
- method: 'POST',
16
- headers: {
17
- 'Content-Type': 'application/json',
18
- },
19
- body: JSON.stringify({ body, err }, null, 2),
20
- })
21
- } catch (err) {
22
- console.error({ body, err })
23
- }
24
- }
25
-
26
- return Promise.resolve()
27
- }
28
-
29
- function isE2ETest(req: NextApiRequest): boolean {
30
- // running e2e tests locally
31
- if (process.env.E2E_TESTS === 'true') {
32
- return true
33
- }
34
-
35
- // running e2e tests against a Vercel preview
36
- if (
37
- 'input' in req.body &&
38
- req.body.input.length > 0 &&
39
- req.body.input[0].leadFormFields.email === 'daniela.rod@example.com'
40
- ) {
41
- return true
42
- }
43
-
44
- return false
45
- }
46
-
47
- async function submitForm(
48
- req: NextApiRequest,
49
- res: NextApiResponse,
50
- {
51
- submissionFilter,
52
- }: {
53
- submissionFilter?: SubmissionFilter
54
- }
55
- ) {
56
- // Don't submit forms to the Marketo API when using E2E tests.
57
- if (isE2ETest(req)) {
58
- res.status(200).json({
59
- requestId: '7d85#181a7ae5e56',
60
- result: [
61
- {
62
- id: 25325329,
63
- status: 'updated',
64
- },
65
- ],
66
- success: true,
67
- })
68
- return
69
- }
70
-
71
- try {
72
- const passesSubmissionFilter = submissionFilter
73
- ? await submissionFilter(req)
74
- : true
75
- if (!passesSubmissionFilter) {
76
- // trick spammers into thinking their form submitted successfully
77
- res.status(200).json({ success: true })
78
- return
79
- }
80
- const marketoRes = await client.submitForm(req.body)
81
- const form = (await marketoRes.json()) as MarketoSubmissionResponse
82
- if (!form.success || includesSkippedRecords(form)) {
83
- await notifyError(req.body, form)
84
- }
85
- res.status(marketoRes.status).json(form)
86
- } catch (err) {
87
- await notifyError(req.body, err)
88
- res.status(500).json({ error: 'internal server error' })
89
- throw err
90
- }
91
- }
92
-
93
- export function buildApiRoutes({
94
- submissionFilter,
95
- }: {
96
- submissionFilter?: SubmissionFilter
97
- } = {}) {
98
- return async function apiRoutes(req: NextApiRequest, res: NextApiResponse) {
99
- const route = Array.isArray(req.query.marketo)
100
- ? req.query.marketo[0]
101
- : req.query.marketo
102
- switch (route) {
103
- case 'submit':
104
- return submitForm(req, res, { submissionFilter })
105
- default:
106
- return res.status(404).json({ error: 'not found' })
107
- }
108
- }
109
- }
@@ -1,98 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import moize from 'moize'
7
- import type {
8
- MarketoFormFieldsResponse,
9
- MarketoFormMetadataResponse,
10
- MarketoFormAPIResponse,
11
- } from '../types'
12
-
13
- interface MarketoTokenResponse {
14
- access_token: string
15
- }
16
-
17
- export async function getToken(): Promise<MarketoTokenResponse> {
18
- const url = new URL(`${process.env.MARKETO_IDENTITY}/oauth/token`)
19
- url.searchParams.append('grant_type', 'client_credentials')
20
- url.searchParams.append('client_id', process.env.MARKETO_CLIENT_ID!)
21
- url.searchParams.append('client_secret', process.env.MARKETO_CLIENT_SECRET!)
22
- const res = await fetch(url.toString())
23
- return await res.json()
24
- }
25
-
26
- export async function getForm(formId: number) {
27
- return await fetch(`https://content.hashicorp.com/api/marketo?id=${formId}`)
28
- }
29
-
30
- export async function getDraftFormProps(formId: number) {
31
- const { access_token } = await getToken()
32
-
33
- const fieldsResponse = await fetch(
34
- `${process.env.MARKETO_ENDPOINT}/asset/v1/form/${formId}/fields.json?status=draft`,
35
- {
36
- headers: {
37
- 'Content-Type': 'application/json',
38
- Authorization: `Bearer ${access_token}`,
39
- },
40
- }
41
- )
42
-
43
- const metadataResponse = await fetch(
44
- `${process.env.MARKETO_ENDPOINT}/asset/v1/form/${formId}.json?status=draft`,
45
- {
46
- headers: {
47
- 'Content-Type': 'application/json',
48
- Authorization: `Bearer ${access_token}`,
49
- },
50
- }
51
- )
52
-
53
- const [fields, metadata] = await Promise.all([
54
- fieldsResponse.json(),
55
- metadataResponse.json(),
56
- ])
57
-
58
- return { fields, metadata }
59
- }
60
-
61
- export async function getFormProps(
62
- id: number
63
- ): Promise<MarketoFormAPIResponse> {
64
- const res = await getForm(id)
65
- if (res.status !== 200) {
66
- throw new Error(
67
- `[marketo-form] non-200 status code when requesting form ${id}: ${res.status}`
68
- )
69
- }
70
-
71
- const form = (await res.json()) as {
72
- result: {
73
- fields: MarketoFormFieldsResponse
74
- metadata: MarketoFormMetadataResponse
75
- }
76
- }
77
-
78
- return form.result
79
- }
80
- export const memoizedGetFormProps = moize(getFormProps, {
81
- isPromise: true,
82
- maxAge: 60 * 1000, // 60 seconds
83
- })
84
-
85
- export async function submitForm(body: unknown) {
86
- const { access_token } = await getToken()
87
- return await fetch(
88
- `${process.env.MARKETO_ENDPOINT}/v1/leads/submitForm.json`,
89
- {
90
- method: 'POST',
91
- headers: {
92
- 'Content-Type': 'application/json',
93
- Authorization: `Bearer ${access_token}`,
94
- },
95
- body: JSON.stringify(body),
96
- }
97
- )
98
- }
@@ -1,8 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import { buildApiRoutes } from './api-routes'
7
-
8
- export { buildApiRoutes }
@@ -1,268 +0,0 @@
1
- /**
2
- * Copyright (c) HashiCorp, Inc.
3
- * SPDX-License-Identifier: MPL-2.0
4
- */
5
-
6
- import type { NextApiRequest } from 'next'
7
-
8
- export type MarketoFormDatatype =
9
- | 'text'
10
- | 'email'
11
- | 'telephone'
12
- | 'textArea'
13
- | 'select'
14
- | 'checkbox'
15
- | 'hidden'
16
- | 'htmltext'
17
- | 'radioButtons'
18
-
19
- export interface Autofill {
20
- value: string
21
- valueFrom: string
22
- parameterName: string
23
- }
24
-
25
- export interface VisibilityRule {
26
- subjectField: string
27
- operator: 'is' | 'isNot' | 'isEmpty'
28
- values: string[]
29
- altLabel: string
30
- }
31
-
32
- export interface VisibilityRules {
33
- rules?: VisibilityRule[]
34
- ruleType: 'alwaysShow' | 'show' | 'hide'
35
- }
36
-
37
- export interface MarketoBaseFormField {
38
- id: string
39
- dataType: MarketoFormDatatype
40
- rowNumber: number
41
- columnNumber: number
42
- defaultValue?: string
43
- label?: string
44
- required: boolean
45
- validationMessage?: string
46
- autoFill?: Autofill
47
- visibilityRules?: VisibilityRules
48
- }
49
-
50
- export interface MarketoFormTextField extends MarketoBaseFormField {
51
- dataType: 'text'
52
- hintText?: string
53
- maxLength?: number
54
- formPrefill?: boolean
55
- }
56
-
57
- export interface MarketoFormEmailField extends MarketoBaseFormField {
58
- dataType: 'email'
59
- hintText?: string
60
- formPrefill: boolean
61
- }
62
-
63
- export interface MarketoFormTelephoneField extends MarketoBaseFormField {
64
- dataType: 'telephone'
65
- hintText?: string
66
- formPrefill: boolean
67
- }
68
-
69
- export interface MarketoFormTextAreaField extends MarketoBaseFormField {
70
- dataType: 'textArea'
71
- hintText?: string
72
- formPrefill: boolean
73
- }
74
-
75
- export interface SelectValue {
76
- label: string
77
- value: string
78
- selected?: boolean
79
- isDefault?: boolean
80
- }
81
-
82
- export interface SelectFieldMetaData {
83
- values?: SelectValue[]
84
- visibleLines?: number
85
- multiSelect?: boolean
86
- }
87
-
88
- export interface MarketoFormSelectField extends MarketoBaseFormField {
89
- dataType: 'select'
90
- fieldMetaData: SelectFieldMetaData
91
- formPrefill: boolean
92
- labelWidth?: number
93
- }
94
-
95
- export interface CheckboxFieldMetaData {
96
- initiallyChecked: boolean
97
- }
98
-
99
- export interface MarketoFormCheckboxField extends MarketoBaseFormField {
100
- dataType: 'checkbox'
101
- fieldMetaData: CheckboxFieldMetaData
102
- formPrefill: boolean
103
- }
104
-
105
- export interface MarketoFormHiddenField extends MarketoBaseFormField {
106
- dataType: 'hidden'
107
- }
108
-
109
- export interface MarketoFormHtmltextField {
110
- id: string
111
- labelWidth: number
112
- dataType: 'htmltext'
113
- rowNumber: number
114
- columnNumber: number
115
- visibilityRules?: VisibilityRules
116
- text: string
117
- }
118
-
119
- export interface MarketoFormRadioButtonsField extends MarketoBaseFormField {
120
- dataType: 'radioButtons'
121
- fieldWidth?: number
122
- formPrefill?: boolean
123
- fieldMetaData: {
124
- values: Array<{ label: string; value: string }>
125
- }
126
- }
127
-
128
- export interface MarketoFormFieldset {
129
- id: string
130
- label?: string
131
- dataType: 'fieldset'
132
- rowNumber: number
133
- columnNumber: number
134
- visibilityRules?: VisibilityRules
135
- fields: Array<string>
136
- }
137
-
138
- export type MarketoFormField =
139
- | MarketoFormTextField
140
- | MarketoFormEmailField
141
- | MarketoFormTelephoneField
142
- | MarketoFormTextAreaField
143
- | MarketoFormSelectField
144
- | MarketoFormCheckboxField
145
- | MarketoFormHiddenField
146
- | MarketoFormHtmltextField
147
- | MarketoFormRadioButtonsField
148
- | MarketoFormFieldset
149
-
150
- export interface MarketoFormMetadata {
151
- id: number
152
- name: string
153
- description: string
154
- createdAt: string
155
- updatedAt: string
156
- url: string
157
- status: string
158
- theme: string
159
- language: string
160
- locale: string
161
- progressiveProfiling: boolean
162
- labelPosition: string
163
- fontFamily: string
164
- fontSize: string
165
- folder?: {
166
- type: string
167
- value: number
168
- folderName: string
169
- }
170
- knownVisitor?: {
171
- type: string
172
- template: unknown
173
- }
174
- thankYouList?: {
175
- followupType: string
176
- followupValue: string | null
177
- default: boolean
178
- }[]
179
- buttonLocation: number
180
- buttonLabel: string
181
- waitingLabel: string
182
- workSpaceId: number
183
- }
184
-
185
- /**
186
- * The Marketo API response containing form fields.
187
- */
188
- export interface MarketoFormResponse<T> {
189
- success: boolean
190
- errors: { code: string; message: string }[]
191
- warnings?: string[]
192
- requestId?: string
193
- result: T[]
194
- }
195
-
196
- export type MarketoFormFieldsResponse = MarketoFormResponse<MarketoFormField>
197
- export type MarketoFormMetadataResponse =
198
- MarketoFormResponse<MarketoFormMetadata>
199
- export interface MarketoFormAPIResponse {
200
- fields: MarketoFormFieldsResponse
201
- metadata: MarketoFormMetadataResponse
202
- }
203
-
204
- /**
205
- * Custom components to be used in lieu of the default built-in components.
206
- */
207
- export interface MarketoFormComponents {
208
- text?: (props: { field: MarketoFormTextField }) => JSX.Element
209
- email?: (props: { field: MarketoFormEmailField }) => JSX.Element
210
- telephone?: (props: { field: MarketoFormTelephoneField }) => JSX.Element
211
- textArea?: (props: { field: MarketoFormTextAreaField }) => JSX.Element
212
- select?: (props: { field: MarketoFormSelectField }) => JSX.Element
213
- checkbox?: (props: { field: MarketoFormCheckboxField }) => JSX.Element
214
- hidden?: (props: { field: MarketoFormHiddenField }) => JSX.Element
215
- htmltext?: (props: { field: MarketoFormHtmltextField }) => JSX.Element
216
- radioButtons?: (props: { field: MarketoFormRadioButtonsField }) => JSX.Element
217
- }
218
-
219
- /**
220
- * Configuration on which fields to render with a single component. Can be used
221
- * to render multiple default components on one row (such as First Name and
222
- * Last Name) or to render a particular set of fields with a single component.
223
- */
224
- export type MarketoFormGroups = Record<
225
- string,
226
- {
227
- fields: string[]
228
- component: (props: { fields: MarketoFormField[] }) => JSX.Element
229
- }
230
- >
231
-
232
- export type SubmissionFilter = (req: NextApiRequest) => Promise<boolean>
233
-
234
- export interface MarketoSubmissionResponse {
235
- success: boolean
236
- result: { status: 'created' | 'updated' | 'skipped' }[]
237
- }
238
-
239
- export type OnSubmitData = Record<string, unknown>
240
-
241
- export interface OnSubmitProps {
242
- /**
243
- * Whether to reset the form after a successful submission.
244
- * Default: false
245
- */
246
- resetOnSubmission?: boolean
247
-
248
- /**
249
- * Callback called when form has started submission process.
250
- * Form will submit with the transformed data returned.
251
- */
252
- transformData?: (data: OnSubmitData) => OnSubmitData
253
-
254
- /**
255
- * Callback called when form has started submission process.
256
- */
257
- onSubmitStart?: () => void
258
-
259
- /**
260
- * Callback called when form has been successfully submitted.
261
- */
262
- onSubmitSuccess?: (data?: OnSubmitData) => void
263
-
264
- /**
265
- * Callback called when form submission results in an error.
266
- */
267
- onSubmitError?: () => void
268
- }