/** * External dependencies */ import classnames from 'classnames'; import { __ } from '@wordpress/i18n'; import { CartCheckoutFeedbackPrompt } from '@woocommerce/editor-components/feedback-prompt'; import { InspectorControls } from '@wordpress/block-editor'; import { Disabled, PanelBody, ToggleControl, Notice, } from '@wordpress/components'; import PropTypes from 'prop-types'; import { CartCheckoutCompatibilityNotice } from '@woocommerce/editor-components/compatibility-notices'; import ViewSwitcher from '@woocommerce/editor-components/view-switcher'; import PageSelector from '@woocommerce/editor-components/page-selector'; import { CART_PAGE_ID } from '@woocommerce/block-settings'; import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary'; import { EditorProvider, useEditorContext, CartProvider, } from '@woocommerce/base-context'; import { createInterpolateElement, useRef } from '@wordpress/element'; import { getAdminLink, getSetting } from '@woocommerce/settings'; import { previewCart } from '@woocommerce/resource-previews'; /** * Internal dependencies */ import Block from './block.js'; import EmptyCartEdit from './empty-cart-edit'; import './editor.scss'; const BlockSettings = ( { attributes, setAttributes } ) => { const { isShippingCalculatorEnabled, checkoutPageId, hasDarkControls, showRateAfterTaxName, } = attributes; const { currentPostId } = useEditorContext(); const { current: savedCheckoutPageId } = useRef( checkoutPageId ); return ( { currentPostId !== CART_PAGE_ID && ( { createInterpolateElement( __( 'If you would like to use this block as your default cart you must update your page settings in WooCommerce.', 'woo-gutenberg-products-block' ), { a: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), } ) } ) } { getSetting( 'shippingEnabled', true ) && ( setAttributes( { isShippingCalculatorEnabled: ! isShippingCalculatorEnabled, } ) } /> ) } { getSetting( 'taxesEnabled' ) && getSetting( 'displayItemizedTaxes', false ) && ! getSetting( 'displayCartPricesIncludingTax', false ) && ( setAttributes( { showRateAfterTaxName: ! showRateAfterTaxName, } ) } /> ) } { ! ( currentPostId === CART_PAGE_ID && savedCheckoutPageId === 0 ) && ( setAttributes( { checkoutPageId: id } ) } labels={ { title: __( 'Proceed to Checkout button', 'woo-gutenberg-products-block' ), default: __( 'WooCommerce Checkout Page', 'woo-gutenberg-products-block' ), } } /> ) } setAttributes( { hasDarkControls: ! hasDarkControls, } ) } /> ); }; /** * Component to handle edit mode of "Cart Block". * * Note: We need to always render `` in the editor. Otherwise, * if the user saves the page without having triggered the 'Empty Cart' * view, inner blocks would not be saved and they wouldn't be visible * in the frontend. * * @param {Object} props Incoming props for the component. * @param {string} props.className CSS class used. * @param {Object} props.attributes Attributes available. * @param {function(any):any} props.setAttributes Setter for attributes. */ const CartEditor = ( { className, attributes, setAttributes } ) => { return (
( { currentView === 'full' && ( <> ) } />
); }; CartEditor.propTypes = { className: PropTypes.string, }; export default CartEditor;