@automattic/newspack-blocks 1.53.0 → 1.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cache/babel/1783de595f21d427355e559781275222.json.gz +0 -0
- package/.cache/babel/2a75259638488d555bb07fb4f54ddde6.json.gz +0 -0
- package/.cache/babel/{64cb5afd808420a679c0d56e7bdb7949.json.gz → 2dfe70bf8fa9218857f45826e2386a32.json.gz} +0 -0
- package/.cache/babel/2ef414e63685642b486b71a962a5cc09.json.gz +0 -0
- package/.cache/babel/5a94cdb1154d1770a8b0e8cd3145825b.json.gz +0 -0
- package/.cache/babel/678cc0f373236434bf692c16d26ba22f.json.gz +0 -0
- package/.cache/babel/71371fcf9db60a3a1e024991cb3b4bf3.json.gz +0 -0
- package/.cache/babel/725e695c6992a4d01573b83867255ea9.json.gz +0 -0
- package/.cache/babel/94ee8f45c55ecf01005a435ab588333b.json.gz +0 -0
- package/.cache/babel/a5759fe1915229088160b7f5eb8a2e75.json.gz +0 -0
- package/.cache/babel/{bdebf548c146fe858685d50dd0ebd031.json.gz → be383af4530fd3521ee3db177be1bbf4.json.gz} +0 -0
- package/.cache/babel/d298f58c94d221b643c4c009ea0d8002.json.gz +0 -0
- package/.cache/babel/dc7e2d653dbbdbd1939aa281435afa5d.json.gz +0 -0
- package/.cache/babel/f50f27ba4b367318e30e91dbe003e5c8.json.gz +0 -0
- package/CHANGELOG.md +35 -0
- package/dist/author-profile/view.asset.php +1 -1
- package/dist/author-profile/view.css +1 -1
- package/dist/author-profile/view.rtl.css +1 -1
- package/dist/carousel/view.asset.php +1 -1
- package/dist/carousel/view.css +1 -1
- package/dist/carousel/view.js +1 -1
- package/dist/carousel/view.rtl.css +1 -1
- package/dist/donate/view.asset.php +1 -1
- package/dist/donate/view.css +1 -1
- package/dist/donate/view.rtl.css +1 -1
- package/dist/donateStreamlined.asset.php +1 -1
- package/dist/donateStreamlined.js +1 -1
- package/dist/editor.asset.php +1 -1
- package/dist/editor.css +1 -1
- package/dist/editor.js +5 -5
- package/dist/editor.rtl.css +1 -1
- package/dist/homepage-articles/view.asset.php +1 -1
- package/dist/homepage-articles/view.css +1 -1
- package/dist/homepage-articles/view.rtl.css +1 -1
- package/dist/placeholder_blocks.asset.php +1 -0
- package/dist/placeholder_blocks.js +1 -0
- package/includes/class-newspack-blocks-api.php +14 -12
- package/includes/class-newspack-blocks-patterns.php +3 -2
- package/includes/class-newspack-blocks.php +64 -1
- package/newspack-blocks.php +3 -2
- package/package.json +17 -16
- package/src/block-patterns/homepage-posts-14.php +1 -1
- package/src/block-patterns/homepage-posts-2.php +1 -1
- package/src/block-patterns/homepage-posts-26.php +1 -1
- package/src/block-patterns/homepage-posts-31.php +13 -0
- package/src/block-patterns/homepage-posts-7.php +1 -1
- package/src/block-styles/core/columns/editor.scss +10 -10
- package/src/block-styles/core/columns/view.scss +8 -8
- package/src/block-styles/core/group/editor.scss +3 -3
- package/src/block-styles/core/group/view.scss +3 -3
- package/src/blocks/author-list/editor.scss +1 -1
- package/src/blocks/author-profile/edit.js +29 -6
- package/src/blocks/author-profile/editor.scss +4 -3
- package/src/blocks/author-profile/view.scss +9 -9
- package/src/blocks/carousel/edit.js +31 -15
- package/src/blocks/carousel/editor.scss +1 -1
- package/src/blocks/carousel/view.php +94 -87
- package/src/blocks/carousel/view.scss +52 -13
- package/src/blocks/donate/block.json +49 -0
- package/src/blocks/donate/edit.tsx +569 -0
- package/src/blocks/donate/editor.scss +68 -8
- package/src/blocks/donate/index.js +8 -41
- package/src/blocks/donate/streamlined/style.scss +17 -17
- package/src/blocks/donate/view.php +226 -174
- package/src/blocks/donate/view.scss +97 -114
- package/src/blocks/homepage-articles/edit.js +28 -22
- package/src/blocks/homepage-articles/editor.scss +5 -5
- package/src/blocks/homepage-articles/templates/article.php +78 -73
- package/src/blocks/homepage-articles/utils.ts +1 -3
- package/src/blocks/homepage-articles/view.scss +68 -40
- package/src/blocks/iframe/edit.js +18 -14
- package/src/blocks/iframe/editor.scss +3 -3
- package/src/blocks/video-playlist/editor.scss +2 -2
- package/src/setup/editor.scss +46 -4
- package/src/setup/placeholder-blocks.js +83 -0
- package/src/shared/sass/_mixins.scss +7 -5
- package/src/types/@wordpress/block-editor.d.ts +1 -0
- package/src/types/@wordpress/components.d.ts +1 -0
- package/src/types/{index.ts → index.d.ts} +5 -1
- package/src/types/newspack-components.d.ts +7 -0
- package/vendor/autoload.php +1 -1
- package/vendor/composer/autoload_real.php +4 -4
- package/vendor/composer/autoload_static.php +2 -2
- package/vendor/composer/installed.php +2 -2
- package/webpack.config.js +4 -0
- package/.cache/babel/07169c73863508b392f15022920bd0b6.json.gz +0 -0
- package/.cache/babel/10faf7c74a89e9aa4d8b9528a654913e.json.gz +0 -0
- package/.cache/babel/3fc03f1e35bc1fde55a903cf25d74d3d.json.gz +0 -0
- package/.cache/babel/553094e2be86910f765ad110c8da1ba1.json.gz +0 -0
- package/.cache/babel/55dd64fbb5126117016b9edff26ca5ee.json.gz +0 -0
- package/.cache/babel/7cbfe1b298fdc2a21add34363b2a6046.json.gz +0 -0
- package/.cache/babel/95c79f7af2e88cb1c48e88f304b1a1fd.json.gz +0 -0
- package/.cache/babel/ac3be6086bb961d3a94ba6ba7728901c.json.gz +0 -0
- package/.cache/babel/c9354785521531ea2b4a9a8c2f526abf.json.gz +0 -0
- package/.cache/babel/ca34d0586d4fbcd06c357ff72bda9a19.json.gz +0 -0
- package/.cache/babel/edb4dcd474dbafd6ea1655b24469e261.json.gz +0 -0
- package/src/blocks/donate/edit.js +0 -587
|
@@ -1,587 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { __, sprintf } from '@wordpress/i18n';
|
|
10
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
11
|
-
import { Component } from '@wordpress/element';
|
|
12
|
-
import {
|
|
13
|
-
PanelBody,
|
|
14
|
-
ExternalLink,
|
|
15
|
-
Placeholder,
|
|
16
|
-
Spinner,
|
|
17
|
-
SelectControl,
|
|
18
|
-
TextControl,
|
|
19
|
-
ToggleControl,
|
|
20
|
-
} from '@wordpress/components';
|
|
21
|
-
import { InspectorControls, RichText } from '@wordpress/block-editor';
|
|
22
|
-
|
|
23
|
-
class Edit extends Component {
|
|
24
|
-
constructor( props ) {
|
|
25
|
-
super( props );
|
|
26
|
-
this.state = {
|
|
27
|
-
suggestedAmounts: [ 0, 0, 0 ],
|
|
28
|
-
suggestedAmountUntiered: 0,
|
|
29
|
-
currencySymbol: '$',
|
|
30
|
-
tiered: false,
|
|
31
|
-
created: false,
|
|
32
|
-
|
|
33
|
-
isLoading: false,
|
|
34
|
-
activeTier: 1,
|
|
35
|
-
customDonationAmounts: {
|
|
36
|
-
once: 0,
|
|
37
|
-
month: 0,
|
|
38
|
-
year: 0,
|
|
39
|
-
},
|
|
40
|
-
error: '',
|
|
41
|
-
uid: Math.random().toString( 16 ).slice( 2 ), // Unique identifier to prevent collisions with other Donate blocks' labels.
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
componentDidMount() {
|
|
45
|
-
this.getSettings();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
componentDidUpdate( prevProps ) {
|
|
49
|
-
const { selectedFrequency } = this.state;
|
|
50
|
-
const { attributes } = this.props;
|
|
51
|
-
const { attributes: prevAttributes } = prevProps;
|
|
52
|
-
if ( ! selectedFrequency || attributes.defaultFrequency !== prevAttributes.defaultFrequency ) {
|
|
53
|
-
this.setState( { selectedFrequency: attributes.defaultFrequency } );
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/* If block is in "manual" mode, override certain state properties with values stored in attributes */
|
|
58
|
-
blockData() {
|
|
59
|
-
const { attributes } = this.props;
|
|
60
|
-
const { defaultFrequency, manual, campaign } = attributes;
|
|
61
|
-
const data = { ...this.state, ...( manual ? attributes : { defaultFrequency } ) };
|
|
62
|
-
if ( manual ) {
|
|
63
|
-
data.customDonationAmounts = {
|
|
64
|
-
once: data.tiered ? 12 * data.suggestedAmounts[ 1 ] : 12 * data.suggestedAmountUntiered,
|
|
65
|
-
month: data.tiered ? data.suggestedAmounts[ 1 ] : data.suggestedAmountUntiered,
|
|
66
|
-
year: data.tiered ? 12 * data.suggestedAmounts[ 1 ] : 12 * data.suggestedAmountUntiered,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
data.campaign = campaign;
|
|
70
|
-
return data;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
isRenderingStreamlinedBlock() {
|
|
74
|
-
return window.newspack_blocks_data?.is_rendering_streamlined_block;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
sanitizeCurrencyInput = amount => Math.max( 0, parseFloat( amount ).toFixed( 2 ) );
|
|
78
|
-
|
|
79
|
-
formatCurrencyWithoutSymbol = amount => {
|
|
80
|
-
const decimalPlaces = parseFloat( amount ) - parseInt( amount ) ? 2 : 0;
|
|
81
|
-
return parseFloat( amount ).toFixed( decimalPlaces );
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
formatCurrency = amount => {
|
|
85
|
-
const { currencySymbol } = this.blockData();
|
|
86
|
-
return currencySymbol + this.formatCurrencyWithoutSymbol( amount );
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
manualChanged = value => {
|
|
90
|
-
const { attributes, setAttributes } = this.props;
|
|
91
|
-
const { suggestedAmounts, suggestedAmountUntiered } = attributes;
|
|
92
|
-
setAttributes( { manual: value } );
|
|
93
|
-
if (
|
|
94
|
-
value &&
|
|
95
|
-
0 === suggestedAmountUntiered &&
|
|
96
|
-
0 === suggestedAmounts[ 0 ] &&
|
|
97
|
-
0 === suggestedAmounts[ 1 ] &&
|
|
98
|
-
0 === suggestedAmounts[ 2 ]
|
|
99
|
-
) {
|
|
100
|
-
setAttributes( {
|
|
101
|
-
suggestedAmounts: [
|
|
102
|
-
this.sanitizeCurrencyInput( this.state.suggestedAmounts[ 0 ] ),
|
|
103
|
-
this.sanitizeCurrencyInput( this.state.suggestedAmounts[ 1 ] ),
|
|
104
|
-
this.sanitizeCurrencyInput( this.state.suggestedAmounts[ 2 ] ),
|
|
105
|
-
],
|
|
106
|
-
suggestedAmountUntiered: this.sanitizeCurrencyInput( this.state.suggestedAmountUntiered ),
|
|
107
|
-
} );
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
getSettings() {
|
|
112
|
-
const path = '/newspack/v1/wizard/newspack-donations-wizard/donation';
|
|
113
|
-
|
|
114
|
-
this.setState( { isLoading: true }, () => {
|
|
115
|
-
apiFetch( { path } )
|
|
116
|
-
.then( settings => {
|
|
117
|
-
const {
|
|
118
|
-
suggestedAmounts,
|
|
119
|
-
suggestedAmountUntiered,
|
|
120
|
-
currencySymbol,
|
|
121
|
-
tiered,
|
|
122
|
-
created,
|
|
123
|
-
} = settings;
|
|
124
|
-
this.setState( {
|
|
125
|
-
suggestedAmounts,
|
|
126
|
-
suggestedAmountUntiered,
|
|
127
|
-
currencySymbol,
|
|
128
|
-
tiered,
|
|
129
|
-
created,
|
|
130
|
-
isLoading: false,
|
|
131
|
-
customDonationAmounts: {
|
|
132
|
-
once: tiered ? 12 * suggestedAmounts[ 1 ] : 12 * suggestedAmountUntiered,
|
|
133
|
-
month: tiered ? suggestedAmounts[ 1 ] : suggestedAmountUntiered,
|
|
134
|
-
year: tiered ? 12 * suggestedAmounts[ 1 ] : 12 * suggestedAmountUntiered,
|
|
135
|
-
},
|
|
136
|
-
activeTier: 1,
|
|
137
|
-
} );
|
|
138
|
-
} )
|
|
139
|
-
.catch( error => {
|
|
140
|
-
this.setState( {
|
|
141
|
-
isLoading: false,
|
|
142
|
-
error: error.message,
|
|
143
|
-
} );
|
|
144
|
-
} );
|
|
145
|
-
} );
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
handleCustomDonationChange( evt, frequency ) {
|
|
149
|
-
const { customDonationAmounts } = this.state;
|
|
150
|
-
customDonationAmounts[ frequency ] = evt.target.value;
|
|
151
|
-
this.setState( { customDonationAmounts } );
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
renderUntieredForm() {
|
|
155
|
-
const { className } = this.props;
|
|
156
|
-
const { uid } = this.state;
|
|
157
|
-
const { currencySymbol, customDonationAmounts, selectedFrequency } = this.blockData();
|
|
158
|
-
|
|
159
|
-
const frequencies = {
|
|
160
|
-
once: __( 'One-time', 'newspack-blocks' ),
|
|
161
|
-
month: __( 'Monthly', 'newspack-blocks' ),
|
|
162
|
-
year: __( 'Annually', 'newspack-blocks' ),
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<div className={ classNames( className, 'untiered wpbnbd' ) }>
|
|
167
|
-
<form>
|
|
168
|
-
<div className="wp-block-newspack-blocks-donate__options">
|
|
169
|
-
{ Object.keys( frequencies ).map( frequencySlug => (
|
|
170
|
-
<div
|
|
171
|
-
className="wp-block-newspack-blocks-donate__frequency frequency"
|
|
172
|
-
key={ frequencySlug }
|
|
173
|
-
>
|
|
174
|
-
<input
|
|
175
|
-
type="radio"
|
|
176
|
-
onClick={ () => this.setState( { selectedFrequency: frequencySlug } ) }
|
|
177
|
-
id={ 'newspack-donate-' + frequencySlug + '-' + uid }
|
|
178
|
-
name="donation_frequency"
|
|
179
|
-
checked={ frequencySlug === selectedFrequency }
|
|
180
|
-
/>
|
|
181
|
-
<label
|
|
182
|
-
htmlFor={ 'newspack-donate-' + frequencySlug + '-' + uid }
|
|
183
|
-
className="donation-frequency-label freq-label"
|
|
184
|
-
>
|
|
185
|
-
{ frequencies[ frequencySlug ] }
|
|
186
|
-
</label>
|
|
187
|
-
<div className="input-container">
|
|
188
|
-
<label
|
|
189
|
-
className="donate-label"
|
|
190
|
-
htmlFor={ 'newspack-' + frequencySlug + '-' + uid + '-untiered-input' }
|
|
191
|
-
>
|
|
192
|
-
{ __( 'Donation amount', 'newspack-blocks' ) }
|
|
193
|
-
</label>
|
|
194
|
-
<div className="wp-block-newspack-blocks-donate__money-input money-input">
|
|
195
|
-
<span className="currency">{ currencySymbol }</span>
|
|
196
|
-
<input
|
|
197
|
-
type="number"
|
|
198
|
-
onChange={ evt => this.handleCustomDonationChange( evt, frequencySlug ) }
|
|
199
|
-
value={ this.formatCurrencyWithoutSymbol(
|
|
200
|
-
customDonationAmounts[ frequencySlug ]
|
|
201
|
-
) }
|
|
202
|
-
id={ 'newspack-' + frequencySlug + '-' + uid + '-untiered-input' }
|
|
203
|
-
/>
|
|
204
|
-
</div>
|
|
205
|
-
</div>
|
|
206
|
-
</div>
|
|
207
|
-
) ) }
|
|
208
|
-
</div>
|
|
209
|
-
{ this.renderFooter() }
|
|
210
|
-
</form>
|
|
211
|
-
</div>
|
|
212
|
-
);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
renderTieredForm() {
|
|
216
|
-
const { className } = this.props;
|
|
217
|
-
const { uid } = this.state;
|
|
218
|
-
const {
|
|
219
|
-
activeTier,
|
|
220
|
-
currencySymbol,
|
|
221
|
-
customDonationAmounts,
|
|
222
|
-
selectedFrequency,
|
|
223
|
-
suggestedAmounts,
|
|
224
|
-
} = this.blockData();
|
|
225
|
-
|
|
226
|
-
const frequencies = {
|
|
227
|
-
once: __( 'One-time', 'newspack-blocks' ),
|
|
228
|
-
month: __( 'Monthly', 'newspack-blocks' ),
|
|
229
|
-
year: __( 'Annually', 'newspack-blocks' ),
|
|
230
|
-
};
|
|
231
|
-
return (
|
|
232
|
-
<div className={ classNames( className, 'tiered wpbnbd' ) }>
|
|
233
|
-
<form>
|
|
234
|
-
<div className="wp-block-newspack-blocks-donate__options">
|
|
235
|
-
<div className="wp-block-newspack-blocks-donate__frequencies frequencies">
|
|
236
|
-
{ Object.keys( frequencies ).map( frequencySlug => (
|
|
237
|
-
<div
|
|
238
|
-
className="wp-block-newspack-blocks-donate__frequency frequency"
|
|
239
|
-
key={ frequencySlug }
|
|
240
|
-
>
|
|
241
|
-
<input
|
|
242
|
-
type="radio"
|
|
243
|
-
onClick={ () => this.setState( { selectedFrequency: frequencySlug } ) }
|
|
244
|
-
id={ 'newspack-donate-' + frequencySlug + '-' + uid }
|
|
245
|
-
name="donation_frequency"
|
|
246
|
-
checked={ frequencySlug === selectedFrequency }
|
|
247
|
-
/>
|
|
248
|
-
<label
|
|
249
|
-
htmlFor={ 'newspack-donate-' + frequencySlug + '-' + uid }
|
|
250
|
-
className="donation-frequency-label freq-label"
|
|
251
|
-
>
|
|
252
|
-
{ frequencies[ frequencySlug ] }
|
|
253
|
-
</label>
|
|
254
|
-
|
|
255
|
-
<div className="wp-block-newspack-blocks-donate__tiers tiers">
|
|
256
|
-
{ suggestedAmounts.map( ( suggestedAmount, index ) => (
|
|
257
|
-
<div className="wp-block-newspack-blocks-donate__tier" key={ index }>
|
|
258
|
-
<input
|
|
259
|
-
type="radio"
|
|
260
|
-
onClick={ () => this.setState( { activeTier: index } ) }
|
|
261
|
-
id={ 'newspack-tier-' + frequencySlug + '-' + uid + '-' + index }
|
|
262
|
-
checked={ index === activeTier }
|
|
263
|
-
/>
|
|
264
|
-
<label
|
|
265
|
-
className="tier-select-label tier-label"
|
|
266
|
-
htmlFor={ 'newspack-tier-' + frequencySlug + '-' + uid + '-' + index }
|
|
267
|
-
>
|
|
268
|
-
{ this.formatCurrency(
|
|
269
|
-
'year' === frequencySlug || 'once' === frequencySlug
|
|
270
|
-
? 12 * suggestedAmount
|
|
271
|
-
: suggestedAmount
|
|
272
|
-
) }
|
|
273
|
-
</label>
|
|
274
|
-
</div>
|
|
275
|
-
) ) }
|
|
276
|
-
|
|
277
|
-
<div className="wp-block-newspack-blocks-donate__tier">
|
|
278
|
-
<input
|
|
279
|
-
type="radio"
|
|
280
|
-
onClick={ () => this.setState( { activeTier: 'other' } ) }
|
|
281
|
-
className="other-input"
|
|
282
|
-
id={ 'newspack-tier-' + frequencySlug + '-' + uid + '-other' }
|
|
283
|
-
checked={ 'other' === activeTier }
|
|
284
|
-
/>
|
|
285
|
-
<label
|
|
286
|
-
className="tier-select-label tier-label"
|
|
287
|
-
htmlFor={ 'newspack-tier-' + frequencySlug + '-' + uid + '-other' }
|
|
288
|
-
>
|
|
289
|
-
{ __( 'Other', 'newspack-blocks' ) }
|
|
290
|
-
</label>
|
|
291
|
-
<label
|
|
292
|
-
className="other-donate-label odl"
|
|
293
|
-
htmlFor={ 'newspack-tier-' + frequencySlug + '-' + uid + '-other-input' }
|
|
294
|
-
>
|
|
295
|
-
{ __( 'Donation amount', 'newspack-blocks' ) }
|
|
296
|
-
</label>
|
|
297
|
-
<div className="wp-block-newspack-blocks-donate__money-input money-input">
|
|
298
|
-
<span className="currency">{ currencySymbol }</span>
|
|
299
|
-
<input
|
|
300
|
-
type="number"
|
|
301
|
-
onChange={ evt => this.handleCustomDonationChange( evt, frequencySlug ) }
|
|
302
|
-
value={ customDonationAmounts[ frequencySlug ] }
|
|
303
|
-
id={ 'newspack-tier-' + frequencySlug + '-' + uid + '-other-input' }
|
|
304
|
-
/>
|
|
305
|
-
</div>
|
|
306
|
-
</div>
|
|
307
|
-
</div>
|
|
308
|
-
</div>
|
|
309
|
-
) ) }
|
|
310
|
-
</div>
|
|
311
|
-
</div>
|
|
312
|
-
{ this.renderFooter() }
|
|
313
|
-
</form>
|
|
314
|
-
</div>
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
renderButton() {
|
|
319
|
-
const { attributes, setAttributes } = this.props;
|
|
320
|
-
const { buttonText } = attributes;
|
|
321
|
-
return (
|
|
322
|
-
<button type="submit" onClick={ evt => evt.preventDefault() }>
|
|
323
|
-
{ this.isRenderingStreamlinedBlock() ? (
|
|
324
|
-
__( 'Donate with card', 'newspack-blocks' )
|
|
325
|
-
) : (
|
|
326
|
-
<RichText
|
|
327
|
-
onChange={ value => setAttributes( { buttonText: value } ) }
|
|
328
|
-
placeholder={ __( 'Button text…', 'newspack-blocks' ) }
|
|
329
|
-
value={ buttonText }
|
|
330
|
-
tagName="span"
|
|
331
|
-
/>
|
|
332
|
-
) }
|
|
333
|
-
</button>
|
|
334
|
-
);
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
renderFooter() {
|
|
338
|
-
const { attributes, setAttributes } = this.props;
|
|
339
|
-
const { thanksText } = attributes;
|
|
340
|
-
return (
|
|
341
|
-
<>
|
|
342
|
-
<p className="wp-block-newspack-blocks-donate__thanks thanks">
|
|
343
|
-
<RichText
|
|
344
|
-
onChange={ value => setAttributes( { thanksText: value } ) }
|
|
345
|
-
placeholder={ __( 'Thank you text…', 'newspack-blocks' ) }
|
|
346
|
-
value={ thanksText }
|
|
347
|
-
tagName="span"
|
|
348
|
-
/>
|
|
349
|
-
</p>
|
|
350
|
-
{ this.isRenderingStreamlinedBlock() ? (
|
|
351
|
-
<div className="wp-block-newspack-blocks-donate__stripe stripe-payment">
|
|
352
|
-
<div className="stripe-payment__row stripe-payment__row--flex stripe-payment__footer">
|
|
353
|
-
<div className="stripe-payment__methods">
|
|
354
|
-
<div className="stripe-payment__request-button">
|
|
355
|
-
{ __( 'Apple/Google Pay Button', 'newspack-blocks' ) }
|
|
356
|
-
</div>
|
|
357
|
-
{ this.renderButton() }
|
|
358
|
-
</div>
|
|
359
|
-
<a
|
|
360
|
-
target="_blank"
|
|
361
|
-
rel="noreferrer"
|
|
362
|
-
className="stripe-payment__branding"
|
|
363
|
-
href="https://stripe.com"
|
|
364
|
-
>
|
|
365
|
-
<img
|
|
366
|
-
width="111"
|
|
367
|
-
height="26"
|
|
368
|
-
src={ window.newspack_blocks_data?.streamlined_block_stripe_badge }
|
|
369
|
-
alt="Stripe"
|
|
370
|
-
/>
|
|
371
|
-
</a>
|
|
372
|
-
</div>
|
|
373
|
-
</div>
|
|
374
|
-
) : (
|
|
375
|
-
this.renderButton()
|
|
376
|
-
) }
|
|
377
|
-
</>
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
renderPlaceholder() {
|
|
382
|
-
const { created, error, isLoading, manual } = this.blockData();
|
|
383
|
-
|
|
384
|
-
if ( manual ) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
if ( isLoading ) {
|
|
388
|
-
return <Placeholder icon={ <Spinner /> } className="component-placeholder__align-center" />;
|
|
389
|
-
}
|
|
390
|
-
if ( error.length ) {
|
|
391
|
-
return (
|
|
392
|
-
<Placeholder
|
|
393
|
-
icon="warning"
|
|
394
|
-
label={ __( 'Error', 'newspack-blocks' ) }
|
|
395
|
-
instructions={ error }
|
|
396
|
-
>
|
|
397
|
-
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
|
|
398
|
-
{ __( 'Go to donation settings to troubleshoot.', 'newspack-blocks' ) }
|
|
399
|
-
</ExternalLink>
|
|
400
|
-
</Placeholder>
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
if ( ! created ) {
|
|
404
|
-
return (
|
|
405
|
-
<Placeholder
|
|
406
|
-
icon="warning"
|
|
407
|
-
label={ __( 'Not ready', 'newspack-blocks' ) }
|
|
408
|
-
instructions={ __(
|
|
409
|
-
'You have not set up your donation settings yet. You need to do that before you can use the Donate Block.',
|
|
410
|
-
'newspack-blocks'
|
|
411
|
-
) }
|
|
412
|
-
>
|
|
413
|
-
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
|
|
414
|
-
{ __( 'Set up donation settings.', 'newspack-blocks' ) }
|
|
415
|
-
</ExternalLink>
|
|
416
|
-
</Placeholder>
|
|
417
|
-
);
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
renderForm() {
|
|
422
|
-
const { created, error, manual, tiered } = this.blockData();
|
|
423
|
-
if ( ! manual && ( error.length || ! created ) ) {
|
|
424
|
-
return null;
|
|
425
|
-
}
|
|
426
|
-
return tiered ? this.renderTieredForm() : this.renderUntieredForm();
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
renderManualControls() {
|
|
430
|
-
const { setAttributes } = this.props;
|
|
431
|
-
const { currencySymbol, suggestedAmounts, suggestedAmountUntiered, tiered } = this.blockData();
|
|
432
|
-
return (
|
|
433
|
-
<>
|
|
434
|
-
<ToggleControl
|
|
435
|
-
key="tiered"
|
|
436
|
-
checked={ tiered }
|
|
437
|
-
onChange={ value => setAttributes( { tiered: value } ) }
|
|
438
|
-
label={ __( 'Tiered', 'newspack-blocks' ) }
|
|
439
|
-
/>
|
|
440
|
-
{ tiered && (
|
|
441
|
-
<>
|
|
442
|
-
<TextControl
|
|
443
|
-
key="low-tier"
|
|
444
|
-
/* Translators: %s: the symbol for the current currency */
|
|
445
|
-
label={ sprintf( __( 'Low-tier (%s)' ), currencySymbol ) }
|
|
446
|
-
type="number"
|
|
447
|
-
step="0.01"
|
|
448
|
-
value={ suggestedAmounts[ 0 ] }
|
|
449
|
-
onChange={ value =>
|
|
450
|
-
setAttributes( {
|
|
451
|
-
suggestedAmounts: [
|
|
452
|
-
this.sanitizeCurrencyInput( value ),
|
|
453
|
-
suggestedAmounts[ 1 ],
|
|
454
|
-
suggestedAmounts[ 2 ],
|
|
455
|
-
],
|
|
456
|
-
} )
|
|
457
|
-
}
|
|
458
|
-
/>
|
|
459
|
-
<TextControl
|
|
460
|
-
key="mid-tier"
|
|
461
|
-
/* Translators: %s: the symbol for the current currency */
|
|
462
|
-
label={ sprintf( __( 'Mid-tier (%s)' ), currencySymbol ) }
|
|
463
|
-
type="number"
|
|
464
|
-
step="0.01"
|
|
465
|
-
value={ suggestedAmounts[ 1 ] }
|
|
466
|
-
onChange={ value =>
|
|
467
|
-
setAttributes( {
|
|
468
|
-
suggestedAmounts: [
|
|
469
|
-
suggestedAmounts[ 0 ],
|
|
470
|
-
this.sanitizeCurrencyInput( value ),
|
|
471
|
-
suggestedAmounts[ 2 ],
|
|
472
|
-
],
|
|
473
|
-
} )
|
|
474
|
-
}
|
|
475
|
-
/>
|
|
476
|
-
<TextControl
|
|
477
|
-
key="hi-tier"
|
|
478
|
-
label={ __( 'Hi-tier' ) + ' (' + currencySymbol + ')' }
|
|
479
|
-
type="number"
|
|
480
|
-
step="0.01"
|
|
481
|
-
value={ suggestedAmounts[ 2 ] }
|
|
482
|
-
onChange={ value =>
|
|
483
|
-
setAttributes( {
|
|
484
|
-
suggestedAmounts: [
|
|
485
|
-
suggestedAmounts[ 0 ],
|
|
486
|
-
suggestedAmounts[ 1 ],
|
|
487
|
-
this.sanitizeCurrencyInput( value ),
|
|
488
|
-
],
|
|
489
|
-
} )
|
|
490
|
-
}
|
|
491
|
-
/>
|
|
492
|
-
</>
|
|
493
|
-
) }
|
|
494
|
-
{ ! tiered && (
|
|
495
|
-
<TextControl
|
|
496
|
-
key="suggestedAmountUntiered"
|
|
497
|
-
label={ __( 'Suggested donation amount per month' ) + ' (' + currencySymbol + ')' }
|
|
498
|
-
type="number"
|
|
499
|
-
step="0.01"
|
|
500
|
-
value={ suggestedAmountUntiered }
|
|
501
|
-
onChange={ value =>
|
|
502
|
-
setAttributes( {
|
|
503
|
-
suggestedAmountUntiered: this.sanitizeCurrencyInput( value ),
|
|
504
|
-
} )
|
|
505
|
-
}
|
|
506
|
-
/>
|
|
507
|
-
) }
|
|
508
|
-
</>
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
render() {
|
|
513
|
-
const { setAttributes } = this.props;
|
|
514
|
-
const { manual, campaign, defaultFrequency } = this.blockData();
|
|
515
|
-
return (
|
|
516
|
-
<>
|
|
517
|
-
{ this.renderPlaceholder() }
|
|
518
|
-
{ this.renderForm() }
|
|
519
|
-
<InspectorControls>
|
|
520
|
-
<PanelBody title={ __( 'Donate Settings', 'newspack-blocks' ) }>
|
|
521
|
-
<SelectControl
|
|
522
|
-
label={ __( 'Default Tab', 'newspack' ) }
|
|
523
|
-
value={ defaultFrequency }
|
|
524
|
-
options={ [
|
|
525
|
-
{
|
|
526
|
-
label: __( 'One-time', 'newspack' ),
|
|
527
|
-
value: 'once',
|
|
528
|
-
},
|
|
529
|
-
{
|
|
530
|
-
label: __( 'Monthly', 'newspack' ),
|
|
531
|
-
value: 'month',
|
|
532
|
-
},
|
|
533
|
-
{
|
|
534
|
-
label: __( 'Annually', 'newspack' ),
|
|
535
|
-
value: 'year',
|
|
536
|
-
},
|
|
537
|
-
] }
|
|
538
|
-
onChange={ _defaultFrequency => {
|
|
539
|
-
setAttributes( {
|
|
540
|
-
defaultFrequency: _defaultFrequency,
|
|
541
|
-
} );
|
|
542
|
-
} }
|
|
543
|
-
/>
|
|
544
|
-
<ToggleControl
|
|
545
|
-
key="manual"
|
|
546
|
-
checked={ manual }
|
|
547
|
-
onChange={ this.manualChanged }
|
|
548
|
-
label={ __( 'Configure manually', 'newspack-blocks' ) }
|
|
549
|
-
/>
|
|
550
|
-
{ ! manual && (
|
|
551
|
-
<>
|
|
552
|
-
<p>
|
|
553
|
-
{ __(
|
|
554
|
-
'The Donate Block allows you to collect donations from readers. The fields are automatically defined based on your donation settings.',
|
|
555
|
-
'newspack-blocks'
|
|
556
|
-
) }
|
|
557
|
-
</p>
|
|
558
|
-
|
|
559
|
-
<ExternalLink href="/wp-admin/admin.php?page=newspack-reader-revenue-wizard#/donations">
|
|
560
|
-
{ __( 'Edit donation setting', 'newspack-blocks' ) }
|
|
561
|
-
</ExternalLink>
|
|
562
|
-
</>
|
|
563
|
-
) }
|
|
564
|
-
</PanelBody>
|
|
565
|
-
{ manual && (
|
|
566
|
-
<PanelBody title={ __( 'Donation Amount', 'newspack-blocks' ) }>
|
|
567
|
-
{ this.renderManualControls() }
|
|
568
|
-
</PanelBody>
|
|
569
|
-
) }
|
|
570
|
-
<PanelBody title={ __( 'Campaign', 'newspack-blocks' ) } initialOpen={ false }>
|
|
571
|
-
<TextControl
|
|
572
|
-
label={ __( 'Campaign ID', 'newspack-blocks' ) }
|
|
573
|
-
value={ campaign ? campaign : '' }
|
|
574
|
-
onChange={ value =>
|
|
575
|
-
setAttributes( {
|
|
576
|
-
campaign: value,
|
|
577
|
-
} )
|
|
578
|
-
}
|
|
579
|
-
/>
|
|
580
|
-
</PanelBody>
|
|
581
|
-
</InspectorControls>
|
|
582
|
-
</>
|
|
583
|
-
);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
export default Edit;
|