PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.1.13
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.1.13
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 / gutenberg / FormBlock / registerFormBlock.tsx

registerFormBlock.tsx in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.1.13, at scripts/gutenberg/FormBlock/registerFormBlock.tsx

74 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React from 'react';
2 import * as WpBlocksApi from '@wordpress/blocks';
3 import SprocketIcon from '../Common/SprocketIcon';
4 import FormBlockSave from './FormBlockSave';
5 import { connectionStatus } from '../../constants/leadinConfig';
6 import FormGutenbergPreview from './FormGutenbergPreview';
7 import ErrorHandler from '../../shared/Common/ErrorHandler';
8 import FormEdit from '../../shared/Form/FormEdit';
9 import ConnectionStatus from '../../shared/enums/connectionStatus';
10 import { __ } from '@wordpress/i18n';
11 import { isFullSiteEditor } from '../../utils/withMetaData';
12
13 export interface IFormBlockAttributes {
14 attributes: {
15 portalId: string;
16 formId: string;
17 preview?: boolean;
18 formName: string;
19 };
20 }
21
22 export interface IFormBlockProps extends IFormBlockAttributes {
23 setAttributes: Function;
24 isSelected: boolean;
25 context?: any;
26 }
27
28 export default function registerFormBlock() {
29 const editComponent = (props: IFormBlockProps) => {
30 if (props.attributes.preview) {
31 return <FormGutenbergPreview />;
32 } else if (connectionStatus === ConnectionStatus.Connected) {
33 return <FormEdit {...props} origin="gutenberg" preview={true} />;
34 } else {
35 return <ErrorHandler status={401} />;
36 }
37 };
38
39 // We do not support the full site editor: https://issues.hubspotcentral.com/browse/WP-1033
40 if (!WpBlocksApi || isFullSiteEditor()) {
41 return null;
42 }
43
44 WpBlocksApi.registerBlockType('leadin/hubspot-form-block', {
45 title: __('HubSpot Form', 'leadin'),
46 description: __('Select and embed a HubSpot form', 'leadin'),
47 icon: SprocketIcon,
48 category: 'leadin-blocks',
49 attributes: {
50 portalId: {
51 type: 'string',
52 default: '',
53 } as WpBlocksApi.BlockAttribute<string>,
54 formId: {
55 type: 'string',
56 } as WpBlocksApi.BlockAttribute<string>,
57 formName: {
58 type: 'string',
59 } as WpBlocksApi.BlockAttribute<string>,
60 preview: {
61 type: 'boolean',
62 default: false,
63 } as WpBlocksApi.BlockAttribute<boolean>,
64 },
65 example: {
66 attributes: {
67 preview: true,
68 },
69 },
70 edit: editComponent,
71 save: props => <FormBlockSave {...props} />,
72 });
73 }
74