steps
1 year ago
App.jsx
1 year ago
Footer.jsx
1 year ago
Header.jsx
1 year ago
StepFooter.jsx
1 year ago
StepWrapper.jsx
1 year ago
onboarding.js
1 year ago
App.jsx
131 lines
| 1 | /** |
| 2 | * External Dependencies |
| 3 | */ |
| 4 | import { useState } from '@wordpress/element'; |
| 5 | |
| 6 | /** |
| 7 | * Internal Dependencies |
| 8 | */ |
| 9 | import Header from './Header'; |
| 10 | import Footer from './Footer'; |
| 11 | import StepWrapper from './StepWrapper'; |
| 12 | import { Wizard } from '@components/wizard'; |
| 13 | import Step1 from './steps/Step1'; |
| 14 | import GoogleAdsense from './steps/GoogleAdsense'; |
| 15 | import BannerAd from './steps/BannerAd'; |
| 16 | import CodeAd from './steps/CodeAd'; |
| 17 | import Congrats from './steps/Congrats'; |
| 18 | |
| 19 | let initDone = false; |
| 20 | function initialState() { |
| 21 | const initial = { |
| 22 | startIndex: 1, |
| 23 | taskOption: 'google_adsense', |
| 24 | googleAdsPlacement: 'manual', |
| 25 | autoAdsOptions: [], |
| 26 | adsenseData: false, |
| 27 | }; |
| 28 | const params = new URLSearchParams(document.location.search); |
| 29 | const wizardData = advancedAds.wizard.adsenseData; |
| 30 | |
| 31 | if ( |
| 32 | 'adsense' === params.get('route') && |
| 33 | 'advanced-ads-onboarding' === params.get('page') |
| 34 | ) { |
| 35 | initial.startIndex = 2; |
| 36 | initial.taskOption = 'google_adsense'; |
| 37 | } |
| 38 | |
| 39 | if ( |
| 40 | 'image' === params.get('route') && |
| 41 | 'advanced-ads-onboarding' === params.get('page') |
| 42 | ) { |
| 43 | initial.startIndex = 2; |
| 44 | initial.taskOption = 'ad_image'; |
| 45 | } |
| 46 | |
| 47 | if (!Array.isArray(wizardData.accounts)) { |
| 48 | const adsenseId = wizardData['adsense-id']; |
| 49 | initial.adsenseData = { |
| 50 | account: { |
| 51 | id: adsenseId, |
| 52 | name: wizardData.accounts[adsenseId].details.name, |
| 53 | }, |
| 54 | }; |
| 55 | } |
| 56 | |
| 57 | if (!initDone) { |
| 58 | if (wizardData.amp) { |
| 59 | initial.autoAdsOptions.push('enableAmp'); |
| 60 | } |
| 61 | |
| 62 | if (wizardData['page-level-enabled']) { |
| 63 | initial.autoAdsOptions.push('enable'); |
| 64 | } |
| 65 | |
| 66 | initDone = true; |
| 67 | } |
| 68 | |
| 69 | return initial; |
| 70 | } |
| 71 | |
| 72 | export default function App() { |
| 73 | const [options, setOptions] = useState({ |
| 74 | ...initialState(), |
| 75 | }); |
| 76 | |
| 77 | const handleOptions = (key, value) => { |
| 78 | const newOptions = { |
| 79 | ...options, |
| 80 | [key]: value, |
| 81 | }; |
| 82 | setOptions(newOptions); |
| 83 | }; |
| 84 | |
| 85 | return ( |
| 86 | <div className="advads-onboarding advads-onboarding-frame"> |
| 87 | <div className="absolute top-0 max-w-3xl w-full py-20"> |
| 88 | <Wizard |
| 89 | header={<Header />} |
| 90 | footer={<Footer />} |
| 91 | startIndex={options.startIndex} |
| 92 | > |
| 93 | <StepWrapper> |
| 94 | <Step1 options={options} setOptions={handleOptions} /> |
| 95 | </StepWrapper> |
| 96 | {'google_adsense' === options.taskOption && ( |
| 97 | <StepWrapper className="pb-4"> |
| 98 | <GoogleAdsense |
| 99 | options={options} |
| 100 | setOptions={handleOptions} |
| 101 | /> |
| 102 | </StepWrapper> |
| 103 | )} |
| 104 | {'ad_image' === options.taskOption && ( |
| 105 | <StepWrapper className="pb-4"> |
| 106 | <BannerAd |
| 107 | options={options} |
| 108 | setOptions={handleOptions} |
| 109 | /> |
| 110 | </StepWrapper> |
| 111 | )} |
| 112 | {'ad_code' === options.taskOption && ( |
| 113 | <StepWrapper className="pb-4"> |
| 114 | <CodeAd |
| 115 | options={options} |
| 116 | setOptions={handleOptions} |
| 117 | /> |
| 118 | </StepWrapper> |
| 119 | )} |
| 120 | <StepWrapper> |
| 121 | <Congrats |
| 122 | options={options} |
| 123 | setOptions={handleOptions} |
| 124 | /> |
| 125 | </StepWrapper> |
| 126 | </Wizard> |
| 127 | </div> |
| 128 | </div> |
| 129 | ); |
| 130 | } |
| 131 |