2021-09-21 15:41:09 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-10-20 14:42:57 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2021-09-21 15:41:09 +00:00
|
|
|
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';
|
|
|
|
import { innerBlockAreas } from '@woocommerce/blocks-checkout';
|
2021-10-15 09:48:57 +00:00
|
|
|
import type { TemplateArray } from '@wordpress/blocks';
|
2021-10-18 16:12:36 +00:00
|
|
|
import { useEditorContext } from '@woocommerce/base-context';
|
2021-10-20 14:42:57 +00:00
|
|
|
import { SHOP_URL } from '@woocommerce/block-settings';
|
2021-09-21 15:41:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2022-04-05 10:14:32 +00:00
|
|
|
import {
|
|
|
|
useForcedLayout,
|
|
|
|
getAllowedBlocks,
|
2022-04-07 13:47:58 +00:00
|
|
|
} from '../../../cart-checkout-shared';
|
2021-10-20 14:42:57 +00:00
|
|
|
|
|
|
|
const browseStoreTemplate = SHOP_URL
|
|
|
|
? [
|
|
|
|
'core/paragraph',
|
|
|
|
{
|
|
|
|
align: 'center',
|
|
|
|
content: sprintf(
|
|
|
|
/* translators: %s is the link to the store product directory. */
|
|
|
|
__(
|
2023-02-07 15:47:13 +00:00
|
|
|
'<a href="%s">Browse store</a>',
|
2021-10-20 14:42:57 +00:00
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
SHOP_URL
|
|
|
|
),
|
|
|
|
dropCap: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: null;
|
|
|
|
|
2022-06-15 09:56:52 +00:00
|
|
|
const defaultTemplate = [
|
2021-10-20 14:42:57 +00:00
|
|
|
[
|
|
|
|
'core/heading',
|
|
|
|
{
|
|
|
|
textAlign: 'center',
|
|
|
|
content: __(
|
|
|
|
'Your cart is currently empty!',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
level: 2,
|
2023-02-07 15:47:13 +00:00
|
|
|
className: 'with-empty-cart-icon wc-block-cart__empty-cart__title',
|
2021-10-20 14:42:57 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
browseStoreTemplate,
|
|
|
|
[
|
|
|
|
'core/separator',
|
|
|
|
{
|
|
|
|
className: 'is-style-dots',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'core/heading',
|
|
|
|
{
|
|
|
|
textAlign: 'center',
|
|
|
|
content: __( 'New in store', 'woo-gutenberg-products-block' ),
|
|
|
|
level: 2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'woocommerce/product-new',
|
|
|
|
{
|
2023-10-09 15:04:19 +00:00
|
|
|
columns: 4,
|
2021-10-20 14:42:57 +00:00
|
|
|
rows: 1,
|
|
|
|
},
|
|
|
|
],
|
2022-06-15 09:56:52 +00:00
|
|
|
].filter( Boolean ) as unknown as TemplateArray;
|
2021-09-21 15:41:09 +00:00
|
|
|
|
|
|
|
export const Edit = ( { clientId }: { clientId: string } ): JSX.Element => {
|
|
|
|
const blockProps = useBlockProps();
|
2021-10-18 16:12:36 +00:00
|
|
|
const { currentView } = useEditorContext();
|
2021-09-21 15:41:09 +00:00
|
|
|
const allowedBlocks = getAllowedBlocks( innerBlockAreas.EMPTY_CART );
|
|
|
|
|
|
|
|
useForcedLayout( {
|
|
|
|
clientId,
|
2021-10-15 09:48:57 +00:00
|
|
|
registeredBlocks: allowedBlocks,
|
|
|
|
defaultTemplate,
|
2021-09-21 15:41:09 +00:00
|
|
|
} );
|
2021-09-22 15:00:19 +00:00
|
|
|
|
2021-09-21 15:41:09 +00:00
|
|
|
return (
|
2021-09-24 15:13:39 +00:00
|
|
|
<div
|
|
|
|
{ ...blockProps }
|
|
|
|
hidden={ currentView !== 'woocommerce/empty-cart-block' }
|
|
|
|
>
|
2021-09-21 15:41:09 +00:00
|
|
|
<InnerBlocks
|
2021-10-15 09:48:57 +00:00
|
|
|
template={ defaultTemplate }
|
2021-09-21 15:41:09 +00:00
|
|
|
templateLock={ false }
|
2021-10-19 11:23:33 +00:00
|
|
|
renderAppender={ InnerBlocks.ButtonBlockAppender }
|
2021-09-21 15:41:09 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Save = (): JSX.Element => {
|
|
|
|
return (
|
|
|
|
<div { ...useBlockProps.save() }>
|
|
|
|
<InnerBlocks.Content />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|