PluginProbe
Hello Plus / 1.5.2
Hello Plus v1.5.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / admin / assets / js / providers / admin-provider.js

admin-provider.js in Hello Plus 1.5.2, at modules/admin/assets/js/providers/admin-provider.js

69 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { createContext, useEffect, useState } from 'react';
2 import apiFetch from '@wordpress/api-fetch';
3 import { __ } from '@wordpress/i18n';
4
5 export const AdminContext = createContext();
6
7 export const AdminProvider = ( { children } ) => {
8 const [ isLoading, setIsLoading ] = React.useState( true );
9 const [ onboardingSettings, setOnboardingSettings ] = React.useState( {} );
10 const [ elementorKitSettings, setElementorKitSettings ] = React.useState( {} );
11 const [ stepAction, setStepAction ] = useState( '' );
12 const [ step, setStep ] = useState( 0 );
13 const [ buttonText, setButtonText ] = useState( '' );
14 const { elementorInstalled, elementorActive, wizardCompleted } = onboardingSettings;
15 const { elementorAppConfig } = window;
16
17 useEffect( () => {
18 if ( elementorAppConfig ) {
19 setElementorKitSettings( elementorAppConfig[ 'kit-library' ] );
20 }
21 }, [ elementorAppConfig ] );
22
23 useEffect( () => {
24 if ( wizardCompleted ) {
25 setStep( 2 );
26 return;
27 }
28 if ( false === elementorInstalled ) {
29 setStepAction( 'install-elementor' );
30 setButtonText( __( 'Start building my website', 'hello-plus' ) );
31 }
32 if ( elementorInstalled && false === elementorActive ) {
33 setStepAction( 'activate-elementor' );
34 setButtonText( __( 'Start building my website', 'hello-plus' ) );
35 }
36 if ( elementorInstalled && elementorActive ) {
37 setStepAction( 'install-kit' );
38 setButtonText( __( 'Install Kit', 'hello-plus' ) );
39 setStep( 1 );
40 }
41 }, [ elementorInstalled, elementorActive, wizardCompleted ] );
42
43 useEffect( () => {
44 Promise.all( [
45 apiFetch( { path: '/elementor-hello-plus/v1/onboarding-settings' } ),
46 ] ).then( ( [ onboarding ] ) => {
47 setOnboardingSettings( onboarding.settings );
48 } ).finally( () => {
49 setIsLoading( false );
50 } );
51 }, [] );
52
53 return (
54 <AdminContext.Provider value={ {
55 onboardingSettings,
56 stepAction,
57 setStepAction,
58 buttonText,
59 step,
60 setStep,
61 isLoading,
62 elementorKitSettings,
63 setIsLoading,
64 } }>
65 { children }
66 </AdminContext.Provider>
67 );
68 };
69