2019-05-07 19:25:51 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-05-30 07:15:39 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-05-27 16:37:02 +00:00
|
|
|
import { Component, createElement, Fragment } from '@wordpress/element';
|
2019-05-28 03:09:48 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2019-05-27 16:37:02 +00:00
|
|
|
import { pick } from 'lodash';
|
2019-05-28 03:09:48 +00:00
|
|
|
import { withDispatch } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { updateQueryString } from '@woocommerce/navigation';
|
2019-05-07 19:25:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal depdencies
|
|
|
|
*/
|
2019-06-12 03:56:10 +00:00
|
|
|
import BusinessDetails from './steps/business-details';
|
|
|
|
import Industry from './steps/industry';
|
2019-05-17 03:04:52 +00:00
|
|
|
import Plugins from './steps/plugins';
|
2019-06-12 03:56:10 +00:00
|
|
|
import ProductTypes from './steps/product-types';
|
|
|
|
import ProfileWizardHeader from './header';
|
2019-05-27 16:37:02 +00:00
|
|
|
import Start from './steps/start';
|
2019-05-30 07:15:39 +00:00
|
|
|
import StoreDetails from './steps/store-details';
|
2019-06-26 02:22:44 +00:00
|
|
|
import Theme from './steps/theme';
|
2019-05-31 04:51:33 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-05-07 19:25:51 +00:00
|
|
|
import './style.scss';
|
2019-05-17 03:04:52 +00:00
|
|
|
|
|
|
|
const getSteps = () => {
|
|
|
|
const steps = [];
|
|
|
|
steps.push( {
|
|
|
|
key: 'start',
|
|
|
|
container: Start,
|
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'plugins',
|
|
|
|
container: Plugins,
|
|
|
|
} );
|
2019-05-27 16:37:02 +00:00
|
|
|
steps.push( {
|
|
|
|
key: 'store-details',
|
2019-05-30 07:15:39 +00:00
|
|
|
container: StoreDetails,
|
2019-05-27 16:37:02 +00:00
|
|
|
label: __( 'Store Details', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'industry',
|
2019-05-28 14:05:55 +00:00
|
|
|
container: Industry,
|
2019-05-27 16:37:02 +00:00
|
|
|
label: __( 'Industry', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'product-types',
|
2019-05-30 08:36:02 +00:00
|
|
|
container: ProductTypes,
|
2019-05-27 16:37:02 +00:00
|
|
|
label: __( 'Product Types', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'business-details',
|
2019-06-12 03:56:10 +00:00
|
|
|
container: BusinessDetails,
|
2019-05-27 16:37:02 +00:00
|
|
|
label: __( 'Business Details', 'woocommerce-admin' ),
|
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'theme',
|
2019-06-26 02:22:44 +00:00
|
|
|
container: Theme,
|
2019-05-27 16:37:02 +00:00
|
|
|
label: __( 'Theme', 'woocommerce-admin' ),
|
|
|
|
} );
|
2019-05-17 03:04:52 +00:00
|
|
|
return steps;
|
|
|
|
};
|
2019-05-07 19:25:51 +00:00
|
|
|
|
2019-05-28 03:09:48 +00:00
|
|
|
class ProfileWizard extends Component {
|
|
|
|
constructor() {
|
|
|
|
super( ...arguments );
|
|
|
|
this.goToNextStep = this.goToNextStep.bind( this );
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:25:51 +00:00
|
|
|
componentDidMount() {
|
2019-05-17 03:04:52 +00:00
|
|
|
document.documentElement.classList.remove( 'wp-toolbar' );
|
2019-05-07 19:25:51 +00:00
|
|
|
document.body.classList.add( 'woocommerce-profile-wizard__body' );
|
2019-07-22 04:53:13 +00:00
|
|
|
document.body.classList.add( 'woocommerce-admin-full-screen' );
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2019-05-17 03:04:52 +00:00
|
|
|
document.documentElement.classList.add( 'wp-toolbar' );
|
2019-05-07 19:25:51 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-profile-wizard__body' );
|
2019-07-22 04:53:13 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-admin-full-screen' );
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 03:09:48 +00:00
|
|
|
getCurrentStep() {
|
2019-05-17 03:04:52 +00:00
|
|
|
const { step } = this.props.query;
|
|
|
|
const currentStep = getSteps().find( s => s.key === step );
|
|
|
|
|
|
|
|
if ( ! currentStep ) {
|
|
|
|
return getSteps()[ 0 ];
|
|
|
|
}
|
|
|
|
|
|
|
|
return currentStep;
|
|
|
|
}
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
async goToNextStep() {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice, isError, updateProfileItems } = this.props;
|
2019-05-28 03:09:48 +00:00
|
|
|
const currentStep = this.getCurrentStep();
|
|
|
|
const currentStepIndex = getSteps().findIndex( s => s.key === currentStep.key );
|
|
|
|
const nextStep = getSteps()[ currentStepIndex + 1 ];
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
if ( 'undefined' === typeof nextStep ) {
|
|
|
|
await updateProfileItems( { completed: true } );
|
|
|
|
|
|
|
|
if ( isError ) {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__( 'There was a problem completing the profiler.', 'woocommerce-admin' )
|
|
|
|
);
|
2019-05-31 04:51:33 +00:00
|
|
|
}
|
|
|
|
return;
|
2019-05-28 03:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return updateQueryString( { step: nextStep.key } );
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:25:51 +00:00
|
|
|
render() {
|
2019-05-17 03:04:52 +00:00
|
|
|
const { query } = this.props;
|
2019-05-28 03:09:48 +00:00
|
|
|
const step = this.getCurrentStep();
|
2019-05-17 03:04:52 +00:00
|
|
|
|
2019-05-28 03:09:48 +00:00
|
|
|
const container = createElement( step.container, {
|
|
|
|
query,
|
|
|
|
step,
|
|
|
|
goToNextStep: this.goToNextStep,
|
|
|
|
} );
|
2019-05-27 16:37:02 +00:00
|
|
|
const steps = getSteps().map( _step => pick( _step, [ 'key', 'label' ] ) );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ProfileWizardHeader currentStep={ step.key } steps={ steps } />
|
|
|
|
<div className="woocommerce-profile-wizard__container">{ container }</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 03:09:48 +00:00
|
|
|
|
|
|
|
export default compose(
|
2019-05-31 04:51:33 +00:00
|
|
|
withSelect( select => {
|
|
|
|
const { getProfileItemsError } = select( 'wc-api' );
|
|
|
|
|
|
|
|
const isError = Boolean( getProfileItemsError() );
|
|
|
|
|
|
|
|
return { isError };
|
|
|
|
} ),
|
2019-05-28 03:09:48 +00:00
|
|
|
withDispatch( dispatch => {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { updateProfileItems } = dispatch( 'wc-api' );
|
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-05-28 03:09:48 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2019-05-31 04:51:33 +00:00
|
|
|
updateProfileItems,
|
2019-05-28 03:09:48 +00:00
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( ProfileWizard );
|