| 1 |
import { useEffect, useState } from "@wordpress/element"; |
| 2 |
import { __ } from "@wordpress/i18n"; |
| 3 |
import useGetChangeLogData from "../../hooks/getChangeLogData"; |
| 4 |
import { Arrow, ArrowRight } from "../icons/navigation"; |
| 5 |
import { Logo, OurPluginsIcon } from "../icons/brand"; |
| 6 |
import { LogNoticeIcon, SpikerNoticeIcon, Support, Blog, Community, DocsStroked, FeatRequest, GetHelp, Roadmap, SetupWizard, TechSupport, Video, WhatsNew, ChangeLogNoticeIcon } from "../icons/ui"; |
| 7 |
import { CloseIcon } from "../../../prebuild-library/icons"; |
| 8 |
|
| 9 |
const GreenCheckIcon = () => ( |
| 10 |
<img |
| 11 |
src={`${sp_pcp_block_settings?.pluginUrl}/assets/images/bell-icon.gif`} |
| 12 |
width={18} |
| 13 |
height={18} |
| 14 |
alt="" |
| 15 |
/> |
| 16 |
); |
| 17 |
|
| 18 |
const GetHelpItems = [ |
| 19 |
{ |
| 20 |
title: __("Documentation", "post-carousel"), |
| 21 |
Icon: DocsStroked, |
| 22 |
link: "https://wpsmartpost.com/docs/", |
| 23 |
}, |
| 24 |
{ |
| 25 |
title: __("Technical Support", "post-carousel"), |
| 26 |
Icon: TechSupport, |
| 27 |
link: "https://shapedplugin.com/create-new-ticket/", |
| 28 |
}, |
| 29 |
{ |
| 30 |
title: __("Setup Wizard", "post-carousel"), |
| 31 |
Icon: SetupWizard, |
| 32 |
link: `${sp_pcp_block_settings?.homeUrl}wp-admin/admin.php?page=pcp_help#setupwizard`, |
| 33 |
}, |
| 34 |
{ |
| 35 |
title: __("Public Roadmap", "post-carousel"), |
| 36 |
Icon: Roadmap, |
| 37 |
link: "https://community.shapedplugin.com/roadmap/smart-post/", |
| 38 |
}, |
| 39 |
{ |
| 40 |
title: __("Request a Feature", "post-carousel"), |
| 41 |
Icon: FeatRequest, |
| 42 |
link: "https://community.shapedplugin.com/portal/space/smartpost/home", |
| 43 |
}, |
| 44 |
{ |
| 45 |
title: __("Video Tutorials", "post-carousel"), |
| 46 |
Icon: Video, |
| 47 |
link: "https://youtu.be/vnveuaiPBdc?si=B-DH-foeAh9TwjE5", |
| 48 |
}, |
| 49 |
{ |
| 50 |
title: __("What's New", "post-carousel"), |
| 51 |
Icon: WhatsNew, |
| 52 |
link: "https://wpsmartpost.com/changelog/", |
| 53 |
}, |
| 54 |
{ |
| 55 |
title: __("Blog: Latest News", "post-carousel"), |
| 56 |
Icon: Blog, |
| 57 |
link: "https://wpsmartpost.com/blog/", |
| 58 |
}, |
| 59 |
{ |
| 60 |
title: __("Join Community", "post-carousel"), |
| 61 |
Icon: Community, |
| 62 |
link: "https://community.shapedplugin.com/portal/", |
| 63 |
}, |
| 64 |
]; |
| 65 |
|
| 66 |
const Header = ({ page, setPage, modulesOptions }) => { |
| 67 |
const [changeLogToggle, setChangeLogToggle] = useState(false); |
| 68 |
const [changeLodData, setChangeLogData] = useState(null); |
| 69 |
|
| 70 |
const { getChangeLog } = useGetChangeLogData(); |
| 71 |
|
| 72 |
const changeLogControl = async () => { |
| 73 |
if (!changeLodData) { |
| 74 |
const changelog = await getChangeLog(); |
| 75 |
setChangeLogData(changelog); |
| 76 |
} |
| 77 |
setChangeLogToggle(!changeLogToggle); |
| 78 |
if (!changeLogToggle) { |
| 79 |
document.querySelector("body").classList.add("show-change-log"); |
| 80 |
} else { |
| 81 |
document.querySelector("body").classList.remove("show-change-log"); |
| 82 |
} |
| 83 |
}; |
| 84 |
|
| 85 |
useEffect(() => { |
| 86 |
const closeChangeLog = (e) => { |
| 87 |
if (e.target.classList.contains("show-change-log")) { |
| 88 |
setChangeLogToggle(false); |
| 89 |
document.querySelector("body").classList.remove("show-change-log"); |
| 90 |
} |
| 91 |
}; |
| 92 |
document.addEventListener("click", closeChangeLog); |
| 93 |
return () => document.removeEventListener("click", closeChangeLog); |
| 94 |
}, []); |
| 95 |
|
| 96 |
const enabledSavedTemplate = modulesOptions?.some((item) => item.module_name === "saved-template" && item.show); |
| 97 |
|
| 98 |
useEffect(() => { |
| 99 |
const postMenu = document.getElementById("menu-posts-sp_post_carousel"); |
| 100 |
const saveTemplateItem = postMenu?.querySelectorAll("li"); |
| 101 |
|
| 102 |
if(!enabledSavedTemplate) { |
| 103 |
saveTemplateItem[3].style.display = "none"; |
| 104 |
}else { |
| 105 |
saveTemplateItem[3].style.display = "block"; |
| 106 |
} |
| 107 |
|
| 108 |
}, [enabledSavedTemplate]) |
| 109 |
|
| 110 |
const tabChange = (e) => { |
| 111 |
const targetValue = e.target.getAttribute( "value" ); |
| 112 |
setPage( targetValue ); |
| 113 |
|
| 114 |
const recommendedPage = document.querySelector(".spspc-recommended-page"); |
| 115 |
|
| 116 |
if(!recommendedPage) return; |
| 117 |
|
| 118 |
if("our-plugins" === targetValue) { |
| 119 |
recommendedPage.style.display = "block"; |
| 120 |
}else{ |
| 121 |
recommendedPage.style.display = "none"; |
| 122 |
} |
| 123 |
|
| 124 |
} |
| 125 |
|
| 126 |
const navigationItems = [ |
| 127 |
{ |
| 128 |
title: __("Getting Started", "post-carousel"), |
| 129 |
value: "quick-start", |
| 130 |
href: "#", |
| 131 |
show: true, |
| 132 |
}, |
| 133 |
{ |
| 134 |
title: __("Blocks", "post-carousel"), |
| 135 |
value: "blocks", |
| 136 |
href: "#blocks", |
| 137 |
show: true, |
| 138 |
badge: __("NEW!", "post-carousel"), |
| 139 |
}, |
| 140 |
{ |
| 141 |
title: __("Modules", "post-carousel"), |
| 142 |
value: "modules", |
| 143 |
href: "#modules", |
| 144 |
show: true, |
| 145 |
}, |
| 146 |
{ |
| 147 |
title: __("Saved Templates", "post-carousel"), |
| 148 |
value: "savedTemplate", |
| 149 |
href: "#savedTemplate", |
| 150 |
show: enabledSavedTemplate, |
| 151 |
}, |
| 152 |
{ |
| 153 |
title: __("Integrations", "post-carousel"), |
| 154 |
value: "integrations", |
| 155 |
href: "#integrations", |
| 156 |
show: true, |
| 157 |
}, |
| 158 |
{ |
| 159 |
title: __("Settings", "post-carousel"), |
| 160 |
value: "settings", |
| 161 |
href: "#settings", |
| 162 |
show: true, |
| 163 |
}, |
| 164 |
{ |
| 165 |
title: __("Lite vs Pro", "post-carousel"), |
| 166 |
value: "lite-vs-pro", |
| 167 |
href: "#lite-vs-pro", |
| 168 |
show: true, |
| 169 |
}, |
| 170 |
{ |
| 171 |
title: __("About Us", "post-carousel"), |
| 172 |
value: "about-us", |
| 173 |
href: "#about-us", |
| 174 |
show: true, |
| 175 |
}, |
| 176 |
{ |
| 177 |
title: __("Our Plugins", "post-carousel"), |
| 178 |
value: "our-plugins", |
| 179 |
href: "#our-plugins", |
| 180 |
show: true, |
| 181 |
icon: <OurPluginsIcon />, |
| 182 |
}, |
| 183 |
]; |
| 184 |
|
| 185 |
return ( |
| 186 |
<> |
| 187 |
<div className="sp-pcp-change-log"> |
| 188 |
<div className="sp-pcp-change-log-header"> |
| 189 |
<h4>Latest Updates - Changelog</h4> |
| 190 |
<span onClick={() => changeLogControl()} className="sp-pcp-change-log-close"> |
| 191 |
<CloseIcon /> |
| 192 |
</span> |
| 193 |
</div> |
| 194 |
{changeLodData && ( |
| 195 |
<div |
| 196 |
className="sp-smart-changelog-details" |
| 197 |
dangerouslySetInnerHTML={{ |
| 198 |
__html: changeLodData?.changelog, |
| 199 |
}} |
| 200 |
/> |
| 201 |
)} |
| 202 |
{!changeLodData && changeLogToggle && ( |
| 203 |
<div className="sp-smart-changelog-details"> |
| 204 |
<p>Loading....</p> |
| 205 |
</div> |
| 206 |
)} |
| 207 |
</div> |
| 208 |
|
| 209 |
<div className="sp-pcp-blocks-settings-page-header"> |
| 210 |
<div className="sp-pcp-green-header-notice"> |
| 211 |
<div className="sp-pcp-green-header-notice-content"> |
| 212 |
<GreenCheckIcon /> |
| 213 |
<span className="sp-pcp-green-header-notice-text"> |
| 214 |
<strong>You're on Lite</strong> — unlock the full power at <strong>50% OFF. Lifetime Deal.</strong> Pay once, Use forever. |
| 215 |
</span> |
| 216 |
<a |
| 217 |
className="sp-pcp-green-header-notice-link" |
| 218 |
href="https://wpsmartpost.com/pricing/?ref=1" |
| 219 |
target="_blank" |
| 220 |
rel="noopener noreferrer" |
| 221 |
> |
| 222 |
{__("Upgrade to Pro", "post-carousel")} |
| 223 |
<ArrowRight /> |
| 224 |
</a> |
| 225 |
</div> |
| 226 |
</div> |
| 227 |
<div className="sp-pcp-blocks-settings-page-header-body"> |
| 228 |
<div className="sp-pcp-blocks-settings-page-header-left"> |
| 229 |
<Logo /> |
| 230 |
<span onClick={() => changeLogControl()}> <LogNoticeIcon /> {sp_pcp_block_settings.pluginVersion}</span> |
| 231 |
</div> |
| 232 |
<button className="sp-pcp-blocks-settings-page-header-right"> |
| 233 |
<GetHelp /> |
| 234 |
|
| 235 |
<span className="get-help">{__("Get Help", "post-carousel")}</span> |
| 236 |
<div className="sp-pcp-help-drop-down"> |
| 237 |
{GetHelpItems?.map( |
| 238 |
({ title, link, Icon }, index) => ( |
| 239 |
<a |
| 240 |
key={index} |
| 241 |
href={link} |
| 242 |
target="_blank" |
| 243 |
rel="noopener noreferrer" |
| 244 |
> |
| 245 |
<Icon /> |
| 246 |
<span>{title}</span> |
| 247 |
<span className="drop-down-arrow"> |
| 248 |
<Arrow /> |
| 249 |
</span> |
| 250 |
</a> |
| 251 |
) |
| 252 |
)} |
| 253 |
</div> |
| 254 |
</button> |
| 255 |
</div> |
| 256 |
</div> |
| 257 |
<div className="sp-smart-post-block-settings-nev"> |
| 258 |
<ul> |
| 259 |
{navigationItems?.map( |
| 260 |
({ title, value, href, show, badge, icon }, index) => |
| 261 |
show && ( |
| 262 |
<li key={index} className={ |
| 263 |
value === "our-plugins" |
| 264 |
? `sp-pcp-nav-our-plugins${page === "about-us" || page === "our-plugins" ? " active" : ""}` |
| 265 |
: "" |
| 266 |
}> |
| 267 |
<a |
| 268 |
href={href} |
| 269 |
className={(page === value) ? "active" : ""} |
| 270 |
value={value} |
| 271 |
onClick={tabChange} |
| 272 |
> |
| 273 |
{icon} |
| 274 |
{title} |
| 275 |
{badge && ( |
| 276 |
<span className="sp-pcp-nav-badge">{badge}</span> |
| 277 |
)} |
| 278 |
</a> |
| 279 |
</li> |
| 280 |
) |
| 281 |
)} |
| 282 |
</ul> |
| 283 |
</div> |
| 284 |
</> |
| 285 |
); |
| 286 |
}; |
| 287 |
|
| 288 |
export default Header; |
| 289 |
|