PluginProbe
MailerLite – WooCommerce integration / 3.1.20
MailerLite – WooCommerce integration v3.1.20
3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 All 147 releases
woo-mailerlite / admin / assets / views / BlocksCheckout / MailerLiteBlock.js

MailerLiteBlock.js in MailerLite – WooCommerce integration 3.1.20, at admin/assets/views/BlocksCheckout/MailerLiteBlock.js

228 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function ( blocks, element, i18n, blocksCheckout, blockEditor, components,settings, ajax, wpData ) {
2
3 const { CheckboxControl } = blocksCheckout
4 const { useState } = element
5 const { useBlockProps, InspectorControls} = blockEditor || {}
6 const { PanelBody, ToggleControl } = components || {}
7 const { getSetting } = settings
8 const innerBlock = 'mailerlite-block/woo-mailerlite'
9
10 const icon = element.createElement('svg',
11 {
12 width: 21,
13 height: 21,
14 viewBox: '0 0 21 21'
15 },
16 element.createElement( 'g',
17 {
18 id: 'Page-1',
19 stroke: 'none',
20 strokeWidth: 1,
21 fill: 'none',
22 fillRule: 'evenodd'
23 },
24 element.createElement( 'g',
25 {
26 id: 'mailerlitelogo',
27 transform: 'translate(0.198319, 0.325455)',
28 fill: '#09C269',
29 fillRule: 'nonzero'
30 },
31 element.createElement( 'path',
32 {
33 id: 'Shape-path',
34 d: "M17.2807581,0.115646258 L2.78853487,0.115646258 C1.28807741,0.115646258 0.0437956203,1.34864717 0.0437956203,2.8355012 L0.0437956203,11.9016843 L0.0437956203,13.6786562 L0.0437956203,20.1156463 L3.83153579,16.3985111 L17.2990564,16.3985111 C18.7995138,16.3985111 20.0437956,15.1655103 20.0437956,13.6786562 L20.0437956,2.8355012 C20.0254974,1.3305148 18.7995138,0.115646258 17.2807581,0.115646258 Z"
35 }
36 )
37 )
38 )
39 );
40
41 const {
42 __
43 } = i18n;
44
45 const el = element.createElement;
46
47 const {
48 MailerLiteWooActive,
49 MailerLiteWooLabel,
50 MailerLiteWooPreselect,
51 MailerLiteWooHidden,
52 MailerLiteNonce,
53 MailerLiteAdminURL,
54 } = getSetting( 'woo-mailerlite_data', '' );
55
56 blocks.registerBlockType( innerBlock, {
57
58 title: __('MailerLite – WooCommerce integration', 'woo-mailerlite'),
59 icon: icon,
60 description: 'Allows checkout integration with MailerLite.',
61 supports: {
62 multiple: false,
63 reusable: false
64 },
65 category: "woocommerce",
66 parent: [
67 'woocommerce/checkout-totals-block',
68 'woocommerce/checkout-fields-block',
69 'woocommerce/checkout-contact-information-block',
70 'woocommerce/checkout-shipping-address-block',
71 'woocommerce/checkout-billing-address-block',
72 'woocommerce/checkout-shipping-methods-block',
73 'woocommerce/checkout-payment-methods-block',
74 ],
75
76 attributes: {
77 preSelect: {
78 type: 'bool',
79 default: MailerLiteWooPreselect,
80 },
81 blockLabel: {
82 type: 'string',
83 default: MailerLiteWooLabel,
84 },
85 blockActive: {
86 type: 'bool',
87 default: MailerLiteWooActive,
88 },
89 blockHidden: {
90 type: 'bool',
91 default: MailerLiteWooHidden,
92 }
93 },
94
95 edit: function ( props ) {
96
97 const [ checked, setChecked ] = useState( props.attributes.preSelect )
98 const [ checkedHidden, setHiddenChecked ] = useState( props.attributes.blockHidden )
99 const blockProps = useBlockProps()
100
101 function updateChecked( isChecked ) {
102
103 ajax.post(
104 'woo_ml_admin_ajax_update_preselect_checkbox',
105 {
106 preselect: isChecked,
107 _wpnonce: MailerLiteNonce,
108 }
109 ).done(function(response) {
110 // success
111 setChecked(isChecked)
112
113 props.setAttributes({
114 'preSelect': isChecked
115 })
116 }).fail(function(xhr, status, err) {
117
118 wpData.dispatch("core/notices").createNotice(
119 'error',
120 'Could not update settings.',
121 {
122 isDismissible: true
123 }
124 )
125 })
126 }
127
128 function updateHiddenChecked( isChecked ) {
129
130 ajax.post(
131 'woo_ml_admin_ajax_update_hide_checkbox',
132 {
133 hidden: isChecked,
134 _wpnonce: MailerLiteNonce,
135 }
136 ).done(function(response) {
137 // success
138 setHiddenChecked(isChecked)
139
140 props.setAttributes({
141 'blockHidden': isChecked
142 })
143 }).fail(function(xhr, status, err) {
144
145 wpData.dispatch("core/notices").createNotice(
146 'error',
147 'Could not update settings.',
148 {
149 isDismissible: true
150 }
151 )
152 })
153 }
154
155 function MailerLiteCheckbox() {
156 return el(
157 CheckboxControl,
158 {
159 label: props.attributes.blockLabel,
160 checked: props.attributes.preSelect,
161 disabled: true,
162 readOnly: true,
163 }
164 )
165 }
166
167 function MailerliteHiddenCheckbox() {
168 return el(
169 'p',
170 {},
171 __('[ Placeholder for the hidden MailerLite checkbox ]', 'woo-mailerlite')
172 )
173 }
174
175 return(el('div', { ...blockProps },
176 el(
177 InspectorControls,
178 {},
179 el(
180 PanelBody,
181 {
182 title: __('Settings', 'woo-mailerlite'),
183 },
184 el(
185 ToggleControl,
186 {
187 label: 'Preselect checkbox',
188 help: 'Check to preselect the signup checkbox by default',
189 checked: checked,
190 onChange: updateChecked,
191 }
192 ),
193 el(
194 ToggleControl,
195 {
196 label: 'Hide checkbox',
197 help: 'Check to hide the checkbox. All customers will be subscribed automatically',
198 checked: checkedHidden,
199 onChange: updateHiddenChecked,
200 }
201 ),
202 el(
203 'p',
204 {},
205 'For additional settings click ',
206 el(
207 'a',
208 {
209 href: MailerLiteAdminURL,
210 },
211 'here'
212 )
213 )
214 ),
215 ),
216 checkedHidden ? MailerliteHiddenCheckbox() : MailerLiteCheckbox(),
217 )
218 );
219 },
220
221 save: function ( props ) {
222
223 return(
224 el('div', { ...useBlockProps.save() })
225 );
226 },
227 } );
228 } )( window.wp.blocks, window.wp.element, window.wp.i18n, window.wc.blocksCheckout, window.wp.blockEditor, window.wp.components, window.wc.wcSettings, window.wp.ajax, window.wp.data );