← All changes
|
scripts/gutenberg/FormBlock/registerFormBlock.tsx
+24
-8
11.1.21
→
11.3.75
View file →
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import React from 'react'; |
| 2 | 2 | import * as WpBlocksApi from '@wordpress/blocks'; |
| 3 | 3 | import SprocketIcon from '../Common/SprocketIcon'; |
| 4 | +import StylesheetErrorBondary from '../Common/StylesheetErrorBondary'; | |
| 4 | 5 | import FormBlockSave from './FormBlockSave'; |
| 5 | 6 | import { connectionStatus } from '../../constants/leadinConfig'; |
| 6 | 7 | import FormGutenbergPreview from './FormGutenbergPreview'; |
| 7 | 8 | import ErrorHandler from '../../shared/Common/ErrorHandler'; |
| @@ -15,8 +16,9 @@ | ||
| 15 | 16 | portalId: string; |
| 16 | 17 | formId: string; |
| 17 | 18 | preview?: boolean; |
| 18 | 19 | formName: string; |
| 20 | + embedVersion?: string; | |
| 19 | 21 | }; |
| 20 | 22 | } |
| 21 | 23 | |
| 22 | 24 | export interface IFormBlockProps extends IFormBlockAttributes { |
| @@ -26,19 +28,30 @@ | ||
| 26 | 28 | } |
| 27 | 29 | |
| 28 | 30 | export default function registerFormBlock() { |
| 29 | 31 | 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 | - } | |
| 32 | + const isPreview = props.attributes.preview; | |
| 33 | + const isConnected = connectionStatus === ConnectionStatus.Connected; | |
| 34 | + return ( | |
| 35 | + <StylesheetErrorBondary> | |
| 36 | + {isPreview ? ( | |
| 37 | + <FormGutenbergPreview /> | |
| 38 | + ) : isConnected ? ( | |
| 39 | + <FormEdit | |
| 40 | + {...props} | |
| 41 | + origin="gutenberg" | |
| 42 | + preview={true} | |
| 43 | + fullSiteEditor={isFullSiteEditor()} | |
| 44 | + /> | |
| 45 | + ) : ( | |
| 46 | + <ErrorHandler status={401} /> | |
| 47 | + )} | |
| 48 | + </StylesheetErrorBondary> | |
| 49 | + ); | |
| 37 | 50 | }; |
| 38 | 51 | |
| 39 | 52 | // We do not support the full site editor: https://issues.hubspotcentral.com/browse/WP-1033 |
| 40 | - if (!WpBlocksApi || isFullSiteEditor()) { | |
| 53 | + if (!WpBlocksApi) { | |
| 41 | 54 | return null; |
| 42 | 55 | } |
| 43 | 56 | |
| 44 | 57 | WpBlocksApi.registerBlockType('leadin/hubspot-form-block', { |
| @@ -54,8 +67,11 @@ | ||
| 54 | 67 | formId: { |
| 55 | 68 | type: 'string', |
| 56 | 69 | } as WpBlocksApi.BlockAttribute<string>, |
| 57 | 70 | formName: { |
| 71 | + type: 'string', | |
| 72 | + } as WpBlocksApi.BlockAttribute<string>, | |
| 73 | + embedVersion: { | |
| 58 | 74 | type: 'string', |
| 59 | 75 | } as WpBlocksApi.BlockAttribute<string>, |
| 60 | 76 | preview: { |
| 61 | 77 | type: 'boolean', |