2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-10-20 16:18:13 +00:00
|
|
|
import classnames from 'classnames';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
|
|
|
|
import { Main } from '@woocommerce/base-components/sidebar-layout';
|
2021-09-07 16:01:14 +00:00
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2021-10-15 09:48:57 +00:00
|
|
|
import type { TemplateArray } from '@wordpress/blocks';
|
2021-09-07 16:01:14 +00:00
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-11-19 10:49:33 +00:00
|
|
|
import { useCheckoutBlockControlsContext } from '../../context';
|
2022-04-05 10:14:32 +00:00
|
|
|
import {
|
|
|
|
useForcedLayout,
|
|
|
|
getAllowedBlocks,
|
2022-04-07 13:47:58 +00:00
|
|
|
} from '../../../cart-checkout-shared';
|
2021-09-16 12:16:21 +00:00
|
|
|
import './style.scss';
|
2021-07-22 11:03:00 +00:00
|
|
|
|
2021-10-20 16:18:13 +00:00
|
|
|
export const Edit = ( {
|
|
|
|
clientId,
|
|
|
|
attributes,
|
|
|
|
}: {
|
|
|
|
clientId: string;
|
|
|
|
attributes: {
|
|
|
|
className?: string;
|
|
|
|
};
|
|
|
|
} ): JSX.Element => {
|
|
|
|
const blockProps = useBlockProps( {
|
|
|
|
className: classnames(
|
|
|
|
'wc-block-checkout__main',
|
|
|
|
attributes?.className
|
|
|
|
),
|
|
|
|
} );
|
2021-09-07 16:01:14 +00:00
|
|
|
const allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_FIELDS );
|
2021-08-31 12:38:51 +00:00
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
const { addressFieldControls: Controls } =
|
|
|
|
useCheckoutBlockControlsContext();
|
2021-09-07 16:01:14 +00:00
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
const defaultTemplate = [
|
2021-10-15 09:48:57 +00:00
|
|
|
[ 'woocommerce/checkout-express-payment-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-contact-information-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-shipping-address-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-billing-address-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-shipping-methods-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-payment-block', {}, [] ],
|
2021-11-19 10:49:33 +00:00
|
|
|
[ 'woocommerce/checkout-order-note-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-terms-block', {}, [] ],
|
|
|
|
[ 'woocommerce/checkout-actions-block', {}, [] ],
|
2022-06-15 09:56:52 +00:00
|
|
|
].filter( Boolean ) as unknown as TemplateArray;
|
2021-10-15 09:48:57 +00:00
|
|
|
|
2021-09-07 16:01:14 +00:00
|
|
|
useForcedLayout( {
|
2021-08-31 12:38:51 +00:00
|
|
|
clientId,
|
2021-10-15 09:48:57 +00:00
|
|
|
registeredBlocks: allowedBlocks,
|
|
|
|
defaultTemplate,
|
2021-08-31 12:38:51 +00:00
|
|
|
} );
|
2021-10-15 09:48:57 +00:00
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
return (
|
2021-10-20 16:18:13 +00:00
|
|
|
<Main { ...blockProps }>
|
|
|
|
<Controls />
|
|
|
|
<form className="wc-block-components-form wc-block-checkout__form">
|
|
|
|
<InnerBlocks
|
|
|
|
allowedBlocks={ allowedBlocks }
|
|
|
|
templateLock={ false }
|
|
|
|
template={ defaultTemplate }
|
|
|
|
renderAppender={ InnerBlocks.ButtonBlockAppender }
|
|
|
|
/>
|
|
|
|
</form>
|
2021-07-22 11:03:00 +00:00
|
|
|
</Main>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|