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
|
|
|
import iconDataUri from './icon-data-uri.js';
|
2021-10-25 14:46:34 +00:00
|
|
|
import './style.scss';
|
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. */
|
|
|
|
__(
|
|
|
|
'<a href="%s">Browse store</a>.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
SHOP_URL
|
|
|
|
),
|
|
|
|
dropCap: false,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: null;
|
|
|
|
|
|
|
|
const defaultTemplate = ( [
|
|
|
|
[
|
|
|
|
'core/image',
|
|
|
|
{
|
|
|
|
align: 'center',
|
|
|
|
url: iconDataUri,
|
|
|
|
sizeSlug: 'small',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'core/heading',
|
|
|
|
{
|
|
|
|
textAlign: 'center',
|
|
|
|
content: __(
|
|
|
|
'Your cart is currently empty!',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
level: 2,
|
|
|
|
className: 'wc-block-cart__empty-cart__title',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
browseStoreTemplate,
|
|
|
|
[
|
|
|
|
'core/separator',
|
|
|
|
{
|
|
|
|
className: 'is-style-dots',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'core/heading',
|
|
|
|
{
|
|
|
|
textAlign: 'center',
|
|
|
|
content: __( 'New in store', 'woo-gutenberg-products-block' ),
|
|
|
|
level: 2,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'woocommerce/product-new',
|
|
|
|
{
|
|
|
|
columns: 3,
|
|
|
|
rows: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
].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>
|
|
|
|
);
|
|
|
|
};
|