Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit a3dd4b8

Browse files
committed
Checkout i2: Show a notice if terms and conditions page (#4859)
* Make Terms block insertable * add a notice to setup pages * push updated error design in editor * fix default text
1 parent 79763ca commit a3dd4b8

File tree

4 files changed

+103
-21
lines changed

4 files changed

+103
-21
lines changed

assets/js/blocks/cart-checkout/checkout/inner-blocks/checkout-terms-block/block.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"align": false,
99
"html": false,
1010
"multiple": false,
11-
"reusable": false,
12-
"inserter": false
11+
"reusable": false
1312
},
1413
"attributes": {
1514
"checkbox": {

assets/js/blocks/cart-checkout/checkout/inner-blocks/checkout-terms-block/edit.tsx

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import {
99
} from '@wordpress/block-editor';
1010
import CheckboxControl from '@woocommerce/base-components/checkbox-control';
1111
import { 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
};

assets/js/blocks/cart-checkout/checkout/inner-blocks/checkout-terms-block/editor.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,14 @@
1919
.wc-block-checkout__terms_notice .components-notice__action {
2020
margin-left: 0;
2121
}
22+
23+
.wc-block-checkout__terms_notice-button {
24+
display: flex;
25+
flex-direction: row;
26+
align-items: center;
27+
28+
.wc-block-checkout__terms_notice-button__icon {
29+
margin-left: $gap-smallest;
30+
}
31+
}
32+

assets/js/editor-components/external-link-card/editor.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.wc-block-editor-components-external-link-card {
2-
display: block;
32
display: flex;
43
flex-direction: row;
54
text-decoration: none;

0 commit comments

Comments
 (0)