| 1 |
import { useTasksStore } from '@assist/state/tasks'; |
| 2 |
import { useEffect, useState } from '@wordpress/element'; |
| 3 |
import { __ } from '@wordpress/i18n'; |
| 4 |
|
| 5 |
const { useAgentOnboarding } = window.extSharedData; |
| 6 |
|
| 7 |
const autoLaunch = { |
| 8 |
title: __("Let's Start Building Your Website", 'extendify-local'), |
| 9 |
description: __( |
| 10 |
'Create a super-fast, beautiful, and fully customized site in minutes with our Site Launcher.', |
| 11 |
'extendify-local', |
| 12 |
), |
| 13 |
buttonText: __('Create your site now', 'extendify-local'), |
| 14 |
}; |
| 15 |
|
| 16 |
const launchSteps = { |
| 17 |
'website-objective': { |
| 18 |
step: __('Website Objective', 'extendify-local'), |
| 19 |
title: __("Let's Start Building Your Website", 'extendify-local'), |
| 20 |
description: __( |
| 21 |
'Create a super-fast, beautiful, and fully customized site in minutes with our Site Launcher.', |
| 22 |
'extendify-local', |
| 23 |
), |
| 24 |
buttonText: __('Add Website Objective', 'extendify-local'), |
| 25 |
}, |
| 26 |
'site-information': { |
| 27 |
step: __('Site Industry', 'extendify-local'), |
| 28 |
title: __('Continue Building Your Website', 'extendify-local'), |
| 29 |
description: __( |
| 30 |
'Create a super-fast, beautiful, and fully customized site in minutes with our Site Launcher.', |
| 31 |
'extendify-local', |
| 32 |
), |
| 33 |
buttonText: __('Add Website Details', 'extendify-local'), |
| 34 |
}, |
| 35 |
'site-structure': { |
| 36 |
step: __('Site Structure', 'extendify-local'), |
| 37 |
title: __('Continue Building Your Website', 'extendify-local'), |
| 38 |
description: __( |
| 39 |
'Create a super-fast, beautiful, and fully customized site in minutes with our Site Launcher.', |
| 40 |
'extendify-local', |
| 41 |
), |
| 42 |
buttonText: __('Pick Your Site Structure', 'extendify-local'), |
| 43 |
}, |
| 44 |
layout: { |
| 45 |
step: __('Design', 'extendify-local'), |
| 46 |
title: __('Continue Building Your Website', 'extendify-local'), |
| 47 |
description: __( |
| 48 |
'Create a super-fast, beautiful, and fully customized site in minutes with our Site Launcher.', |
| 49 |
'extendify-local', |
| 50 |
), |
| 51 |
buttonText: __('Select Site Design', 'extendify-local'), |
| 52 |
}, |
| 53 |
'page-select': { |
| 54 |
step: __('Pages', 'extendify-local'), |
| 55 |
title: __('Continue Building Your Website', 'extendify-local'), |
| 56 |
description: __( |
| 57 |
'Create a super-fast, beautiful, and fully customized site in minutes with our Site Launcher.', |
| 58 |
'extendify-local', |
| 59 |
), |
| 60 |
buttonText: __('Select Site Pages', 'extendify-local'), |
| 61 |
}, |
| 62 |
}; |
| 63 |
|
| 64 |
const getCurrentLaunchStep = () => { |
| 65 |
const pageData = JSON.parse( |
| 66 |
localStorage.getItem(`extendify-pages-${window.extSharedData.siteId}`), |
| 67 |
) || { state: {} }; |
| 68 |
const currentPageSlug = pageData?.state?.currentPageSlug; |
| 69 |
|
| 70 |
// If their last step doesn't exist in our options, just use step 1 |
| 71 |
if (!Object.keys(launchSteps).includes(currentPageSlug)) { |
| 72 |
return 'website-objective'; |
| 73 |
} |
| 74 |
|
| 75 |
return currentPageSlug; |
| 76 |
}; |
| 77 |
|
| 78 |
export const LaunchCard = ({ task }) => { |
| 79 |
const [currentStep, setCurrentStep] = useState(); |
| 80 |
const { dismissTask } = useTasksStore(); |
| 81 |
|
| 82 |
useEffect(() => { |
| 83 |
if (currentStep) return; |
| 84 |
setCurrentStep(getCurrentLaunchStep()); |
| 85 |
}, [currentStep]); |
| 86 |
|
| 87 |
const stepData = useAgentOnboarding ? autoLaunch : launchSteps[currentStep]; |
| 88 |
|
| 89 |
const launchUrl = `${window.extSharedData.adminUrl}admin.php?page=${ |
| 90 |
useAgentOnboarding ? 'extendify-auto-launch' : 'extendify-launch' |
| 91 |
}`; |
| 92 |
|
| 93 |
return ( |
| 94 |
<div className="h-full justify-center overflow-hidden bg-white/95 text-base"> |
| 95 |
<div className="flex h-full flex-col items-center justify-center gap-5 p-7 text-center md:p-8"> |
| 96 |
{task?.htmlBefore()} |
| 97 |
<div className="flex h-full flex-col items-center justify-center text-center lg:justify-between"> |
| 98 |
<div> |
| 99 |
<h2 className="mb-2 text-2xl font-semibold leading-10 md:mt-0 lg:text-2xl"> |
| 100 |
{stepData?.title} |
| 101 |
</h2> |
| 102 |
<p className="m-0 text-sm md:text-base">{stepData?.description}</p> |
| 103 |
</div> |
| 104 |
<div className="cta mt-6 flex flex-wrap items-center text-sm md:gap-3 lg:mt-3"> |
| 105 |
<a |
| 106 |
href={launchUrl} |
| 107 |
className="min-w-24 cursor-pointer rounded-xs bg-design-main px-4 py-2.5 text-sm font-medium text-design-text no-underline hover:opacity-90" |
| 108 |
> |
| 109 |
{stepData?.buttonText} |
| 110 |
</a> |
| 111 |
<button |
| 112 |
type="button" |
| 113 |
id="dismiss" |
| 114 |
onClick={() => { |
| 115 |
dismissTask('site-builder-launcher'); |
| 116 |
}} |
| 117 |
className="bg-transparent text-sm text-design-main underline-offset-4 hover:underline" |
| 118 |
> |
| 119 |
{__('Dismiss', 'extendify-local')} |
| 120 |
</button> |
| 121 |
</div> |
| 122 |
</div> |
| 123 |
</div> |
| 124 |
</div> |
| 125 |
); |
| 126 |
}; |
| 127 |
|