diff --git a/projects/packages/forms/changelog/remove-contact-form-hocs b/projects/packages/forms/changelog/remove-contact-form-hocs
new file mode 100644
index 000000000000..9b38f38c0c17
--- /dev/null
+++ b/projects/packages/forms/changelog/remove-contact-form-hocs
@@ -0,0 +1,4 @@
+Significance: patch
+Type: changed
+
+Forms: Remove wrapping
element from form block.
diff --git a/projects/packages/forms/src/blocks/contact-form/edit.js b/projects/packages/forms/src/blocks/contact-form/edit.js
index fff949c91a86..a1279826cc9b 100644
--- a/projects/packages/forms/src/blocks/contact-form/edit.js
+++ b/projects/packages/forms/src/blocks/contact-form/edit.js
@@ -23,9 +23,9 @@ import {
TextControl,
Notice,
} from '@wordpress/components';
-import { compose, withInstanceId } from '@wordpress/compose';
-import { withDispatch, withSelect } from '@wordpress/data';
-import { forwardRef, Fragment, useEffect, useState } from '@wordpress/element';
+import { useInstanceId } from '@wordpress/compose';
+import { useDispatch, useSelect } from '@wordpress/data';
+import { useEffect, useRef, useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import clsx from 'clsx';
import { filter, get, isArray, map } from 'lodash';
@@ -38,8 +38,8 @@ import JetpackEmailConnectionSettings from './components/jetpack-email-connectio
import JetpackManageResponsesSettings from './components/jetpack-manage-responses-settings';
import NewsletterIntegrationSettings from './components/jetpack-newsletter-integration-settings';
import SalesforceLeadFormSettings from './components/jetpack-salesforce-lead-form/jetpack-salesforce-lead-form-settings';
-import { withStyleVariables } from './util/with-style-variables';
import defaultVariations from './variations';
+import './util/form-styles.js';
const validFields = filter( childBlocks, ( { settings } ) => {
return (
@@ -72,332 +72,299 @@ const PRIORITIZED_INSERTER_BLOCKS = [ ...map( validFields, block => `jetpack/${
const RESPONSES_PATH = `${ get( getJetpackData(), 'adminUrl', false ) }edit.php?post_type=feedback`;
const CUSTOMIZING_FORMS_URL = 'https://jetpack.com/support/jetpack-blocks/contact-form/';
-export const JetpackContactFormEdit = forwardRef(
- (
- {
- attributes,
- setAttributes,
- postAuthorEmail,
- hasInnerBlocks,
- replaceInnerBlocks,
- selectBlock,
- clientId,
- instanceId,
- className,
- blockType,
- variations,
- defaultVariation,
- canUserInstallPlugins,
- style,
- },
- ref
- ) => {
- const {
- to,
- subject,
- customThankyou,
- customThankyouHeading,
- customThankyouMessage,
- customThankyouRedirect,
- jetpackCRM,
- salesforceData,
- } = attributes;
- const [ isPatternsModalOpen, setIsPatternsModalOpen ] = useState( false );
-
- const blockProps = useBlockProps();
- const { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } =
- useModuleStatus( 'contact-form' );
+function JetpackContactFormEdit( { name, attributes, setAttributes, clientId, className } ) {
+ const {
+ to,
+ subject,
+ customThankyou,
+ customThankyouHeading,
+ customThankyouMessage,
+ customThankyouRedirect,
+ jetpackCRM,
+ salesforceData,
+ } = attributes;
+ const instanceId = useInstanceId( JetpackContactFormEdit );
+ const { replaceInnerBlocks, selectBlock } = useDispatch( 'core/block-editor' );
+ const {
+ blockType,
+ canUserInstallPlugins,
+ defaultVariation,
+ variations,
+ hasInnerBlocks,
+ postAuthorEmail,
+ } = useSelect(
+ select => {
+ const { getBlockType, getBlockVariations, getDefaultBlockVariation } =
+ select( 'core/blocks' );
+ const { getBlocks } = select( 'core/block-editor' );
+ const { getEditedPostAttribute } = select( 'core/editor' );
+ const { getUser, canUser } = select( 'core' );
+ const innerBlocks = getBlocks( clientId );
- const formClassnames = clsx( className, 'jetpack-contact-form', {
- 'is-placeholder': ! hasInnerBlocks && registerBlockVariation,
- } );
+ const authorId = getEditedPostAttribute( 'author' );
+ const authorEmail = authorId && getUser( authorId ) && getUser( authorId ).email;
+ const submitButton = innerBlocks.find( block => block.name === 'jetpack/button' );
+ if ( submitButton && ! submitButton.attributes.lock ) {
+ const lock = { move: false, remove: true };
+ submitButton.attributes.lock = lock;
+ }
- const isSalesForceExtensionEnabled =
- !! window?.Jetpack_Editor_Initial_State?.available_blocks[
- 'contact-form/salesforce-lead-form'
- ];
+ return {
+ blockType: getBlockType && getBlockType( name ),
+ canUserInstallPlugins: canUser( 'create', 'plugins' ),
+ defaultVariation: getDefaultBlockVariation && getDefaultBlockVariation( name, 'block' ),
+ variations: getBlockVariations && getBlockVariations( name, 'block' ),
+ hasInnerBlocks: innerBlocks.length > 0,
+ postAuthorEmail: authorEmail,
+ };
+ },
+ [ clientId, name ]
+ );
+ const [ isPatternsModalOpen, setIsPatternsModalOpen ] = useState( false );
+ const wrapperRef = useRef();
+ const innerRef = useRef();
+ const blockProps = useBlockProps( { ref: wrapperRef } );
+ const { isLoadingModules, isChangingStatus, isModuleActive, changeStatus } =
+ useModuleStatus( 'contact-form' );
- const createBlocksFromInnerBlocksTemplate = innerBlocksTemplate => {
- const blocks = map( innerBlocksTemplate, ( [ name, attr, innerBlocks = [] ] ) =>
- createBlock( name, attr, createBlocksFromInnerBlocksTemplate( innerBlocks ) )
- );
+ const formClassnames = clsx( className, 'jetpack-contact-form', {
+ 'is-placeholder': ! hasInnerBlocks && registerBlockVariation,
+ } );
- return blocks;
- };
+ const isSalesForceExtensionEnabled =
+ !! window?.Jetpack_Editor_Initial_State?.available_blocks[
+ 'contact-form/salesforce-lead-form'
+ ];
- const setVariation = variation => {
- if ( variation.attributes ) {
- setAttributes( variation.attributes );
- }
+ const createBlocksFromInnerBlocksTemplate = innerBlocksTemplate => {
+ const blocks = map( innerBlocksTemplate, ( [ blockName, attr, innerBlocks = [] ] ) =>
+ createBlock( blockName, attr, createBlocksFromInnerBlocksTemplate( innerBlocks ) )
+ );
- if ( variation.innerBlocks ) {
- replaceInnerBlocks(
- clientId,
- createBlocksFromInnerBlocksTemplate( variation.innerBlocks )
- );
- }
+ return blocks;
+ };
- selectBlock( clientId );
- };
+ const setVariation = variation => {
+ if ( variation.attributes ) {
+ setAttributes( variation.attributes );
+ }
- useEffect( () => {
- // Populate default variation on older versions of WP or GB that don't support variations.
- if ( ! hasInnerBlocks && ! registerBlockVariation ) {
- setVariation( defaultVariations[ 0 ] );
- }
- } );
+ if ( variation.innerBlocks ) {
+ replaceInnerBlocks( clientId, createBlocksFromInnerBlocksTemplate( variation.innerBlocks ) );
+ }
- useEffect( () => {
- if (
- ! hasInnerBlocks &&
- registerBlockVariation &&
- ! isPatternsModalOpen &&
- window.location.search.indexOf( 'showJetpackFormsPatterns' ) !== -1
- ) {
- setIsPatternsModalOpen( true );
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [] );
+ selectBlock( clientId );
+ };
- const renderSubmissionSettings = () => {
- return (
- <>
-
- { __( 'Customize the view after form submission:', 'jetpack-forms' ) }
-
-
setAttributes( { customThankyou: newMessage } ) }
- __nextHasNoMarginBottom={ true }
- __next40pxDefaultSize={ true }
- />
+ useEffect( () => {
+ // Populate default variation on older versions of WP or GB that don't support variations.
+ if ( ! hasInnerBlocks && ! registerBlockVariation ) {
+ setVariation( defaultVariations[ 0 ] );
+ }
+ } );
- { 'redirect' !== customThankyou && (
- setAttributes( { customThankyouHeading: newHeading } ) }
- __nextHasNoMarginBottom={ true }
- __next40pxDefaultSize={ true }
- />
- ) }
+ useEffect( () => {
+ if (
+ ! hasInnerBlocks &&
+ registerBlockVariation &&
+ ! isPatternsModalOpen &&
+ window.location.search.indexOf( 'showJetpackFormsPatterns' ) !== -1
+ ) {
+ setIsPatternsModalOpen( true );
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [] );
- { 'message' === customThankyou && (
- setAttributes( { customThankyouMessage: newMessage } ) }
- __nextHasNoMarginBottom={ true }
- />
- ) }
+ let elt;
- { 'redirect' === customThankyou && (
-
- setAttributes( { customThankyouRedirect: newURL } ) }
- />
-
- ) }
- >
+ if ( ! isModuleActive ) {
+ if ( isLoadingModules ) {
+ elt = ;
+ } else {
+ elt = (
+
);
- };
-
- const renderVariationPicker = () => {
- return (
-
-
! v.hiddenFromPicker ) }
- onSelect={ ( nextVariation = defaultVariation ) => {
- setVariation( nextVariation );
- } }
- />
-
-
+ );
+ } else {
+ const style = window.jetpackForms.generateStyleVariables( innerRef.current );
+ elt = (
+ <>
+
+ { ! attributes.formTitle && (
+
+
+ { __(
+ 'Add a heading inside the form or before it to help everybody identify it.',
+ 'jetpack-forms'
+ ) }
+ { ' ' }
-
-
+
+
+
+
+ { __( 'Customize the view after form submission:', 'jetpack-forms' ) }
+
+ setAttributes( { customThankyou: newMessage } ) }
+ __nextHasNoMarginBottom={ true }
+ __next40pxDefaultSize={ true }
+ />
+
+ { 'redirect' !== customThankyou && (
+ setAttributes( { customThankyouHeading: newHeading } ) }
+ __nextHasNoMarginBottom={ true }
+ __next40pxDefaultSize={ true }
/>
-
+ ) }
- { isSalesForceExtensionEnabled && salesforceData?.sendToSalesforce && (
- setAttributes( { customThankyouMessage: newMessage } ) }
+ __nextHasNoMarginBottom={ true }
/>
) }
- { ! ( isSimpleSite() || isAtomicSite() ) && (
-
- { canUserInstallPlugins && (
-
-
-
- ) }
-
-
-
-
+
+ { 'redirect' === customThankyou && (
+
+ setAttributes( { customThankyouRedirect: newURL } ) }
+ />
+
) }
-
+
+
+
+
-
-
-
- >
- );
- }
+ ) }
+ { ! ( isSimpleSite() || isAtomicSite() ) && (
+ <>
+ { canUserInstallPlugins && (
+
+
+
+ ) }
+
+
+
+ >
+ ) }
+
- return { elt }
;
+
+
+
+ >
+ );
}
-);
-
-const withThemeProvider = WrappedComponent => props => (
-
-
-
-);
-
-export default compose( [
- withSelect( ( select, props ) => {
- const { getBlockType, getBlockVariations, getDefaultBlockVariation } = select( 'core/blocks' );
- const { getBlocks } = select( 'core/block-editor' );
- const { getEditedPostAttribute } = select( 'core/editor' );
- const { getUser, canUser } = select( 'core' );
- const innerBlocks = getBlocks( props.clientId );
-
- const authorId = getEditedPostAttribute( 'author' );
- const authorEmail = authorId && getUser( authorId ) && getUser( authorId ).email;
- const canUserInstallPlugins = canUser( 'create', 'plugins' );
- const submitButton = innerBlocks.find( block => block.name === 'jetpack/button' );
- if ( submitButton && ! submitButton.attributes.lock ) {
- const lock = { move: false, remove: true };
- submitButton.attributes.lock = lock;
- }
-
- return {
- blockType: getBlockType && getBlockType( props.name ),
- canUserInstallPlugins,
- defaultVariation: getDefaultBlockVariation && getDefaultBlockVariation( props.name, 'block' ),
- variations: getBlockVariations && getBlockVariations( props.name, 'block' ),
+ return (
+
+ { elt }
+
+ );
+}
- innerBlocks,
- hasInnerBlocks: innerBlocks.length > 0,
- postAuthorEmail: authorEmail,
- };
- } ),
- withDispatch( dispatch => {
- const { replaceInnerBlocks, selectBlock } = dispatch( 'core/block-editor' );
- return { replaceInnerBlocks, selectBlock };
- } ),
- withInstanceId,
- withThemeProvider,
-] )( withStyleVariables( JetpackContactFormEdit ) );
+export default JetpackContactFormEdit;
diff --git a/projects/packages/forms/src/blocks/contact-form/util/with-style-variables.js b/projects/packages/forms/src/blocks/contact-form/util/with-style-variables.js
deleted file mode 100644
index 705689137dda..000000000000
--- a/projects/packages/forms/src/blocks/contact-form/util/with-style-variables.js
+++ /dev/null
@@ -1,15 +0,0 @@
-import './form-styles.js';
-import { useRef } from '@wordpress/element';
-
-export const withStyleVariables = WrappedComponent => props => {
- const { generateStyleVariables } = window.jetpackForms;
- const componentRef = useRef( undefined );
-
- return (
-
- );
-};
diff --git a/projects/plugins/jetpack/changelog/remove-contact-form-hocs b/projects/plugins/jetpack/changelog/remove-contact-form-hocs
new file mode 100644
index 000000000000..3566d3d26c79
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/remove-contact-form-hocs
@@ -0,0 +1,4 @@
+Significance: patch
+Type: other
+
+Forms: Remove wrapping element from form block.