/** * External dependencies */ import clsx from 'clsx'; import { useRef } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; import { InspectorControls, RichText, useBlockProps, } from '@wordpress/block-editor'; import PageSelector from '@woocommerce/editor-components/page-selector'; import { PanelBody, ToggleControl } from '@wordpress/components'; import { CHECKOUT_PAGE_ID } from '@woocommerce/block-settings'; import { ReturnToCartButton } from '@woocommerce/base-components/cart-checkout'; import EditableButton from '@woocommerce/editor-components/editable-button'; /** * Internal dependencies */ import { defaultPlaceOrderButtonLabel, defaultReturnToCartButtonLabel, } from './constants'; export const Edit = ( { attributes, setAttributes, }: { attributes: { showReturnToCart: boolean; cartPageId: number; placeOrderButtonLabel: string; returnToCartButtonLabel: string; }; setAttributes: ( attributes: Record< string, unknown > ) => void; } ): JSX.Element => { const blockProps = useBlockProps(); const { cartPageId = 0, showReturnToCart = false, placeOrderButtonLabel, returnToCartButtonLabel, } = attributes; const { current: savedCartPageId } = useRef( cartPageId ); const currentPostId = useSelect( ( select ) => { if ( ! savedCartPageId ) { const store = select( 'core/editor' ); return store.getCurrentPostId(); } return savedCartPageId; }, [ savedCartPageId ] ); return (
setAttributes( { showReturnToCart: ! showReturnToCart, } ) } /> { showReturnToCart && ! ( currentPostId === CHECKOUT_PAGE_ID && savedCartPageId === 0 ) && ( setAttributes( { cartPageId: id } ) } labels={ { title: __( 'Return to Cart button', 'woocommerce' ), default: __( 'WooCommerce Cart Page', 'woocommerce' ), } } /> ) }
{ showReturnToCart && ( { setAttributes( { returnToCartButtonLabel: content, } ); } } /> ) } { setAttributes( { placeOrderButtonLabel: content, } ); } } />
); }; export const Save = (): JSX.Element => { return
; };