| 1 |
import { useEffect, useState } from '@wordpress/element'; |
| 2 |
import { __ } from '@wordpress/i18n'; |
| 3 |
import { useStateValue } from '../utils/StateProvider'; |
| 4 |
import apiFetch from '@wordpress/api-fetch'; |
| 5 |
import confetti from 'canvas-confetti'; |
| 6 |
import { ArrowLongRightIcon, ArrowPathIcon } from '@heroicons/react/24/outline'; |
| 7 |
|
| 8 |
function ReadyStep() { |
| 9 |
const [ |
| 10 |
{ showConfetti, selected_page_builder, isStoreCheckoutImported }, |
| 11 |
dispatch, |
| 12 |
] = useStateValue(); |
| 13 |
const ConfettiFrame = confetti.create( |
| 14 |
document.getElementById( 'wcf-confetti-wrapper' ), |
| 15 |
{ resize: true } |
| 16 |
); |
| 17 |
|
| 18 |
const [ isFinishingSetup, setIsFinishingSetup ] = useState( false ); |
| 19 |
|
| 20 |
if ( ! showConfetti ) { |
| 21 |
setTimeout( function () { |
| 22 |
ConfettiFrame( { |
| 23 |
particleCount: 250, |
| 24 |
origin: { x: 1, y: 1.4 }, |
| 25 |
gravity: 0.4, |
| 26 |
spread: 80, |
| 27 |
ticks: 300, |
| 28 |
angle: 120, |
| 29 |
startVelocity: 100, |
| 30 |
colors: [ |
| 31 |
'#0e6ef1', |
| 32 |
'#f5b800', |
| 33 |
'#ff344c', |
| 34 |
'#98e027', |
| 35 |
'#9900f1', |
| 36 |
], |
| 37 |
} ); |
| 38 |
|
| 39 |
dispatch( { |
| 40 |
status: 'SET_SHOW_CONFETTI', |
| 41 |
showConfetti: true, |
| 42 |
} ); |
| 43 |
}, 100 ); |
| 44 |
} |
| 45 |
|
| 46 |
useEffect( () => { |
| 47 |
const ajaxData = new window.FormData(); |
| 48 |
ajaxData.append( 'action', 'cartflows_onboarding_completed' ); |
| 49 |
ajaxData.append( |
| 50 |
'security', |
| 51 |
cartflows_wizard.onboarding_completed_nonce |
| 52 |
); |
| 53 |
|
| 54 |
apiFetch( { |
| 55 |
url: ajaxurl, |
| 56 |
method: 'POST', |
| 57 |
body: ajaxData, |
| 58 |
} ).then( () => {} ); |
| 59 |
}, [] ); |
| 60 |
|
| 61 |
const handleClick = ( e ) => { |
| 62 |
e.preventDefault(); |
| 63 |
|
| 64 |
setIsFinishingSetup( true ); |
| 65 |
let redirectUrl = '?page=cartflows'; |
| 66 |
|
| 67 |
if ( isStoreCheckoutImported ) { |
| 68 |
// Redirect to Store Checkout. |
| 69 |
redirectUrl = redirectUrl + '&path=store-checkout'; |
| 70 |
} else if ( 'bricks-builder' === selected_page_builder ) { |
| 71 |
// Redirect to Dashboard to create the template from scratch. |
| 72 |
redirectUrl = redirectUrl; // Redirect to the default page i:e dashboard itself. |
| 73 |
} else { |
| 74 |
// Redirec to Import the ready-made templates of start from scratch. |
| 75 |
redirectUrl = redirectUrl + '&path=library'; |
| 76 |
} |
| 77 |
|
| 78 |
// Redirect to the created url. |
| 79 |
window.location.href = cartflows_wizard.admin_url + redirectUrl; |
| 80 |
}; |
| 81 |
|
| 82 |
return ( |
| 83 |
<div className="wcf-container"> |
| 84 |
<canvas |
| 85 |
id="wcf-confetti-wrapper" |
| 86 |
width={ window.innerWidth } |
| 87 |
height={ window.innerHeight } |
| 88 |
/> |
| 89 |
<div className="wcf-row mt-12"> |
| 90 |
<div className="bg-white rounded mx-auto px-11"> |
| 91 |
<div className="text-center overflow-hidden"> |
| 92 |
<span className="text-sm font-medium text-primary-600 mb-10 text-center block tracking-[.24em] uppercase"> |
| 93 |
{ __( 'Step 6 of 6', 'cartflows' ) } |
| 94 |
</span> |
| 95 |
<h1 className="wcf-step-heading mb-4"> |
| 96 |
{ __( |
| 97 |
'Congratulations, You Did It!', |
| 98 |
'cartflows' |
| 99 |
) } |
| 100 |
</h1> |
| 101 |
<p className="text-center overflow-hidden mb-10 mx-auto text-lg font-normal text-slate-500"> |
| 102 |
{ __( |
| 103 |
'CartFlows is set up on your website! Please watch the short video below for your next steps.', |
| 104 |
'cartflows' |
| 105 |
) } |
| 106 |
</p> |
| 107 |
</div> |
| 108 |
<iframe |
| 109 |
className="mx-auto" |
| 110 |
width="80%" |
| 111 |
height="400" |
| 112 |
src="https://www.youtube.com/embed/nQ8O1jObdlc" |
| 113 |
title={ __( |
| 114 |
'CartFlows Extended Walkthrough Tutorial', |
| 115 |
'cartflows' |
| 116 |
) } |
| 117 |
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" |
| 118 |
></iframe> |
| 119 |
|
| 120 |
<div className="mt-[50px] flex justify-center"> |
| 121 |
<div |
| 122 |
className={ `wcf-wizard--button hover:text-white ${ |
| 123 |
isFinishingSetup ? 'cursor-wait opacity-80' : '' |
| 124 |
}` } |
| 125 |
onClick={ handleClick } |
| 126 |
> |
| 127 |
{ ! isFinishingSetup |
| 128 |
? __( 'Finish Store Setup', 'cartflows' ) |
| 129 |
: __( 'Finishing the Setup', 'cartflows' ) } |
| 130 |
|
| 131 |
{ ! isFinishingSetup ? ( |
| 132 |
<ArrowLongRightIcon className="w-5 ml-1.5 fill-[#243c5a] stroke-2" /> |
| 133 |
) : ( |
| 134 |
<ArrowPathIcon className="w-5 ml-1.5 stroke-2 animate-spin" /> |
| 135 |
) } |
| 136 |
</div> |
| 137 |
</div> |
| 138 |
</div> |
| 139 |
</div> |
| 140 |
</div> |
| 141 |
); |
| 142 |
} |
| 143 |
|
| 144 |
export default ReadyStep; |
| 145 |
|