PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.54
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.54
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
leadin / scripts / elementor / FormWidget / ElementorFormSelect.tsx

ElementorFormSelect.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.0.54, at scripts/elementor/FormWidget/ElementorFormSelect.tsx

87 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState, useEffect, Fragment } from 'react';
2 import { portalId, refreshToken } from '../../constants/leadinConfig';
3 import ElementorBanner from '../Common/ElementorBanner';
4 import UISpinner from '../../shared/UIComponents/UISpinner';
5 import { __ } from '@wordpress/i18n';
6 import {
7 BackgroudAppContext,
8 useBackgroundAppContext,
9 } from '../../iframe/useBackgroundApp';
10 import useForms from './hooks/useForms';
11 import { getOrCreateBackgroundApp } from '../../utils/backgroundAppUtils';
12
13 interface IElementorFormSelectProps {
14 formId: string;
15 setAttributes: Function;
16 }
17
18 function ElementorFormSelect({
19 formId,
20 setAttributes,
21 }: IElementorFormSelectProps) {
22 const { hasError, forms, loading } = useForms();
23
24 return loading ? (
25 <div>
26 <UISpinner />
27 </div>
28 ) : hasError ? (
29 <ElementorBanner type="danger">
30 {__('Please refresh your forms or try again in a few minutes', 'leadin')}
31 </ElementorBanner>
32 ) : (
33 <select
34 value={formId}
35 onChange={event => {
36 const selectedForm = forms.find(
37 form => form.value === event.target.value
38 );
39 if (selectedForm) {
40 setAttributes({
41 portalId,
42 formId: selectedForm.value,
43 formName: selectedForm.label,
44 });
45 }
46 }}
47 >
48 <option value="" disabled={true} selected={true}>
49 {__('Search for a form', 'leadin')}
50 </option>
51 {forms.map(form => (
52 <option key={form.value} value={form.value}>
53 {form.label}
54 </option>
55 ))}
56 </select>
57 );
58 }
59
60 function ElementorFormSelectWrapper(props: IElementorFormSelectProps) {
61 const isBackgroundAppReady = useBackgroundAppContext();
62
63 return (
64 <Fragment>
65 {!isBackgroundAppReady ? (
66 <div>
67 <UISpinner />
68 </div>
69 ) : (
70 <ElementorFormSelect {...props} />
71 )}
72 </Fragment>
73 );
74 }
75
76 export default function ElementorFormSelectContainer(
77 props: IElementorFormSelectProps
78 ) {
79 return (
80 <BackgroudAppContext.Provider
81 value={refreshToken && getOrCreateBackgroundApp(refreshToken)}
82 >
83 <ElementorFormSelectWrapper {...props} />
84 </BackgroudAppContext.Provider>
85 );
86 }
87