| 1 |
import { useRef, useState, useEffect } from "@wordpress/element"; |
| 2 |
import { __ } from "@wordpress/i18n"; |
| 3 |
|
| 4 |
import { LeftArrow, RightArrow, TickIcon, RightArrowLong } from "../../icons/icons"; |
| 5 |
import WelcomePage from "./pages/welcome"; |
| 6 |
import BlocksSetup from "./pages/setup"; |
| 7 |
import classNames from "classnames"; |
| 8 |
import FinishPage from "./pages/finish"; |
| 9 |
import "../style.scss"; |
| 10 |
import { BlockPage, cardData } from "../pages/blocks"; |
| 11 |
import { WEBSITE_BUILDER_BLOCKS } from "../../controls/constants"; |
| 12 |
import { Toaster } from "react-hot-toast"; |
| 13 |
import Modules from "../pages/modules"; |
| 14 |
|
| 15 |
// const licenseStatus = sp_pcp_block_settings?.license_data?.status || false; |
| 16 |
const spPCPSiteType = sp_pcp_block_settings?.sp_ua_site_type; |
| 17 |
|
| 18 |
const SetupWizard = ({ blocksSettings, modulesOptions, blockShowHideHandler }) => { |
| 19 |
const footer = document.querySelector("#wpfooter"); |
| 20 |
|
| 21 |
if (footer) { |
| 22 |
footer.style.display = "none"; |
| 23 |
} |
| 24 |
const nextBtnRef = useRef(null); |
| 25 |
const [stepNumber, setStepNumber] = useState(0); |
| 26 |
const [websiteType, setWebsiteType] = useState(spPCPSiteType); |
| 27 |
const [isExiting, setIsExiting] = useState(false); |
| 28 |
const [errorMessage, setErrorMessage] = useState(""); |
| 29 |
|
| 30 |
const [direction, setDirection] = useState("left"); |
| 31 |
const [animationClass, setAnimationClass] = useState(""); |
| 32 |
|
| 33 |
const setupSteps = [ |
| 34 |
"Welcome", |
| 35 |
"Blocks", |
| 36 |
"Modules", |
| 37 |
"Finish", |
| 38 |
]; |
| 39 |
|
| 40 |
const onAnimationEnd = () => { |
| 41 |
if (isExiting) { |
| 42 |
if (direction === "left") { |
| 43 |
setStepNumber((prev) => prev + 1); |
| 44 |
} else { |
| 45 |
setStepNumber((prev) => prev - 1); |
| 46 |
} |
| 47 |
setAnimationClass("is-entering"); |
| 48 |
setIsExiting(false); |
| 49 |
} |
| 50 |
}; |
| 51 |
|
| 52 |
const nextStep = () => { |
| 53 |
setDirection("left"); |
| 54 |
setIsExiting(true); |
| 55 |
setAnimationClass("is-exiting"); |
| 56 |
}; |
| 57 |
|
| 58 |
const handleNext = () => { |
| 59 |
if (stepNumber === 1 && websiteType === "") { |
| 60 |
setErrorMessage(true); |
| 61 |
return; |
| 62 |
} |
| 63 |
setErrorMessage(false); |
| 64 |
nextStep(); |
| 65 |
}; |
| 66 |
|
| 67 |
const handlePrev = () => { |
| 68 |
setDirection("right"); |
| 69 |
setIsExiting(true); |
| 70 |
setAnimationClass("is-exiting"); |
| 71 |
}; |
| 72 |
|
| 73 |
return ( |
| 74 |
<div className="sp-pcp-blocks-setting-wrapper setup-wizard"> |
| 75 |
<div className="sp-smart-post-setup-wizard-wrapper"> |
| 76 |
<div className={`sp-smart-post-setup-wizard-content`}> |
| 77 |
<div className="sp-smart-post-setup-steps"> |
| 78 |
{setupSteps?.map((step, index) => ( |
| 79 |
<div className="sp-smart-post-setup-step" key={index}> |
| 80 |
<span |
| 81 |
className={classNames( |
| 82 |
"sp-smart-post-setup-step-number", |
| 83 |
{ |
| 84 |
active: index === stepNumber, |
| 85 |
previous: index < stepNumber, |
| 86 |
} |
| 87 |
)} |
| 88 |
> |
| 89 |
{index < stepNumber ? ( |
| 90 |
<TickIcon /> |
| 91 |
) : ( |
| 92 |
"0" + (index + 1) |
| 93 |
)} |
| 94 |
</span> |
| 95 |
<span className="sp-smart-post-setup-step-title"> |
| 96 |
{step} |
| 97 |
</span> |
| 98 |
{index !== setupSteps.length - 1 && ( |
| 99 |
<RightArrowLong /> |
| 100 |
)} |
| 101 |
</div> |
| 102 |
))} |
| 103 |
</div> |
| 104 |
<div |
| 105 |
className={`sp-smart-post-setup-step-page ${animationClass}`} |
| 106 |
onAnimationEnd={onAnimationEnd} |
| 107 |
> |
| 108 |
{setupSteps[stepNumber] === "Welcome" && ( |
| 109 |
<WelcomePage /> |
| 110 |
)} |
| 111 |
|
| 112 |
{setupSteps[stepNumber] === "Blocks" && ( |
| 113 |
<div className="sp-smart-post-setup-wizard-selected-blocks-page"> |
| 114 |
<BlocksSetup |
| 115 |
websiteType={websiteType} |
| 116 |
setWebsiteType={setWebsiteType} |
| 117 |
errorMessage={errorMessage} |
| 118 |
/> |
| 119 |
<div className="sp-smart-post-setup-page-wrapper"> |
| 120 |
<h3 className="sp-smart-post-setup-page-title">{__("Enable the Blocks You Need", "post-carousel")}</h3> |
| 121 |
<p className="sp-smart-post-setup-page-desc"> |
| 122 |
{__("Turn on the blocks that fit your workflow. You can update your selection anytime.", "post-carousel")} |
| 123 |
</p> |
| 124 |
</div> |
| 125 |
<div className="sp-smart-post-wizard-blocks-container"> |
| 126 |
<BlockPage |
| 127 |
blocksSettings={blocksSettings} blockShowHideHandler={blockShowHideHandler} |
| 128 |
type="setup-wizard" |
| 129 |
/> |
| 130 |
</div> |
| 131 |
</div> |
| 132 |
)} |
| 133 |
{setupSteps[stepNumber] === "Modules" && ( |
| 134 |
<div className="sp-smart-post-modules-wizard"> |
| 135 |
<div className="sp-smart-post-setup-page-wrapper"> |
| 136 |
<h3 className="sp-smart-post-setup-page-title">{__("Enable the Modules You Need", "post-carousel")}</h3> |
| 137 |
<p className="sp-smart-post-setup-page-desc"> |
| 138 |
{__("Turn on the features that match your workflow. You can update your selection anytime.", "post-carousel")} |
| 139 |
</p> |
| 140 |
</div> |
| 141 |
<Modules |
| 142 |
modulesOptions={modulesOptions} blockShowHideHandler={blockShowHideHandler} |
| 143 |
type="setup-wizard" |
| 144 |
/> |
| 145 |
</div> |
| 146 |
)} |
| 147 |
{setupSteps[stepNumber] === "Finish" && ( |
| 148 |
<FinishPage websiteType={websiteType} /> |
| 149 |
)} |
| 150 |
</div> |
| 151 |
<div className="sp-smart-post-setup-wizard-btn-wrapper"> |
| 152 |
{stepNumber !== 0 && |
| 153 |
stepNumber !== setupSteps.length - 1 && ( |
| 154 |
<button |
| 155 |
className="sp-smart-post-setup-wizard-nav-btn prev-btn" |
| 156 |
onClick={handlePrev} |
| 157 |
> |
| 158 |
<LeftArrow /> |
| 159 |
{__("Previous", "post-carousel")} |
| 160 |
</button> |
| 161 |
)} |
| 162 |
|
| 163 |
{stepNumber === 0 && ( |
| 164 |
<a |
| 165 |
className="sp-smart-post-setup-wizard-nav-btn prev-btn skip-it-btn" |
| 166 |
href={`${sp_pcp_block_settings?.homeUrl}wp-admin/edit.php?post_type=sp_post_carousel&page=pcp_help`} |
| 167 |
> |
| 168 |
{"Skip it"} |
| 169 |
</a> |
| 170 |
)} |
| 171 |
{stepNumber !== setupSteps.length - 1 && ( |
| 172 |
<button |
| 173 |
className="sp-smart-post-setup-wizard-nav-btn next-btn" |
| 174 |
onClick={handleNext} |
| 175 |
ref={nextBtnRef} |
| 176 |
> |
| 177 |
{__("Next Step", "post-carousel")} |
| 178 |
<RightArrow /> |
| 179 |
</button> |
| 180 |
)} |
| 181 |
</div> |
| 182 |
</div> |
| 183 |
</div> |
| 184 |
<Toaster position="top-right" reverseOrder={false} /> |
| 185 |
</div> |
| 186 |
); |
| 187 |
}; |
| 188 |
|
| 189 |
|
| 190 |
export default SetupWizard; |
| 191 |
|