PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.4
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.4
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.1.4, at wizard/assets/src/wizard-steps/PluginsInstallStep.js

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