| 1 |
import { __ } from "@wordpress/i18n"; |
| 2 |
import { useState } from "@wordpress/element"; |
| 3 |
import { CheckboxControl, Spinner } from "@wordpress/components"; |
| 4 |
import axios from "axios"; |
| 5 |
import { toastErrorMsg, UserDataInfoModal } from "../../pages/Settings/functions"; |
| 6 |
import { RightArrow } from "../../../icons/icons"; |
| 7 |
|
| 8 |
const FinishPage = ({ websiteType }) => { |
| 9 |
const phpToJsBool = { |
| 10 |
0: false, |
| 11 |
1: true, |
| 12 |
}; |
| 13 |
const initialConsent = |
| 14 |
sp_pcp_block_settings?.sp_pcp_user_consent === "undefined" |
| 15 |
? true |
| 16 |
: phpToJsBool[sp_pcp_block_settings?.sp_pcp_user_consent]; |
| 17 |
const [shareData, setShareData] = useState(initialConsent); |
| 18 |
const [isFinishing, setIsFinishing] = useState(false); |
| 19 |
|
| 20 |
const [isOpenModal, setOpenModal] = useState(false); |
| 21 |
const openModal = () => setOpenModal(true); |
| 22 |
const closeModal = () => setOpenModal(false); |
| 23 |
|
| 24 |
const saveUserData = async () => { |
| 25 |
setIsFinishing(true); |
| 26 |
try { |
| 27 |
const formData = new window.FormData(); |
| 28 |
formData.append("action", "sp_smart_post_get_user_consent"); |
| 29 |
formData.append("nonce", sp_pcp_block_settings.nonce); |
| 30 |
formData.append("shareData", JSON.stringify(shareData)); |
| 31 |
formData.append("website_type", websiteType); |
| 32 |
|
| 33 |
const response = await axios.post(ajaxurl, formData); |
| 34 |
|
| 35 |
if (response?.data?.success) { |
| 36 |
window.location.href = `${sp_pcp_block_settings?.homeUrl}wp-admin/admin.php?page=pcp_help`; |
| 37 |
} |
| 38 |
} catch (error) { |
| 39 |
toastErrorMsg(__("Something Went Wrong", "post-carousel")); |
| 40 |
return { success: false, error }; |
| 41 |
} finally { |
| 42 |
setIsFinishing(false); |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
return ( |
| 47 |
<div className="sp-smart-post-setup-finish-page"> |
| 48 |
<div className="sp-smart-post-setup-plugin-logo-wrapper"> |
| 49 |
<img src={`${sp_pcp_block_settings?.wizardImages}/plugin-logo.svg`} alt="Plugin Logo" /> |
| 50 |
</div> |
| 51 |
<img src={`${sp_pcp_block_settings?.wizardImages}/congratulations.svg`} alt="Congratulations" /> |
| 52 |
<h3 className="sp-smart-post-setup-page-title"> |
| 53 |
{__("All Set to Create Your Website!", "post-carousel")} |
| 54 |
</h3> |
| 55 |
<p className="sp-smart-post-setup-page-desc" style={{ width: "636px", textAlign: "center" }}> |
| 56 |
{__( |
| 57 |
"You’re ready to build your website with Smart Post. Enjoy a seamless, efficient content-building experience—no coding, no complications.", |
| 58 |
"post-carousel" |
| 59 |
)} |
| 60 |
</p> |
| 61 |
<button |
| 62 |
className="sp-smart-post-setup-wizard-nav-btn next-btn" |
| 63 |
onClick={saveUserData} |
| 64 |
disabled={isFinishing} |
| 65 |
aria-busy={isFinishing ? "true" : "false"} |
| 66 |
> |
| 67 |
{isFinishing ? ( |
| 68 |
<> |
| 69 |
<Spinner /> {__("Finishing…", "post-carousel")} |
| 70 |
</> |
| 71 |
) : ( |
| 72 |
__("Finish & Let's Get Started", "post-carousel") |
| 73 |
)} |
| 74 |
</button> |
| 75 |
<div className="sp-smart-post-setup-finish-page-banner"> |
| 76 |
{/* <div className="sp-smart-post-setup-finish-page-left-banner-img"> |
| 77 |
<img src={`${sp_pcp_block_settings?.wizardImages}finish-page-banner-left.png`} alt="smart post" /> |
| 78 |
</div> */} |
| 79 |
<div className="sp-smart-post-setup-finish-page-banner-content"> |
| 80 |
<h4 className="sp-smart-post-setup-page-title"> |
| 81 |
{__("Effortlessly Create Stunning Post Layouts for Blogs, News & Any Website—With Smart Post", "post-carousel")} |
| 82 |
</h4> |
| 83 |
<p>Trusted by <b>30,000+</b> bloggers, writers, creators, agencies, marketers, and design professionals.</p> |
| 84 |
<div className="sp-smart-post-setup-wizard-btn"> |
| 85 |
{/* <a |
| 86 |
className="sp-smart-post-upgrade-btn pro-btn" |
| 87 |
href="https://wpsmartpost.com/patterns/" |
| 88 |
target="_blank" |
| 89 |
> |
| 90 |
<span className="sp-go-pro-icon"></span> |
| 91 |
{__("Upgrade to Pro!", "post-carousel")} |
| 92 |
</a> */} |
| 93 |
<a className="sp-smart-post-upgrade-btn-wrapper" href="https://wpsmartpost.com/pricing/?ref=1" target="_blank"> |
| 94 |
<span className="sp-smart-post-upgrade-btn"> |
| 95 |
<span className="sp-go-pro-icon"></span> |
| 96 |
{__("Upgrade to Pro!", "post-carousel")} |
| 97 |
</span> |
| 98 |
</a> |
| 99 |
<a |
| 100 |
className="sp-smart-post-setup-wizard-nav-btn prev-btn" |
| 101 |
href="https://wpsmartpost.com/patterns/" |
| 102 |
target="_blank" |
| 103 |
> |
| 104 |
{__("Explore All Patterns", "post-carousel")} |
| 105 |
<RightArrow /> |
| 106 |
</a> |
| 107 |
</div> |
| 108 |
</div> |
| 109 |
<div className="sp-smart-post-setup-finish-page-right-banner-img"> |
| 110 |
<img src={`${sp_pcp_block_settings?.wizardImages}wizard-banner-footer.png`} alt="smart post" /> |
| 111 |
</div> |
| 112 |
</div> |
| 113 |
<div className="sp-smart-post-checkbox-component-wrapper"> |
| 114 |
<p className="sp-smart-post-setup-page-desc"> |
| 115 |
{__( |
| 116 |
"Help us improve Smart Post and get useful tips by sharing non-sensitive diagnostic data. See ", |
| 117 |
"post-carousel" |
| 118 |
)} |
| 119 |
<span |
| 120 |
className="sp-smart-post-modal-btn" |
| 121 |
style={{ |
| 122 |
fontWeight: "600", |
| 123 |
textDecoration: "underline", |
| 124 |
}} |
| 125 |
onClick={openModal} |
| 126 |
> |
| 127 |
{__("what we collect.", "post-carousel")} |
| 128 |
</span> |
| 129 |
</p> |
| 130 |
<CheckboxControl |
| 131 |
checked={shareData} |
| 132 |
onChange={() => setShareData(!shareData)} |
| 133 |
__nextHasNoMarginBottom |
| 134 |
/> |
| 135 |
</div> |
| 136 |
{isOpenModal && <UserDataInfoModal closeModal={closeModal} />} |
| 137 |
</div> |
| 138 |
); |
| 139 |
}; |
| 140 |
|
| 141 |
export default FinishPage; |
| 142 |
|