/** * External dependencies */ import { __ } from '@wordpress/i18n'; import FeedbackPrompt from '@woocommerce/block-components/feedback-prompt'; import { previewCart, previewShippingRates, } from '@woocommerce/resource-previews'; import { InspectorControls } from '@wordpress/block-editor'; import { PanelBody, ToggleControl, CheckboxControl, SelectControl, Notice, Disabled, } from '@wordpress/components'; import BlockErrorBoundary from '@woocommerce/base-components/block-error-boundary'; import { PRIVACY_URL, TERMS_URL, SHIPPING_METHODS_EXIST, CHECKOUT_PAGE_ID, } from '@woocommerce/block-settings'; import { useSelect } from '@wordpress/data'; import { getAdminLink } from '@woocommerce/settings'; import { __experimentalCreateInterpolateElement } from 'wordpress-element'; import { EditorProvider, useEditorContext } from '@woocommerce/base-context'; /** * Internal dependencies */ import Block from './block.js'; import './editor.scss'; const BlockSettings = ( { attributes, setAttributes } ) => { const { showCompanyField, showAddress2Field, showPhoneField, requireCompanyField, requirePhoneField, showPolicyLinks, showReturnToCart, cartPageId, } = attributes; const { currentPostId } = useEditorContext(); const pages = useSelect( ( select ) => { return select( 'core' ).getEntityRecords( 'postType', 'page', { status: 'publish', orderby: 'title', order: 'asc', per_page: 100, } ); }, [] ) || null; return ( { currentPostId !== CHECKOUT_PAGE_ID && ( { __experimentalCreateInterpolateElement( __( 'If you would like to use this block as your default checkout you must update your page settings in WooCommerce.', 'woo-gutenberg-products-block' ), { a: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), } ) } ) }

{ __( 'Choose whether your checkout form requires extra information from customers.', 'woo-gutenberg-products-block' ) }

setAttributes( { showCompanyField: ! showCompanyField, } ) } /> { showCompanyField && ( setAttributes( { requireCompanyField: ! requireCompanyField, } ) } className="components-base-control--nested" /> ) } setAttributes( { showAddress2Field: ! showAddress2Field, } ) } /> setAttributes( { showPhoneField: ! showPhoneField, } ) } /> { showPhoneField && ( setAttributes( { requirePhoneField: ! requirePhoneField, } ) } className="components-base-control--nested" /> ) }

{ __( 'Choose additional content to display.', 'woo-gutenberg-products-block' ) }

setAttributes( { showPolicyLinks: ! showPolicyLinks, } ) } /> { showPolicyLinks && ( ! PRIVACY_URL || ! TERMS_URL ) && ( { __experimentalCreateInterpolateElement( __( 'Pages must be first setup in store settings: Privacy policy, Terms and conditions.', 'woo-gutenberg-products-block' ), { a1: ( // eslint-disable-next-line jsx-a11y/anchor-has-content
), a2: ( // eslint-disable-next-line jsx-a11y/anchor-has-content ), } ) } ) } setAttributes( { showReturnToCart: ! showReturnToCart, } ) } /> { showReturnToCart && ( currentPostId !== CHECKOUT_PAGE_ID || !! cartPageId ) && pages && ( { return { label: page.title.raw, value: parseInt( page.id, 10 ), }; } ), ] } onChange={ ( value ) => setAttributes( { cartPageId: parseInt( value, 10 ), } ) } /> ) }
); }; const CheckoutEditor = ( { attributes, setAttributes } ) => { const { className } = attributes; return (
); }; export default CheckoutEditor;