2021-07-22 11:03:00 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
2021-07-22 11:03:00 +00:00
|
|
|
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
|
|
|
|
import { Sidebar } 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-09-16 12:16:21 +00:00
|
|
|
import './style.scss';
|
2022-04-05 10:14:32 +00:00
|
|
|
import {
|
|
|
|
useForcedLayout,
|
|
|
|
getAllowedBlocks,
|
2022-04-07 13:47:58 +00:00
|
|
|
} from '../../../cart-checkout-shared';
|
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( {
|
2024-05-31 03:49:36 +00:00
|
|
|
className: clsx( 'wc-block-checkout__sidebar', attributes?.className ),
|
2021-10-20 16:18:13 +00:00
|
|
|
} );
|
2021-09-07 16:01:14 +00:00
|
|
|
const allowedBlocks = getAllowedBlocks( innerBlockAreas.CHECKOUT_TOTALS );
|
|
|
|
|
2021-10-15 09:48:57 +00:00
|
|
|
const defaultTemplate = [
|
2022-04-01 13:45:18 +00:00
|
|
|
[ 'woocommerce/checkout-order-summary-block', {}, [] ],
|
2021-10-15 09:48:57 +00:00
|
|
|
] as TemplateArray;
|
|
|
|
|
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-09-07 16:01:14 +00:00
|
|
|
|
2021-07-22 11:03:00 +00:00
|
|
|
return (
|
2021-10-20 16:18:13 +00:00
|
|
|
<Sidebar { ...blockProps }>
|
|
|
|
<InnerBlocks
|
|
|
|
allowedBlocks={ allowedBlocks }
|
|
|
|
templateLock={ false }
|
|
|
|
template={ defaultTemplate }
|
|
|
|
renderAppender={ InnerBlocks.ButtonBlockAppender }
|
|
|
|
/>
|
2021-07-22 11:03:00 +00:00
|
|
|
</Sidebar>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|