/** * External dependencies */ import { __ } from '@wordpress/i18n'; import FeedbackPrompt from '@woocommerce/block-components/feedback-prompt'; import { InspectorControls } from '@wordpress/block-editor'; import { Disabled, PanelBody, ToggleControl, SelectControl, Notice, } from '@wordpress/components'; import PropTypes from 'prop-types'; import ViewSwitcher from '@woocommerce/block-components/view-switcher'; import { SHIPPING_ENABLED, 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 { useSelect } from '@wordpress/data'; import { __experimentalCreateInterpolateElement } from 'wordpress-element'; import { getAdminLink } from '@woocommerce/settings'; import { previewCart, cartBlockPreview } 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, isShippingCostHidden, checkoutPageId, } = attributes; const pages = useSelect( ( select ) => { return select( 'core' ).getEntityRecords( 'postType', 'page', { status: 'publish', orderby: 'title', order: 'asc', per_page: 100, } ); }, [] ) || null; const { currentPostId } = useEditorContext(); return ( { currentPostId !== CART_PAGE_ID && ( { __experimentalCreateInterpolateElement( __( '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 ), } ) } ) } setAttributes( { isShippingCalculatorEnabled: ! isShippingCalculatorEnabled, } ) } /> { ( currentPostId !== CART_PAGE_ID || checkoutPageId ) && pages && ( { return { label: page.title.raw, value: parseInt( page.id, 10 ), }; } ), ] } onChange={ ( value ) => setAttributes( { checkoutPageId: parseInt( value, 10 ), } ) } /> ) } ); }; /** * Component to handle edit mode of "Cart Block". */ const CartEditor = ( { className, attributes, setAttributes } ) => { if ( attributes.isPreview ) { return cartBlockPreview; } return (
( { currentView === 'full' && ( <> { SHIPPING_ENABLED && ( ) } ) } ) } />
); }; CartEditor.propTypes = { className: PropTypes.string, }; export default CartEditor;