| 1 |
import { Fragment } from '@wordpress/element' |
| 2 |
import { __ } from '@wordpress/i18n' |
| 3 |
import classNames from 'classnames' |
| 4 |
import { colord } from 'colord' |
| 5 |
import { useGlobalStore } from '../state/Global' |
| 6 |
|
| 7 |
const steps = { |
| 8 |
'site-type': { |
| 9 |
step: __('Site Industry', 'extendify'), |
| 10 |
title: __("Let's Start Building Your Website", 'extendify'), |
| 11 |
description: __( |
| 12 |
'Create a super-fast, beautiful, and fully customized site in minutes with the Launch in the core WordPress editor.', |
| 13 |
'extendify', |
| 14 |
), |
| 15 |
buttonText: __('Select Site Industry', 'extendify'), |
| 16 |
}, |
| 17 |
goals: { |
| 18 |
step: __('Goals', 'extendify'), |
| 19 |
title: __('Continue Building Your Website', 'extendify'), |
| 20 |
description: __( |
| 21 |
'Create a super-fast, beautiful, and fully customized site in minutes with the Launch in the core WordPress editor.', |
| 22 |
'extendify', |
| 23 |
), |
| 24 |
buttonText: __('Select Site Goals', 'extendify'), |
| 25 |
}, |
| 26 |
style: { |
| 27 |
step: __('Design', 'extendify'), |
| 28 |
title: __('Continue Building Your Website', 'extendify'), |
| 29 |
description: __( |
| 30 |
'Create a super-fast, beautiful, and fully customized site in minutes with the Launch in the core WordPress editor.', |
| 31 |
'extendify', |
| 32 |
), |
| 33 |
buttonText: __('Select Site Design', 'extendify'), |
| 34 |
}, |
| 35 |
pages: { |
| 36 |
step: __('Pages', 'extendify'), |
| 37 |
title: __('Continue Building Your Website', 'extendify'), |
| 38 |
description: __( |
| 39 |
'Create a super-fast, beautiful, and fully customized site in minutes with the Launch in the core WordPress editor.', |
| 40 |
'extendify', |
| 41 |
), |
| 42 |
buttonText: __('Select Site Pages', 'extendify'), |
| 43 |
}, |
| 44 |
confirmation: { |
| 45 |
step: __('Launch', 'extendify'), |
| 46 |
title: __("Let's Launch Your Site", 'extendify'), |
| 47 |
description: __( |
| 48 |
"You're one step away from creating a super-fast, beautiful, and fully customizable site with the Launch in the core WordPress editor.", |
| 49 |
'extendify', |
| 50 |
), |
| 51 |
buttonText: __('Launch The Site', 'extendify'), |
| 52 |
}, |
| 53 |
} |
| 54 |
|
| 55 |
export const AdminNotice = () => { |
| 56 |
const noticeKey = 'extendify-launch' |
| 57 |
const { isDismissed, dismissNotice } = useGlobalStore() |
| 58 |
|
| 59 |
// To avoid content flash, we load in this partial piece of state early via php |
| 60 |
const dismissed = window.extAssistData.dismissedNotices.find( |
| 61 |
(notice) => notice.id === noticeKey, |
| 62 |
) |
| 63 |
if (dismissed || isDismissed(noticeKey)) return null |
| 64 |
|
| 65 |
const pageData = JSON.parse(localStorage.getItem('extendify-pages') ?? null) |
| 66 |
if (!pageData) return null |
| 67 |
|
| 68 |
// Filter out pages that don't match step keys |
| 69 |
const pages = pageData?.state?.availablePages.filter((p) => |
| 70 |
Object.keys(steps).includes(p), |
| 71 |
) |
| 72 |
// If their last step doesn't exist in our options, just use step 1 |
| 73 |
const lastStep = pageData?.state?.currentPageSlug |
| 74 |
const currentStep = Object.keys(steps).includes(lastStep) |
| 75 |
? lastStep |
| 76 |
: 'site-type' |
| 77 |
|
| 78 |
let reached = false |
| 79 |
|
| 80 |
// Compute the color based on the active admin menu item color |
| 81 |
const bgColor = |
| 82 |
window.getComputedStyle( |
| 83 |
document.querySelector('a.wp-has-current-submenu'), |
| 84 |
)['background-color'] ?? '#3858e9' |
| 85 |
const bgDarker = colord(bgColor).darken(0.05).toHex() |
| 86 |
|
| 87 |
return ( |
| 88 |
<div className="mt-6 mb-8 max-w-screen-3xl"> |
| 89 |
<div |
| 90 |
style={{ background: bgColor, minHeight: '420px' }} |
| 91 |
className="relative flex flex-col"> |
| 92 |
<div |
| 93 |
style={{ background: bgDarker }} |
| 94 |
className="justify-between items-center py-6 px-2 lg:px-12 gap-x-3 hidden md:flex"> |
| 95 |
{pages.map((item, index) => { |
| 96 |
if (item === currentStep) reached = true |
| 97 |
return ( |
| 98 |
<Fragment key={item}> |
| 99 |
<StepCircle |
| 100 |
reached={reached} |
| 101 |
bgColor={bgColor} |
| 102 |
step={index + 1} |
| 103 |
stepName={steps[item]?.step} |
| 104 |
current={item === currentStep} |
| 105 |
/> |
| 106 |
{index !== pages.length - 1 && ( |
| 107 |
<div className="hidden lg:block border-0 border-b-2 border-white border-solid border-opacity-10 h-0 grow w-full text-white" /> |
| 108 |
)} |
| 109 |
</Fragment> |
| 110 |
) |
| 111 |
})} |
| 112 |
</div> |
| 113 |
<div |
| 114 |
className="h-10 md:hidden" |
| 115 |
aria-hidden={true} |
| 116 |
style={{ backgroundColor: bgDarker }} |
| 117 |
/> |
| 118 |
<div className="max-w-screen-md flex-grow w-full flex flex-col justify-center lg:w-1/2 p-6 lg:p-12"> |
| 119 |
<h2 className="text-3xl m-0 mb-4 text-white"> |
| 120 |
{steps[currentStep]?.title} |
| 121 |
</h2> |
| 122 |
<p className="text-lg text-white"> |
| 123 |
{steps[currentStep]?.description} |
| 124 |
</p> |
| 125 |
<div className="flex items-center gap-x-4 mt-9"> |
| 126 |
<a |
| 127 |
href={`${window.extAssistData.adminUrl}post-new.php?extendify=onboarding`} |
| 128 |
className="cursor-pointer rounded-sm px-6 py-4 bg-gray-900 text-lg text-white border-none no-underline"> |
| 129 |
{steps[currentStep]?.buttonText} |
| 130 |
</a> |
| 131 |
<div> |
| 132 |
<button |
| 133 |
className="text-white p-1 text-sm z-10 flex items-center uppercase opacity-70 hover:opacity-100 bg-transparent border-none cursor-pointer" |
| 134 |
onClick={() => dismissNotice(noticeKey)} |
| 135 |
type="button"> |
| 136 |
<span className="dashicons dashicons-no-alt"></span> |
| 137 |
<span className="tracking-wide"> |
| 138 |
{__('Dismiss', 'extendify')} |
| 139 |
</span> |
| 140 |
</button> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
</div> |
| 144 |
<img |
| 145 |
className="lg:absolute bottom-0 right-0 max-w-lg w-full block mx-auto" |
| 146 |
src={ |
| 147 |
window.extAssistData.asset_path + |
| 148 |
'/extendify-preview.png' |
| 149 |
} |
| 150 |
/> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
) |
| 154 |
} |
| 155 |
|
| 156 |
const StepCircle = ({ reached, step, current, stepName, bgColor }) => ( |
| 157 |
<div className="flex-none text-white text-sm flex items-center gap-x-2"> |
| 158 |
<span |
| 159 |
style={{ background: reached ? undefined : bgColor }} |
| 160 |
className={classNames( |
| 161 |
'border-2 border-solid w-9 h-9 rounded-full flex items-center justify-center', |
| 162 |
{ |
| 163 |
'disc-checked border-white border-opacity-10': !reached, |
| 164 |
'disc-number border-white': reached, |
| 165 |
'border-dotted': current, |
| 166 |
}, |
| 167 |
)}> |
| 168 |
{reached ? step : <span className="dashicons dashicons-saved" />} |
| 169 |
</span> |
| 170 |
<span>{stepName}</span> |
| 171 |
</div> |
| 172 |
) |
| 173 |
|