PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.3.0
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.3.0
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / wizard / assets / src / wizard-steps / PluginsInstallStep.js

PluginsInstallStep.js in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 3.3.0, at wizard/assets/src/wizard-steps/PluginsInstallStep.js

276 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useState, useEffect, useCallback } from '@wordpress/element';
2 import { __ } from '@wordpress/i18n';
3 import { useHistory } from 'react-router-dom';
4 import { useStateValue } from '../utils/StateProvider';
5 import { CheckCircleIcon } from '@heroicons/react/24/outline';
6
7 function PluginsInstallStep() {
8 const [ processing, setProcessing ] = useState( {
9 isProcessing: false,
10 buttonText: __( 'Install & Activate', 'cartflows' ),
11 } );
12
13 const { buttonText } = processing;
14
15 const [ { action_button, selected_page_builder }, dispatch ] =
16 useStateValue();
17 const history = useHistory();
18
19 const required_plugins = cartflows_wizard.plugins;
20 let installed_plugins_count = 0;
21
22 /**
23 * Dispatcher function to change the button text on wizard footer.
24 */
25 const dispatchChangeButtonText = useCallback( ( data ) => {
26 dispatch( {
27 status: 'SET_NEXT_STEP',
28 action_button: data,
29 } );
30 }, [] );
31
32 /**
33 * Function used to change the footer button text and the primary button text while processing the request.
34 */
35 const handleOnClickProcessing = function () {
36 const processing_buttonText = __(
37 'Installing Required Plugins',
38 'cartflows'
39 );
40
41 setProcessing( {
42 isProcessing: true,
43 buttonText: processing_buttonText,
44 } );
45
46 dispatchChangeButtonText( {
47 button_text: processing_buttonText,
48 button_class: 'is-loading',
49 } );
50
51 dispatch( {
52 status: 'PROCESSING',
53 } );
54 };
55
56 useEffect( () => {
57 dispatchChangeButtonText( {
58 button_text: __( 'Install & Activate', 'cartflows' ),
59 button_class: '',
60 } );
61
62 const installPluginsSuccess = function () {
63 setProcessing( false );
64
65 if ( 'bricks-builder' === selected_page_builder ) {
66 history.push( {
67 pathname: 'index.php',
68 search: `?page=cartflow-setup&step=optin`,
69 } );
70 } else {
71 history.push( {
72 pathname: 'index.php',
73 search: `?page=cartflow-setup&step=store-checkout`,
74 } );
75 }
76
77 dispatch( {
78 status: 'RESET',
79 } );
80 };
81
82 document.addEventListener(
83 'wcf-plugins-install-success',
84 installPluginsSuccess,
85 false
86 );
87
88 const installPluginsProcess = function () {
89 handleOnClickProcessing();
90 };
91
92 document.addEventListener(
93 'wcf-install-require-plugins-processing',
94 installPluginsProcess,
95 false
96 );
97
98 return () => {
99 document.removeEventListener(
100 'wcf-plugins-install-success',
101 installPluginsSuccess
102 );
103 document.removeEventListener(
104 'wcf-install-require-plugins-processing',
105 installPluginsProcess
106 );
107 };
108 }, [ dispatchChangeButtonText ] );
109
110 const handleRedirection = function ( e ) {
111 e.preventDefault();
112 setProcessing( {
113 isProcessing: true,
114 buttonText: __( 'Continuing…', 'cartflows' ),
115 } );
116
117 history.push( {
118 pathname: 'index.php',
119 search: `?page=cartflow-setup&step=store-checkout`,
120 } );
121
122 setProcessing( false );
123 };
124
125 return (
126 <div className="wcf-container wcf-wizard--plugin-install">
127 <div className="mt-12">
128 <div className="bg-white rounded mx-auto px-11 text-center">
129 <span className="text-sm font-medium text-primary-600 mb-10 text-center block tracking-[.24em] uppercase">
130 { __( 'Step 3 of 6', 'cartflows' ) }
131 </span>
132 <h1 className="wcf-step-heading mb-4">
133 <span className="flex items-center justify-center gap-3">
134 { __( 'Great job!', 'cartflows' ) }
135 </span>
136 { __(
137 "Now let's install some required plugins.",
138 'cartflows'
139 ) }
140 </h1>
141 <p className="text-center overflow-hidden max-w-2xl mb-10 mx-auto text-lg font-normal text-slate-500 block">
142 { __(
143 "Since CartFlows uses WooCommerce, we'll set it up for you along with Cart Abandonment and Stripe Payments so you can recover abandoned orders and easily accept payments.",
144 'cartflows'
145 ) }
146 </p>
147 <p className="text-center overflow-hidden max-w-2xl mb-6 mx-auto text-lg font-normal text-slate-500 block">
148 { __(
149 'The following plugins will be installed and activated for you:',
150 'cartflows'
151 ) }
152 </p>
153
154 <div className="flex justify-center w-11/12 text-left text-base text-[#1F2937] mx-auto">
155 <fieldset className="">
156 <form
157 method="post"
158 className="wcf-install-plugin-form flex gap-3 space-y-1 text-gray-500 list-inside dark:text-gray-400"
159 >
160 { required_plugins.map( ( plugin, index ) => {
161 const plugin_name = plugin.name,
162 plugin_stat = plugin.status;
163
164 // Skip the display of Spectra plugin if default page builder is set other than gutenberg,
165 // and is not empty.
166 if (
167 'gutenberg' !== selected_page_builder &&
168 '' !== selected_page_builder &&
169 'ultimate-addons-for-gutenberg' ===
170 plugin.slug
171 ) {
172 // Increasing the plugin count for the non-gutenberg page builders.
173 installed_plugins_count++;
174 return '';
175 }
176
177 if ( 'active' === plugin_stat ) {
178 installed_plugins_count++;
179 }
180
181 return (
182 <div
183 className="relative !m-0"
184 key={ index }
185 >
186 <div className="!m-0 text-sm leading-6 py-2 px-3 border border-gray-200 rounded-md">
187 <input
188 id={ plugin.slug }
189 aria-describedby={
190 plugin.slug
191 }
192 name="required_plugins[]"
193 type="checkbox"
194 data-status={ plugin_stat }
195 data-slug={ plugin.slug }
196 className="!hidden !m-0 !h-5 !w-5 !rounded !border-gray-300 !text-[#f06434] focus:!ring-offset-2 focus:!ring-2 focus:!ring-[#f06434] checked:bg-[#f06434]"
197 defaultChecked={ true }
198 disabled={
199 'active' === plugin_stat
200 }
201 />
202
203 <label
204 htmlFor={ plugin.slug }
205 className="font-medium text-slate-800 capitalize flex items-center gap-2"
206 >
207 { 'ultimate-addons-for-gutenberg' ===
208 plugin.slug
209 ? __(
210 'Spectra',
211 'cartflows'
212 )
213 : plugin_name }{ ' ' }
214 { 'active' ===
215 plugin_stat && (
216 <CheckCircleIcon className="w-5 h-5 text-green-600" />
217 ) }
218 <span className="capitalize text-xs italic sr-only">
219 ({ plugin_stat })
220 </span>
221 </label>
222 </div>
223 </div>
224 );
225 } ) }
226 </form>
227 </fieldset>
228 </div>
229
230 <div className="wcf-action-buttons mt-[40px] flex justify-center">
231 { Object.keys( required_plugins ).length ===
232 installed_plugins_count ? (
233 <button
234 className={ `installed-required-plugins wcf-wizard--button ${
235 action_button.button_class
236 ? action_button.button_class
237 : ''
238 }` }
239 onClick={ handleRedirection }
240 >
241 { __( 'Continue', 'cartflows' ) }
242 <svg
243 xmlns="http://www.w3.org/2000/svg"
244 className="w-5 mt-0.5 ml-1.5 fill-[#243c5a]"
245 fill="none"
246 viewBox="0 0 24 24"
247 stroke="currentColor"
248 strokeWidth={ 2 }
249 >
250 <path
251 strokeLinecap="round"
252 strokeLinejoin="round"
253 d="M17 8l4 4m0 0l-4 4m4-4H3"
254 />
255 </svg>
256 </button>
257 ) : (
258 <button
259 className={ `install-required-plugins wcf-wizard--button ${
260 action_button.button_class
261 ? action_button.button_class
262 : ''
263 }` }
264 >
265 { buttonText }
266 </button>
267 ) }
268 </div>
269 </div>
270 </div>
271 </div>
272 );
273 }
274
275 export default PluginsInstallStep;
276