99} from '@wordpress/block-editor' ;
1010import CheckboxControl from '@woocommerce/base-components/checkbox-control' ;
1111import { PanelBody , ToggleControl , Notice } from '@wordpress/components' ;
12+ import { PRIVACY_URL , TERMS_URL } from '@woocommerce/block-settings' ;
13+ import { ADMIN_URL } from '@woocommerce/settings' ;
14+ import { Icon , external } from '@wordpress/icons' ;
1215
1316/**
1417 * Internal dependencies
@@ -24,8 +27,12 @@ export const Edit = ( {
2427 setAttributes : ( attributes : Record < string , unknown > ) => void ;
2528} ) : JSX . Element => {
2629 const blockProps = useBlockProps ( ) ;
27- const currentText = text || termsCheckboxDefaultText ;
2830
31+ const defaultText = checkbox
32+ ? termsCheckboxDefaultText
33+ : termsConsentDefaultText ;
34+
35+ const currentText = text || defaultText ;
2936 return (
3037 < div { ...blockProps } >
3138 < InspectorControls >
@@ -66,41 +73,107 @@ export const Edit = ( {
6673 ) : (
6774 < RichText
6875 tagName = "span"
69- value = { text || termsConsentDefaultText }
76+ value = { currentText }
7077 onChange = { ( value ) =>
7178 setAttributes ( { text : value } )
7279 }
7380 />
7481 ) }
7582 </ div >
76- { ! currentText . includes ( '<a ' ) && (
83+ { /* Show this notice if a terms page or a privacy page is not setup. */ }
84+ { ( ! TERMS_URL || ! PRIVACY_URL ) && (
7785 < Notice
7886 className = "wc-block-checkout__terms_notice"
7987 status = "warning"
8088 isDismissible = { false }
81- actions = {
82- termsConsentDefaultText !== text
83- ? [
84- {
85- label : __ (
86- 'Restore default text' ,
87- 'woo-gutenberg-products-block'
88- ) ,
89- onClick : ( ) =>
90- setAttributes ( { text : '' } ) ,
91- } ,
92- ]
93- : [ ]
94- }
89+ actions = { [
90+ ! TERMS_URL && {
91+ className : 'wc-block-checkout__terms_notice-button' ,
92+ label : (
93+ < >
94+ { __ (
95+ 'Setup a Terms and Conditions page' ,
96+ 'woo-gutenberg-products-block'
97+ ) }
98+ < Icon
99+ icon = { external }
100+ size = { 16 }
101+ className = "wc-block-checkout__terms_notice-button__icon"
102+ />
103+ </ >
104+ ) ,
105+
106+ onClick : ( ) =>
107+ window . open (
108+ `${ ADMIN_URL } admin.php?page=wc-settings&tab=advanced` ,
109+ '_blank'
110+ ) ,
111+ } ,
112+ ! PRIVACY_URL && {
113+ className : 'wc-block-checkout__terms_notice-button' ,
114+ label : (
115+ < >
116+ { __ (
117+ 'Setup a Privacy Policy page' ,
118+ 'woo-gutenberg-products-block'
119+ ) }
120+ < Icon
121+ size = { 16 }
122+ icon = { external }
123+ className = "wc-block-checkout__terms_notice-button__icon"
124+ />
125+ </ >
126+ ) ,
127+ onClick : ( ) =>
128+ window . open (
129+ `${ ADMIN_URL } options-privacy.php` ,
130+ '_blank'
131+ ) ,
132+ } ,
133+ ] . filter ( Boolean ) }
95134 >
96135 < p >
97136 { __ (
98- 'Ensure you add links to your policy pages in this section.' ,
137+ "You don't seem to have a Terms and Conditions and/or a Privacy Policy pages setup." ,
99138 'woo-gutenberg-products-block'
100139 ) }
101140 </ p >
102141 </ Notice >
103142 ) }
143+ { /* Show this notice if we have both a terms and privacy pages, but they're not present in the text. */ }
144+ { TERMS_URL &&
145+ PRIVACY_URL &&
146+ ! (
147+ currentText . includes ( TERMS_URL ) &&
148+ currentText . includes ( PRIVACY_URL )
149+ ) && (
150+ < Notice
151+ className = "wc-block-checkout__terms_notice"
152+ status = "warning"
153+ isDismissible = { false }
154+ actions = {
155+ termsConsentDefaultText !== text
156+ ? [
157+ {
158+ label : __ (
159+ 'Restore default text' ,
160+ 'woo-gutenberg-products-block'
161+ ) ,
162+ onClick : ( ) =>
163+ setAttributes ( { text : '' } ) ,
164+ } ,
165+ ]
166+ : [ ]
167+ }
168+ >
169+ < p >
170+ { __ (
171+ 'Ensure you add links to your policy pages in this section.' ,
172+ 'woo-gutenberg-products-block'
173+ ) }
174+ </ p >
175+ </ Notice >
176+ ) }
104177 </ div >
105178 ) ;
106179} ;
0 commit comments