Skip to content

Commit

Permalink
finish UX
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoladj77 committed Oct 10, 2024
1 parent c0c9beb commit 6deeb74
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Checkbox from '@elementor/ui/Checkbox';
import Link from '@elementor/ui/Link';
import { __ } from '@wordpress/i18n';

export const GetStarted = ( { message, buttonText, onClick, severity } ) => {
export const GetStarted = ( { message, buttonText, onClick, severity, allowTracking, setAllowTracking } ) => {
return (
<>
<Stack direction="column" alignItems="center" justifyContent="center">
Expand Down Expand Up @@ -36,7 +36,7 @@ export const GetStarted = ( { message, buttonText, onClick, severity } ) => {
<Stack direction="column" alignItems="center" justifyContent="center" sx={ { marginTop: 'auto', pb: 4 } }>
<Stack sx={ { maxWidth: 'fit-content' } } alignItems="center" justifyContent="center">
<Stack direction="row" alignItems="center" justifyContent="center" >
<Checkbox sx={ { p: 0.5 } } size="small" defaultChecked color="default" />
<Checkbox sx={ { p: 0.5 } } size="small" checked={ allowTracking } onClick={ () => setAllowTracking( ! allowTracking ) } color="default" />
<Typography variant="body1" align="center" color="text.tertiary">
{ __( 'Become a super contributor by sharing non-sensitive plugin data to help us improve the tools you use every day.', 'hello-plus' ) }
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Navigation } from '../navigation';
import Typography from '@elementor/ui/Typography';
import Alert from '@elementor/ui/Alert';
import { __ } from '@wordpress/i18n';
import Grid from '@elementor/ui/Grid';
import Image from '@elementor/ui/Image';

export const InstallKit = ( { message, buttonText, onClick, severity } ) => {
export const InstallKit = ( { message, kits = [], setPreviewKit, severity } ) => {
return (
<Stack direction="column" alignItems="center" justifyContent="center">
<Stack sx={ { maxWidth: 662 } } alignItems="center" justifyContent="center" gap={ 4 }>
Expand All @@ -22,6 +24,19 @@ export const InstallKit = ( { message, buttonText, onClick, severity } ) => {
}
</Typography>
{ message && <Alert severity={ severity }>{ message }</Alert> }

<Grid container rowSpacing={ 3 } columnSpacing={ 5 } >
{ kits.map( ( kit ) => (
<Grid key={ kit._id } item xs={ 12 } sm={ 6 } md={ 3 }>
<Stack direction="column" gap={ 2 } >
<Typography variant="body2" sx={ { height: 40 } }>{ kit.title }</Typography>
<Image src={ kit.thumbnail } alt={ kit.title } sx={ { cursor: 'pointer', borderRadius: 1 } } onClick={ () => {
setPreviewKit( 'english-pub-hp' );
} } />
</Stack>
</Grid>
) ) }
</Grid>
</Stack>
</Stack>
</Stack>
Expand Down
44 changes: 44 additions & 0 deletions modules/admin/assets/js/components/onboarding/screens/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Stack from '@elementor/ui/Stack';
import Box from '@elementor/ui/Box';
import Typography from '@elementor/ui/Typography';
import { __ } from '@wordpress/i18n';
import ChevronRightIcon from '@elementor/icons/ChevronRightIcon';
import Button from '@elementor/ui/Button';

export const Preview = ( { slug, title, setPreviewKit, setStep } ) => {
return (
<>
<Stack direction="row" sx={ { alignItems: 'center', height: 50, px: 2, backgroundColor: 'background.default', justifyContent: 'space-between' } }>
<Stack
direction="row"
spacing={ 1 }
alignItems="center"
sx={ { borderRight: '1px solid var(--divider-divider, rgba(0, 0, 0, 0.12))', width: 'fit-content', p: 2, cursor: 'pointer' } }
onClick={ () => setPreviewKit( '' ) }
>
<ChevronRightIcon sx={ { transform: 'rotate(180deg)' } } color="action" />
<Typography variant="subtitle1" color="action">{ __( 'Back to Wizard', 'hello-plus' ) }</Typography>
</Stack>
<Stack direction="row" gap={ 1 }>
<Button variant="outlined" color="primary">
{ __( 'Overview', 'hello-plus' ) }
</Button>
<Button variant="contained" color="primary" onClick={ () => {
setPreviewKit( '' );
setStep( 2 );
} }>
{ __( 'Apply Kit', 'hello-plus' ) }
</Button>
</Stack>
</Stack>
<Box sx={ { position: 'relative', width: '100%', height: '100%' } }>
<iframe
src={ `https://library.elementor.com/${ slug }/` }
style={ { position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', border: 'none' } }
title={ title }
/>
</Box>
</>

);
};
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import Stack from '@elementor/ui/Stack';
import { Navigation } from '../navigation';
import Typography from '@elementor/ui/Typography';
import Alert from '@elementor/ui/Alert';
import Box from '@elementor/ui/Box';
import Button from '@elementor/ui/Button';
import { __ } from '@wordpress/i18n';

export const ReadyToGo = ( { message, buttonText, onClick, severity } ) => {
export const ReadyToGo = ( { modalCloseRedirectUrl } ) => {
return (
<Stack direction="column" alignItems="center" justifyContent="center">
<Stack sx={ { maxWidth: 662 } } alignItems="center" justifyContent="center" gap={ 4 }>
Expand All @@ -23,10 +21,18 @@ export const ReadyToGo = ( { message, buttonText, onClick, severity } ) => {
)
}
</Typography>
{ message && <Alert severity={ severity }>{ message }</Alert> }
<Box p={ 1 } mt={ 6 }>
{ buttonText && <Button variant="contained" onClick={ onClick }>{ buttonText }</Button> }
</Box>
<Stack direction="row" gap={ 1 } mt={ 5 }>
<Button variant="outlined" color="primary" onClick={ () => {
window.location.href = modalCloseRedirectUrl;
} }>
{ __( 'Customize my site', 'hello-plus' ) }
</Button>
<Button variant="contained" color="primary" onClick={ () => {
window.location.href = '/';
} }>
{ __( 'View my site', 'hello-plus' ) }
</Button>
</Stack>
</Stack>
</Stack>
</Stack>
Expand Down
2 changes: 1 addition & 1 deletion modules/admin/assets/js/hooks/use-get-current-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const useGetCurrentStep = () => {
if ( elementorInstalled && elementorActive ) {
setStepAction( 'install-kit' );
setButtonText( __( 'Install Kit', 'hello-plus' ) );
setStep( 0 );
setStep( 1 );
}
}, [ elementorInstalled, elementorActive ] );

Expand Down
33 changes: 25 additions & 8 deletions modules/admin/assets/js/pages/onboarding-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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';

const style = {
position: 'fixed',
Expand All @@ -28,9 +29,11 @@ export const OnboardingPage = () => {
const [ message, setMessage ] = useState( '' );
const [ severity, setSeverity ] = useState( 'info' );
const [ loading, setLoading ] = useState( false );
const [ previewKit, setPreviewKit ] = useState( null );
const [ allowTracking, setAllowTracking ] = useState( true );

const { onboardingSettings: { nonce, modalCloseRedirectUrl } = {} } = useAdminContext();
const { stepAction, buttonText, step } = useGetCurrentStep();
const { onboardingSettings: { nonce, modalCloseRedirectUrl, kits } = {} } = useAdminContext();
const { stepAction, buttonText, step, setStep } = useGetCurrentStep();

const onClick = useCallback( async () => {
setMessage( '' );
Expand All @@ -39,8 +42,11 @@ export const OnboardingPage = () => {
step: stepAction,
_wpnonce: nonce,
slug: 'elementor',
allowTracking,
};

setLoading( true );

try {
switch ( stepAction ) {
case 'install-elementor':
Expand All @@ -54,23 +60,31 @@ export const OnboardingPage = () => {
if ( activate.ok ) {
setSeverity( 'success' );
setMessage( __( 'Elementor plugin has been installed and activated' ) );
} else {
throw new Error( __( 'Failed to activate Elementor plugin', 'hello-plus' ) );
}
}

setStep( 1 );
setMessage( '' );
break;
case 'activate-elementor':
setMessage( __( 'Activating Elementor plugin…', 'hello-plus' ) );
await wp.ajax.post( 'hello_plus_setup_wizard', data );
setMessage( __( 'Elementor plugin has been activated.' ) );
data.slug = 'elementor';
setStep( 1 );
setMessage( '' );
break;
case 'install-kit':
break;
}
} catch ( error ) {
setMessage( error.errorMessage );
setSeverity( 'error' );
} finally {
setLoading( false );
}
}, [ nonce, stepAction ] );
}, [ allowTracking, nonce, setStep, stepAction ] );

const onClose = () => {
window.location.href = modalCloseRedirectUrl;
Expand All @@ -80,10 +94,13 @@ export const OnboardingPage = () => {
<ThemeProvider colorScheme="auto">
<Modal open sx={ { zIndex: 100000 } } >
<Box style={ { ...style, display: 'flex', flexDirection: 'column' } }>
<TopBarContent onClose={ onClose } sx={ { borderBottom: '1px solid var(--divider-divider, rgba(0, 0, 0, 0.12))', mb: 4 } } iconSize="small" />
{ 0 === step && ! loading && ( <GetStarted severity={ severity } message={ message } buttonText={ buttonText } onClick={ onClick } /> ) }
{ 1 === step && ! loading && ( <InstallKit severity={ severity } message={ message } onClick={ onClick } /> ) }
{ 2 === step && ! loading && ( <ReadyToGo severity={ severity } message={ message } onClick={ onClick } /> ) }
{ ! previewKit && ( <TopBarContent onClose={ onClose } sx={ { borderBottom: '1px solid var(--divider-divider, rgba(0, 0, 0, 0.12))', mb: 4 } } iconSize="small" /> ) }
{ 0 === step && ! loading && ! previewKit && (
<GetStarted allowTracking={ allowTracking } setAllowTracking={ setAllowTracking } severity={ severity } message={ message } buttonText={ buttonText } onClick={ onClick } />
) }
{ 1 === step && ! loading && ! previewKit && ( <InstallKit setPreviewKit={ setPreviewKit } severity={ severity } message={ message } onClick={ onClick } kits={ kits } /> ) }
{ 2 === step && ! loading && ! previewKit && ( <ReadyToGo modalCloseRedirectUrl={ modalCloseRedirectUrl } /> ) }
{ previewKit && <Preview slug={ previewKit } setStep={ setStep } setPreviewKit={ setPreviewKit } title="Title" /> }
{ loading && <Spinner /> }
</Box>
</Modal>
Expand Down
7 changes: 7 additions & 0 deletions modules/admin/classes/ajax/setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public function ajax_setup_wizard() {
check_ajax_referer( 'updates', 'nonce' );

$step = filter_input( INPUT_POST, 'step', FILTER_UNSAFE_RAW );
$allow_tracking = filter_input( INPUT_POST, 'allowTracking', FILTER_VALIDATE_BOOLEAN );

if ( $allow_tracking ) {
update_option( 'elementor_allow_tracking', true );
} else {
delete_option( 'elementor_allow_tracking' );
}

switch ( $step ) {
case 'install-elementor':
Expand Down
2 changes: 1 addition & 1 deletion modules/admin/classes/rest/admin-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function get_site_parts( array $config ) {
}

public function get_open_homepage_with_tab( $action ) {
return get_edit_post_link( get_option( 'page_on_front' ), 'admin' ) . '&action=elementor&active-document=34&tab=' . $action;
return get_edit_post_link( get_option( 'page_on_front' ), 'admin' ) . '&action=elementor&active-document=34&active-tab=' . $action;
}

public function get_quicklinks( $config ) {
Expand Down

0 comments on commit 6deeb74

Please sign in to comment.