2023-06-16 16:43:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Disabled, Placeholder } from '@wordpress/components';
|
|
|
|
import ServerSideRender from '@wordpress/server-side-render';
|
|
|
|
import { gridBlockPreview } from '@woocommerce/resource-previews';
|
|
|
|
import { Icon, percent } from '@wordpress/icons';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { Attributes } from './types';
|
|
|
|
import { ProductOnSaleInspectorControls } from './inspector-controls';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
attributes: Attributes;
|
|
|
|
setAttributes: ( attributes: Record< string, unknown > ) => void;
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const EmptyPlaceholder = () => (
|
|
|
|
<Placeholder
|
|
|
|
icon={ <Icon icon={ percent } /> }
|
2023-12-12 22:12:36 +00:00
|
|
|
label={ __( 'On Sale Products', 'woocommerce' ) }
|
2023-06-16 16:43:54 +00:00
|
|
|
className="wc-block-product-on-sale"
|
|
|
|
>
|
|
|
|
{ __(
|
|
|
|
'This block shows on-sale products. There are currently no discounted products in your store.',
|
2023-12-12 22:12:36 +00:00
|
|
|
'woocommerce'
|
2023-06-16 16:43:54 +00:00
|
|
|
) }
|
|
|
|
</Placeholder>
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to handle edit mode of "On Sale Products".
|
|
|
|
*/
|
|
|
|
const ProductOnSaleBlock: React.FunctionComponent< Props > = (
|
|
|
|
props: Props
|
|
|
|
) => {
|
|
|
|
const { attributes, setAttributes, name } = props;
|
|
|
|
|
|
|
|
if ( attributes.isPreview ) {
|
|
|
|
return gridBlockPreview;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<ProductOnSaleInspectorControls
|
|
|
|
attributes={ attributes }
|
|
|
|
setAttributes={ setAttributes }
|
|
|
|
/>
|
|
|
|
<Disabled>
|
|
|
|
<ServerSideRender
|
|
|
|
block={ name }
|
|
|
|
attributes={ attributes }
|
|
|
|
EmptyResponsePlaceholder={ EmptyPlaceholder }
|
|
|
|
/>
|
|
|
|
</Disabled>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProductOnSaleBlock;
|