import Box from '@elementor/ui/Box'; import { ThemeProvider } from '@elementor/ui/styles'; import { __ } from '@wordpress/i18n'; import { useCallback, useState } from 'react'; import { useAdminContext } from '../hooks/use-admin-context'; import Modal from '@elementor/ui/Modal'; import { TopBarContent } from '../components/top-bar/top-bar-content'; import { GetStarted } from '../components/onboarding/screens/get-started'; import Spinner from '../components/spinner/spinner'; import { InstallKit } from '../components/onboarding/screens/install-kit'; import { ReadyToGo } from '../components/onboarding/screens/ready-to-go'; import { Preview } from '../components/onboarding/screens/preview'; export const OnboardingPage = () => { const [ message, setMessage ] = useState( '' ); const [ severity, setSeverity ] = useState( 'info' ); const [ previewKit, setPreviewKit ] = useState( null ); const { isLoading, setIsLoading, stepAction, step, onboardingSettings: { nonce, modalCloseRedirectUrl, kits, getStartedText = {}, readyToGoText = {}, installKitText = {} } = {}, } = useAdminContext(); const { title = '', description = '', disclaimer = '', termsUrl = '', termsText = '', buttonText: getStartedButtonText = '', } = getStartedText; const { title: readyTitle = '', description: readyDescription = '', viewSite = '', customizeSite = '', } = readyToGoText; const { title: kitTitle = '', description: kitDescription = '', } = installKitText; const onClick = useCallback( async () => { setMessage( '' ); const data = { step: stepAction, _wpnonce: nonce, slug: 'elementor', }; setIsLoading( true ); try { switch ( stepAction ) { case 'install-elementor': const response = await wp.ajax.post( 'helloplus_setup_wizard', data ); if ( response.activateUrl ) { const activate = await fetch( response.activateUrl ); if ( activate.ok ) { window.location.reload(); } else { throw new Error( __( 'Failed to activate Elementor plugin', 'hello-plus' ) ); } } break; case 'activate-elementor': await wp.ajax.post( 'helloplus_setup_wizard', data ); window.location.reload(); break; default: break; } } catch ( error ) { setMessage( error.errorMessage ); setSeverity( 'error' ); } finally { setIsLoading( false ); } }, [ nonce, setIsLoading, stepAction ] ); const onClose = () => { window.location.href = modalCloseRedirectUrl; }; return ( { ! previewKit && ( ) } { 0 === step && ! isLoading && ! previewKit && ( ) } { 1 === step && ! isLoading && ! previewKit && ( ) } { 2 === step && ! isLoading && ! previewKit && ( ) } { previewKit && } { isLoading && } ); };