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 / assets / src / Components / Migration.js
templates-patterns-collection / assets / src / Components Last commit date
CloudLibrary 1 year ago Settings 1 year ago StarterSites 3 years ago App.js 2 years ago Card.js 3 years ago CategoriesTabs.js 3 years ago CategorySelector.js 2 years ago CustomTooltip.js 3 years ago DocNotice.js 2 years ago EditorSelector.js 2 years ago EditorTabs.js 4 years ago Header.js 2 years ago Icon.js 2 years ago ImportModal.js 1 year ago ImportModalError.js 2 years ago ImportModalMock.js 4 years ago ImportModalNote.js 4 years ago ImportStepper.js 1 year ago InstallModal.js 1 year ago License.js 2 years ago LicensePanelContext.js 3 years ago Loading.js 4 years ago Main.js 1 year ago Migration.js 4 years ago NewTCNotice.js 1 year ago Notification.js 4 years ago OnboardingContent.js 4 years ago PreviewFrame.js 3 years ago Search.js 2 years ago StarterSiteCard.js 3 years ago
Migration.js
276 lines
1 /* global tiobDash */
2 import { send } from '../utils/rest';
3 import { installPlugins } from '../utils/site-import';
4 import ImportModalNote from './ImportModalNote';
5 import ImportModalError from './ImportModalError';
6
7 import { __ } from '@wordpress/i18n';
8 import { Dashicon, Button, Modal } from '@wordpress/components';
9 import { useState, Fragment } from '@wordpress/element';
10
11 const Migration = ( { data } ) => {
12 const setToast = ( string ) => console.log( string );
13 const [ dismissed, setDismissed ] = useState( false );
14 const [ modalOpen, setModalOpen ] = useState( false );
15 const [ migrating, setMigrating ] = useState( false );
16 const [ error, setError ] = useState( null );
17 const [ frontPageID, setFrontPageID ] = useState( null );
18
19 if ( dismissed ) {
20 return null;
21 }
22
23 const closeModal = () => {
24 if ( 'done' === migrating ) {
25 setDismissed( true );
26 }
27 setModalOpen( false );
28 setError( null );
29 setMigrating( false );
30 };
31
32 function startMigration() {
33 const plugins = Object.keys( data.mandatory_plugins ).reduce( function (
34 p,
35 key
36 ) {
37 p[ key ] = true;
38 return p;
39 },
40 {} );
41
42 installPlugins( plugins ).then( ( r ) => {
43 setMigrating( true );
44 if ( ! r.success ) {
45 setError( {
46 code: r.data || null,
47 message: __(
48 'Something went wrong while installing the necessary plugins.',
49 'templates-patterns-collection'
50 ),
51 } );
52 setMigrating( false );
53 return false;
54 }
55 const { template, template_name } = data;
56 send( tiobDash.onboarding.root + '/migrate_frontpage', {
57 template,
58 template_name,
59 } ).then( ( r ) => {
60 if ( ! r.success ) {
61 setError( {
62 code: r.data || null,
63 message: __(
64 'Something went wrong while importing the website content.',
65 'templates-patterns-collection'
66 ),
67 } );
68 setMigrating( false );
69 return false;
70 }
71 setFrontPageID( r.data );
72 setMigrating( 'done' );
73 } );
74 } );
75 }
76
77 const renderModal = () => {
78 return (
79 <Modal
80 className="ob-import-modal migration"
81 title={
82 __( 'Migrate', 'templates-patterns-collection' ) +
83 ' ' +
84 data.theme_name
85 }
86 onRequestClose={ closeModal }
87 shouldCloseOnClickOutside={ ! migrating }
88 isDismissible={ ! migrating }
89 >
90 <Fragment>
91 <div className="modal-body">
92 { error && (
93 <ImportModalError
94 message={ error.message || null }
95 code={ error.code || null }
96 />
97 ) }
98 { false === migrating && ! error && (
99 <Fragment>
100 <ImportModalNote data={ data } />
101 { data.mandatory_plugins && (
102 <Fragment>
103 <hr />
104 <h3>
105 { __(
106 'The following plugins will be installed',
107 'templates-patterns-collection'
108 ) }
109 :
110 </h3>
111 <ul>
112 { Object.keys(
113 data.mandatory_plugins
114 ).map( ( k, index ) => (
115 <li key={ index }>
116 -{ ' ' }
117 {
118 data.mandatory_plugins[
119 k
120 ]
121 }
122 </li>
123 ) ) }
124 </ul>
125 </Fragment>
126 ) }
127 </Fragment>
128 ) }
129 { 'done' === migrating && (
130 <p className="import-result">
131 { __(
132 'Content was successfully imported. Enjoy your new site!',
133 'templates-patterns-collection'
134 ) }
135 </p>
136 ) }
137 { true === migrating && (
138 <div className="loading">
139 <Dashicon icon="update" size={ 50 } />
140 <h3>
141 { __(
142 'Migrating',
143 'templates-patterns-collection'
144 ) }
145 ...
146 </h3>
147 </div>
148 ) }
149 </div>
150 { ( ! migrating || 'done' === migrating ) && (
151 <div className="modal-footer">
152 <Button
153 isSecondary={ 'done' !== migrating }
154 isLink={ 'done' === migrating }
155 className={
156 'done' === migrating ? 'close' : null
157 }
158 onClick={ closeModal }
159 >
160 { 'done' === migrating
161 ? __(
162 'Close',
163 'templates-patterns-collection'
164 )
165 : __(
166 'Cancel',
167 'templates-patterns-collection'
168 ) }
169 </Button>
170 { ! error && 'done' !== migrating ? (
171 <Button
172 isPrimary
173 onClick={ () => {
174 startMigration();
175 } }
176 >
177 { __(
178 'Start Migration',
179 'templates-patterns-collection'
180 ) }
181 </Button>
182 ) : (
183 <Fragment>
184 <Button
185 style={ { marginLeft: 20 } }
186 isSecondary
187 href={ `${ tiobDash.onboarding.homeUrl }/wp-admin/post.php?post=${ frontPageID }&action=elementor` }
188 >
189 { __(
190 'Edit Content',
191 'templates-patterns-collection'
192 ) }
193 </Button>
194 <Button
195 isPrimary
196 href={ tiobDash.onboarding.homeUrl }
197 >
198 { __(
199 'View Website',
200 'templates-patterns-collection'
201 ) }
202 </Button>
203 </Fragment>
204 ) }
205 </div>
206 ) }
207 </Fragment>
208 </Modal>
209 );
210 };
211
212 return (
213 <div className="ob-migration">
214 { modalOpen && renderModal() }
215 <h2>{ data.heading }</h2>
216 <p>{ data.description }</p>
217 <div className="card starter-site-card" style={ { maxWidth: 330 } }>
218 <div className="top">
219 { data.screenshot && (
220 <div className="image">
221 <img
222 src={ data.screenshot }
223 alt={ data.theme_name }
224 />
225 </div>
226 ) }
227 </div>
228 <div className="bottom">
229 <p className="title">{ data.theme_name }</p>
230 </div>
231 </div>
232 <div className="actions">
233 <Button
234 isPrimary
235 onClick={ () => {
236 setModalOpen( true );
237 return false;
238 } }
239 >
240 { __( 'Migrate', 'templates-patterns-collection' ) +
241 ' ' +
242 data.theme_name }
243 </Button>
244 <Button
245 isSecondary
246 onClick={ () => {
247 send( tiobDash.onboarding.root + '/dismiss_migration', {
248 theme_mod: data.theme_mod,
249 } ).then( ( r ) => {
250 if ( ! r.success ) {
251 setToast(
252 __(
253 'Something went wrong. Please reload the page and try again.',
254 'templates-patterns-collection'
255 )
256 );
257 return false;
258 }
259 setToast(
260 __(
261 'Dismissed',
262 'templates-patterns-collection'
263 )
264 );
265 setDismissed( true );
266 } );
267 } }
268 >
269 { __( 'Dismiss', 'templates-patterns-collection' ) }
270 </Button>
271 </div>
272 </div>
273 );
274 };
275 export default Migration;
276