Skip to content

Commit 5f9b7a8

Browse files
authored
feat: add handler for submit error in hubspot forms (#135)
1 parent 7d99104 commit 5f9b7a8

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/sub-blocks/HubspotForm/__stories__/HubspotForm.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Default.args = {
2626
/*eslint-disable no-console */
2727
onBeforeLoad: () => console.log('onBeforeLoad'),
2828
onBeforeSubmit: () => console.log('onBeforeSubmit'),
29+
onSubmitError: () => console.log('onSubmitError'),
2930
onLoad: () => console.log('onLoad'),
3031
onSubmit: () => console.log('onSubmit'),
3132
/*eslint-enable */

src/sub-blocks/HubspotForm/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const HubspotForm: React.FunctionComponent<HubspotFormProps> = (props) => {
2929
onSubmit,
3030
onBeforeLoad,
3131
onLoad,
32+
onSubmitError,
3233
} = props;
3334

3435
const handleMetrika = useMetrika();
@@ -43,12 +44,13 @@ const HubspotForm: React.FunctionComponent<HubspotFormProps> = (props) => {
4344
onBeforeLoad,
4445
onBeforeSubmit,
4546
onLoad,
47+
onSubmitError,
4648
onSubmit: (e) => {
4749
handleMetrika?.({pixelEvents});
4850
onSubmit?.(e);
4951
},
5052
}),
51-
[onBeforeLoad, onBeforeSubmit, onLoad, handleMetrika, pixelEvents, onSubmit],
53+
[onBeforeLoad, onBeforeSubmit, onLoad, handleMetrika, pixelEvents, onSubmit, onSubmitError],
5254
);
5355

5456
useHandleHubspotEvents(handlers, formId);

src/utils/hubspot.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type HubspotEventName =
33
| 'onFormReady'
44
| 'onFormSubmit'
55
| 'onFormSubmitted'
6+
| 'onFormError'
67
| `_${string}`;
78

89
export interface HubspotEventData {
@@ -26,6 +27,7 @@ export interface HubspotEventHandlers {
2627
onBeforeSubmit?: (arg: HubspotEventData) => void;
2728
onSubmit?: (arg: HubspotEventData) => void;
2829
onLoad?: (arg: HubspotEventData) => void;
30+
onSubmitError?: (arg: HubspotEventData) => void;
2931
}
3032

3133
export function loopBackHabspotEvents(formId: string) {
@@ -73,6 +75,10 @@ export function handleHubspotEvents(handlers: HubspotEventHandlers, formId: stri
7375
handlers.onSubmit?.(data);
7476
break;
7577
}
78+
case 'onFormError': {
79+
handlers.onSubmitError?.(data);
80+
break;
81+
}
7682
default:
7783
break;
7884
}

0 commit comments

Comments
 (0)