PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.75
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.75
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
← All changes | scripts/shared/Form/hooks/useForms.ts +20 -9 11.1.2111.3.75 View file →
@@ -1,30 +1,41 @@
1 1 import { useState } from 'react';
2 2 import debounce from 'lodash/debounce';
3 3 import { usePostAsyncBackgroundMessage } from '../../../iframe/useBackgroundApp';
4 -import { DEFAULT_OPTIONS } from '../../../constants/defaultFormOptions';
5 4 import { ProxyMessages } from '../../../iframe/integratedMessages';
6 5 import { IForm } from '../../types';
6 +import useGetTemplateAvailability, {
7 + getTemplateOptions,
8 +} from './useGetTemplateAvailability';
7 9
8 10 export default function useForms() {
9 11 const proxy = usePostAsyncBackgroundMessage();
10 12 const [formApiError, setFormApiError] = useState<any>(null);
13 + const { availabilityPromise } = useGetTemplateAvailability();
11 14
12 15 const search = debounce(
13 16 (search: string, callback: Function) => {
14 - return proxy({
15 - key: ProxyMessages.FetchForms,
16 - payload: {
17 - search,
18 - },
19 - })
20 - .then(forms => {
17 + return Promise.all([
18 + availabilityPromise,
19 + proxy({
20 + key: ProxyMessages.FetchForms,
21 + payload: {
22 + search,
23 + },
24 + }),
25 + ])
26 + .then(([templateAvailabilityResponse, forms]) => {
27 + const TEMPLATE_OPTIONS = getTemplateOptions(
28 + templateAvailabilityResponse.templateAvailability
29 + );
30 +
21 31 callback([
22 32 ...forms.map((form: IForm) => ({
23 33 label: form.name,
24 34 value: form.guid,
35 + embedVersion: form.embedVersion,
25 36 })),
26 - DEFAULT_OPTIONS,
37 + TEMPLATE_OPTIONS,
27 38 ]);
28 39 })
29 40 .catch(error => {
30 41 setFormApiError(error);