PluginProbe ʕ •ᴥ•ʔ
Starter Sites & Templates by Neve / trunk
Starter Sites & Templates by Neve vtrunk
1.4.0 1.3.0 1.2.29 1.2.28 1.2.6 1.2.7 1.2.8 1.2.9 trunk 1.0.10 1.0.11 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.27 1.1.28 1.1.29 1.1.3 1.1.30 1.1.31 1.1.32 1.1.33 1.1.34 1.1.35 1.1.36 1.1.37 1.1.38 1.1.39 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.3 1.2.4 1.2.5
templates-patterns-collection / onboarding / src / Components / ImportForm.js
templates-patterns-collection / onboarding / src / Components Last commit date
CustomizeControls 2 months ago Steps 2 weeks ago App.js 2 years ago CategoryButtons.js 2 weeks ago CustomTooltip.js 2 years ago EditorSelector.js 2 years ago FeaturesList.js 1 year ago Filters.js 2 weeks ago Header.js 2 weeks ago ImportError.js 2 years ago ImportForm.js 1 year ago ImportMock.js 2 years ago ImportProgress.js 1 year ago Onboarding.js 2 weeks ago ProgressBar.js 2 years ago Search.js 2 weeks ago SitePreview.js 2 years ago SiteSettings.js 2 months ago Sites.js 2 weeks ago StarterSiteCard.js 2 weeks ago Toast.js 2 weeks ago WelcomeMock.js 2 years ago
ImportForm.js
193 lines
1 /* global tiobDash */
2 /* eslint-disable no-console */
3 import { __ } from '@wordpress/i18n';
4 import { TextControl, Button, SelectControl } from '@wordpress/components';
5 import { useState } from '@wordpress/element';
6 import { ajaxAction, track } from '../utils/rest';
7 import { withSelect } from '@wordpress/data';
8
9 const ImportForm = ( { trackingId } ) => {
10 const [ email, setEmail ] = useState( tiobDash.emailSubscribe.email || '' );
11 const [ userLevel, setUserLevel ] = useState( '' );
12 const [ buildingFor, setBuildingFor ] = useState( '' );
13 const [ processingSub, setProcessingSub ] = useState( false );
14
15 const userLevelMap = [
16 {
17 disabled: true,
18 label: __( 'I am a…', 'templates-patterns-collection' ),
19 value: '',
20 },
21 {
22 label: __( 'Beginner', 'templates-patterns-collection' ),
23 value: 'beginner',
24 },
25 {
26 label: __( 'Intermediate', 'templates-patterns-collection' ),
27 value: 'intermediate',
28 },
29 {
30 label: __( 'Expert', 'templates-patterns-collection' ),
31 value: 'expert',
32 },
33 ];
34 const buildingForMap = [
35 {
36 disabled: true,
37 label: __(
38 'I build this site for…',
39 'templates-patterns-collection'
40 ),
41 value: '',
42 },
43 {
44 label: __( 'Myself', 'templates-patterns-collection' ),
45 value: 'myself',
46 },
47 {
48 label: __( 'My Company', 'templates-patterns-collection' ),
49 value: 'company',
50 },
51 {
52 label: __( 'My Client', 'templates-patterns-collection' ),
53 value: 'client',
54 },
55 ];
56
57 const site = tiobDash.onboarding.homeUrl || '';
58
59 const viewWebsiteAndSubscribe = ( event, skipSubscribe = false ) => {
60 event.preventDefault();
61
62 setProcessingSub( true );
63
64 const trackData = {
65 slug: 'neve',
66 license_id: tiobDash.license,
67 site: tiobDash.onboarding.homeUrl || '',
68 user_meta: {
69 email,
70 i_am: userLevel,
71 making_website_for: buildingFor,
72 },
73 step_id: 5,
74 step_status: skipSubscribe ? 'skip' : 'completed',
75 };
76 const trackingPromise = track( trackingId, trackData );
77
78 let subscribePromise;
79 if ( ! skipSubscribe ) {
80 subscribePromise = fetch(
81 'https://api.themeisle.com/tracking/subscribe',
82 {
83 method: 'POST',
84 headers: {
85 'Content-Type': 'application/json',
86 },
87 body: JSON.stringify( {
88 slug: 'templates-patterns-collection',
89 site,
90 email,
91 } ),
92 }
93 );
94 }
95
96 const finishImportPromise = ajaxAction(
97 tiobDash.onboardingDone.ajaxURL,
98 'mark_onboarding_done',
99 tiobDash.onboardingDone.nonce
100 );
101
102 Promise.all( [
103 trackingPromise,
104 subscribePromise,
105 finishImportPromise,
106 ] )
107 .catch( ( error ) => {
108 console.error( error );
109 } )
110 .finally( () => {
111 window.location.href = site;
112 } );
113 };
114
115 return (
116 <>
117 <p>
118 { __(
119 // eslint-disable-next-line
120 "You're all set. Tell us a bit about yourself.",
121 'templates-patterns-collection'
122 ) }
123 </p>
124 <form
125 className="ob-subscribe-form"
126 onSubmit={ ( event ) => {
127 viewWebsiteAndSubscribe( event );
128 } }
129 >
130 <div className="ob-form-wrap">
131 <TextControl
132 aria-label={ __(
133 'Enter your email',
134 'templates-patterns-collection'
135 ) }
136 type="email"
137 value={ email }
138 onChange={ setEmail }
139 />
140 <SelectControl
141 className="ob-select"
142 options={ userLevelMap }
143 value={ userLevel }
144 onChange={ setUserLevel }
145 />
146 <SelectControl
147 className="ob-select"
148 options={ buildingForMap }
149 value={ buildingFor }
150 onChange={ setBuildingFor }
151 />
152 </div>
153 <div className="ob-done-actions">
154 <Button
155 type="submit"
156 isPrimary
157 className="ob-button full"
158 disabled={
159 processingSub ||
160 ( ! email && ! userLevel && ! buildingFor )
161 }
162 >
163 { __(
164 'Submit and view site',
165 'templates-patterns-collection'
166 ) }
167 </Button>
168 <Button
169 isLink
170 className="close is-grayed"
171 disabled={ processingSub }
172 onClick={ ( event ) =>
173 viewWebsiteAndSubscribe( event, true )
174 }
175 >
176 { __(
177 'Skip and view site',
178 'templates-patterns-collection'
179 ) }
180 </Button>
181 </div>
182 </form>
183 </>
184 );
185 };
186
187 export default withSelect( ( select ) => {
188 const { getTrackingId } = select( 'ti-onboarding' );
189 return {
190 trackingId: getTrackingId(),
191 };
192 } )( ImportForm );
193