2019-12-03 13:57:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-12-16 14:59:16 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-02-19 16:33:10 +00:00
|
|
|
|
|
|
|
import { InspectorControls } from '@wordpress/block-editor';
|
|
|
|
import { Disabled, PanelBody, ToggleControl } from '@wordpress/components';
|
2019-12-10 15:41:57 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-16 14:59:16 +00:00
|
|
|
import { withFeedbackPrompt } from '@woocommerce/block-hocs';
|
2020-01-16 14:50:48 +00:00
|
|
|
import ViewSwitcher from '@woocommerce/block-components/view-switcher';
|
2020-02-18 23:06:37 +00:00
|
|
|
import { previewCart } from '@woocommerce/resource-previews';
|
2020-02-19 16:33:10 +00:00
|
|
|
import { SHIPPING_ENABLED } from '@woocommerce/block-settings';
|
2019-12-05 21:08:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-12-10 15:41:57 +00:00
|
|
|
import FullCart from './full-cart';
|
|
|
|
import EmptyCart from './empty-cart';
|
2019-12-03 13:57:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component to handle edit mode of "Cart Block".
|
|
|
|
*/
|
2020-02-19 16:33:10 +00:00
|
|
|
const CartEditor = ( { className, attributes, setAttributes } ) => {
|
|
|
|
const { isShippingCalculatorEnabled, isShippingCostHidden } = attributes;
|
|
|
|
|
|
|
|
const BlockSettings = () => (
|
|
|
|
<InspectorControls>
|
|
|
|
<PanelBody
|
|
|
|
title={ __(
|
|
|
|
'Shipping calculations',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
>
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
|
|
|
'Shipping calculator',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
help={ __(
|
|
|
|
'Allow customers to estimate shipping.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ isShippingCalculatorEnabled }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
isShippingCalculatorEnabled: ! isShippingCalculatorEnabled,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
{ isShippingCalculatorEnabled && (
|
|
|
|
<ToggleControl
|
|
|
|
label={ __(
|
|
|
|
'Hide shipping costs',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
help={ __(
|
|
|
|
'Hide shipping costs until an address is entered.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
) }
|
|
|
|
checked={ isShippingCostHidden }
|
|
|
|
onChange={ () =>
|
|
|
|
setAttributes( {
|
|
|
|
isShippingCostHidden: ! isShippingCostHidden,
|
|
|
|
} )
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</PanelBody>
|
|
|
|
</InspectorControls>
|
|
|
|
);
|
|
|
|
|
2019-12-05 21:08:48 +00:00
|
|
|
return (
|
2019-12-10 15:41:57 +00:00
|
|
|
<div className={ className }>
|
2020-01-16 14:50:48 +00:00
|
|
|
<ViewSwitcher
|
|
|
|
label={ __( 'Edit', 'woo-gutenberg-products-block' ) }
|
|
|
|
views={ [
|
|
|
|
{
|
|
|
|
value: 'full',
|
|
|
|
name: __( 'Full Cart', 'woo-gutenberg-products-block' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'empty',
|
|
|
|
name: __(
|
|
|
|
'Empty Cart',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
] }
|
|
|
|
defaultView={ 'full' }
|
|
|
|
render={ ( currentView ) => (
|
2020-02-19 16:33:10 +00:00
|
|
|
<>
|
2020-01-16 14:50:48 +00:00
|
|
|
{ currentView === 'full' && (
|
2020-02-19 16:33:10 +00:00
|
|
|
<>
|
|
|
|
{ SHIPPING_ENABLED && <BlockSettings /> }
|
|
|
|
<Disabled>
|
|
|
|
<FullCart
|
|
|
|
cartItems={ previewCart.items }
|
|
|
|
cartTotals={ previewCart.totals }
|
|
|
|
isShippingCostHidden={
|
|
|
|
isShippingCostHidden
|
|
|
|
}
|
|
|
|
isShippingCalculatorEnabled={
|
|
|
|
isShippingCalculatorEnabled
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</Disabled>
|
|
|
|
</>
|
2020-01-16 14:50:48 +00:00
|
|
|
) }
|
|
|
|
<EmptyCart hidden={ currentView === 'full' } />
|
2020-02-19 16:33:10 +00:00
|
|
|
</>
|
2020-01-16 14:50:48 +00:00
|
|
|
) }
|
|
|
|
/>
|
2019-12-10 15:41:57 +00:00
|
|
|
</div>
|
2019-12-05 21:08:48 +00:00
|
|
|
);
|
2019-12-03 13:57:56 +00:00
|
|
|
};
|
|
|
|
|
2019-12-10 15:41:57 +00:00
|
|
|
CartEditor.propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
};
|
2019-12-03 13:57:56 +00:00
|
|
|
|
2019-12-16 14:59:16 +00:00
|
|
|
export default withFeedbackPrompt(
|
|
|
|
__(
|
|
|
|
'We are currently working on improving our cart and providing merchants with tools and options to customize their cart to their stores needs.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
)
|
|
|
|
)( CartEditor );
|