/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { useBlockProps, RichText, InspectorControls, } from '@wordpress/block-editor'; import { CheckboxControl } from '@woocommerce/blocks-components'; import { PanelBody, ToggleControl, Notice, ExternalLink, } from '@wordpress/components'; import { PRIVACY_URL, TERMS_URL } from '@woocommerce/block-settings'; import { ADMIN_URL } from '@woocommerce/settings'; /** * Internal dependencies */ import './editor.scss'; import { termsConsentDefaultText, termsCheckboxDefaultText } from './constants'; export const Edit = ( { attributes: { checkbox, text }, setAttributes, }: { attributes: { text: string; checkbox: boolean }; setAttributes: ( attributes: Record< string, unknown > ) => void; } ): JSX.Element => { const blockProps = useBlockProps(); const defaultText = checkbox ? termsCheckboxDefaultText : termsConsentDefaultText; const currentText = text || defaultText; return (
{ /* Show this notice if a terms page or a privacy page is not setup. */ } { ( ! TERMS_URL || ! PRIVACY_URL ) && ( { __( "Link to your store's Terms and Conditions and Privacy Policy pages by creating pages for them.", 'woo-gutenberg-products-block' ) }
{ ! TERMS_URL && ( <>
{ __( 'Setup a Terms and Conditions page', 'woo-gutenberg-products-block' ) } ) } { ! PRIVACY_URL && ( <>
{ __( 'Setup a Privacy Policy page', 'woo-gutenberg-products-block' ) } ) }
) } { /* Show this notice if we have both a terms and privacy pages, but they're not present in the text. */ } { TERMS_URL && PRIVACY_URL && ! ( currentText.includes( TERMS_URL ) && currentText.includes( PRIVACY_URL ) ) && ( setAttributes( { text: '', } ), }, ] : [] } >

{ __( 'Ensure you add links to your policy pages in this section.', 'woo-gutenberg-products-block' ) }

) } setAttributes( { checkbox: ! checkbox, } ) } />
{ checkbox ? ( <> setAttributes( { text: value } ) } /> ) : ( setAttributes( { text: value } ) } /> ) }
); }; export const Save = (): JSX.Element => { return
; };