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 / InstallModal.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
InstallModal.js
195 lines
1 /* global tiobDash */
2
3 import { Button, Modal } from '@wordpress/components';
4 import { withDispatch, withSelect } from '@wordpress/data';
5 import { compose } from '@wordpress/compose';
6 import { useState } from '@wordpress/element';
7 import { __, sprintf } from '@wordpress/i18n';
8 import { get } from '../utils/rest';
9
10 const InstallModal = ( {
11 setImportModal,
12 setInstallModal,
13 themeData,
14 setThemeAction,
15 singleImport,
16 showTemplateModal,
17 } ) => {
18 const { action, slug, nonce } = themeData;
19 const { themesURL, brandedTheme } = tiobDash;
20 const [ installing, setInstalling ] = useState( false );
21 const [ error, setError ] = useState( null );
22 const handleDismiss = () => {
23 setInstallModal( false );
24 };
25
26 const handleError = ( message ) => {
27 setInstalling( false );
28 setError(
29 sprintf(
30 // translators: %s: Error message.
31 __(
32 'An error has ocurred: %s',
33 'templates-patterns-collection'
34 ),
35 message
36 )
37 );
38 };
39
40 const handleInstall = () => {
41 setInstalling( 'installing' );
42 wp.updates.installTheme( {
43 slug: 'neve',
44 success: () => {
45 setThemeAction( { ...themeData, action: 'activate' } );
46 handleActivate();
47 },
48 error: ( err ) => {
49 setThemeAction( { ...themeData, action: 'activate' } );
50 handleError(
51 err.errorMessage ||
52 __(
53 'Could not install theme.',
54 'templates-patterns-collection'
55 )
56 );
57 },
58 } );
59 };
60
61 const handleActivate = () => {
62 setInstalling( 'activating' );
63 const url = `${ themesURL }?action=activate&stylesheet=${ slug }&_wpnonce=${ nonce }`;
64 get( url, true ).then( ( response ) => {
65 if ( response.status !== 200 ) {
66 handleError(
67 __(
68 'Could not activate theme.',
69 'templates-patterns-collection'
70 )
71 );
72 setInstalling( false );
73 return false;
74 }
75 setInstalling( false );
76 setInstallModal( false );
77 setThemeAction( false );
78 if ( singleImport ) {
79 showTemplateModal();
80 return false;
81 }
82 setImportModal( true );
83 } );
84 };
85
86 return (
87 <Modal
88 className="ob-import-modal install-modal"
89 title={ __(
90 'Install and Activate Neve',
91 'templates-patterns-collection'
92 ) }
93 onRequestClose={ handleDismiss }
94 shouldCloseOnClickOutside={ ! installing }
95 isDismissible={ ! installing }
96 >
97 <div className="modal-body" style={ { textAlign: 'center' } }>
98 { ! brandedTheme && (
99 <img
100 style={ { width: 75 } }
101 src={ `${ tiobDash.assets }/img/logo.svg` }
102 alt={ __( 'Logo', 'templates-patterns-collection' ) }
103 />
104 ) }
105 { error && (
106 <div className="well error" style={ { margin: '20px 0' } }>
107 { error }
108 </div>
109 ) }
110 <p
111 style={ {
112 lineHeight: 1.6,
113 fontSize: '15px',
114 } }
115 >
116 { __(
117 'In order to import the starter site, Neve theme has to be installed and activated. Click the button below to install and activate Neve',
118 'templates-patterns-collection'
119 ) }
120 </p>
121 </div>
122 <div
123 className="modal-footer"
124 style={ { justifyContent: 'center' } }
125 >
126 <div className="actions" style={ { display: 'flex' } }>
127 { ! error && (
128 <Button
129 dismiss={ error }
130 isPrimary
131 disabled={ installing }
132 className={ installing && 'is-loading' }
133 icon={ installing && 'update' }
134 onClick={
135 action === 'install'
136 ? handleInstall
137 : handleActivate
138 }
139 >
140 { installing &&
141 ( installing === 'installing'
142 ? __( 'Installing', 'templates-patterns-collection' )
143 : __( 'Activating', 'templates-patterns-collection' ) ) }
144
145 { ! installing &&
146 ( action === 'install'
147 ? __(
148 'Install and Activate',
149 'templates-patterns-collection'
150 )
151 : __(
152 'Activate',
153 'templates-patterns-collection'
154 ) ) }
155 </Button>
156 ) }
157 <Button
158 style={ { marginLeft: 30 } }
159 isSecondary
160 disabled={ installing }
161 onClick={ handleDismiss }
162 >
163 { __( 'Close', 'templates-patterns-collection' ) }
164 </Button>
165 </div>
166 </div>
167 </Modal>
168 );
169 };
170
171 export default compose(
172 withSelect( ( select ) => {
173 const { getSingleImport, getThemeAction } = select( 'neve-onboarding' );
174
175 return {
176 themeData: getThemeAction() || false,
177 singleImport: getSingleImport(),
178 };
179 } ),
180 withDispatch( ( dispatch ) => {
181 const {
182 setImportModalStatus,
183 setInstallModalStatus,
184 setThemeAction,
185 setTemplateModal,
186 } = dispatch( 'neve-onboarding' );
187 return {
188 setImportModal: ( status ) => setImportModalStatus( status ),
189 setInstallModal: ( status ) => setInstallModalStatus( status ),
190 setThemeAction: ( status ) => setThemeAction( status ),
191 showTemplateModal: () => setTemplateModal( true ),
192 };
193 } )
194 )( InstallModal );
195