2019-05-07 19:25:51 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
2020-04-29 18:01:27 +00:00
|
|
|
import { identity, pick } from 'lodash';
|
2020-07-15 14:52:21 +00:00
|
|
|
import { withDispatch, __experimentalResolveSelect } from '@wordpress/data';
|
2019-05-28 03:09:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2020-07-15 14:52:21 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/wc-admin-settings';
|
2020-07-16 15:17:10 +00:00
|
|
|
import {
|
|
|
|
getHistory,
|
|
|
|
getNewPath,
|
|
|
|
updateQueryString,
|
|
|
|
} from '@woocommerce/navigation';
|
2020-04-27 14:56:15 +00:00
|
|
|
import {
|
2020-05-28 08:51:40 +00:00
|
|
|
ONBOARDING_STORE_NAME,
|
2020-07-14 10:46:25 +00:00
|
|
|
OPTIONS_STORE_NAME,
|
2020-04-27 14:56:15 +00:00
|
|
|
PLUGINS_STORE_NAME,
|
|
|
|
withPluginsHydration,
|
|
|
|
} from '@woocommerce/data';
|
2019-05-07 19:25:51 +00:00
|
|
|
|
|
|
|
/**
|
2019-11-14 14:35:55 +00:00
|
|
|
* Internal dependencies
|
2019-05-07 19:25:51 +00:00
|
|
|
*/
|
2020-03-03 09:44:26 +00:00
|
|
|
import Benefits from './steps/benefits';
|
2019-06-12 03:56:10 +00:00
|
|
|
import BusinessDetails from './steps/business-details';
|
2020-07-15 14:52:21 +00:00
|
|
|
import { createNoticesFromResponse } from 'lib/notices';
|
2019-06-12 03:56:10 +00:00
|
|
|
import Industry from './steps/industry';
|
|
|
|
import ProductTypes from './steps/product-types';
|
|
|
|
import ProfileWizardHeader from './header';
|
2020-01-10 01:36:30 +00:00
|
|
|
import { QUERY_DEFAULTS } from 'wc-api/constants';
|
2020-02-20 11:59:02 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
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
|
|
|
|
2019-05-28 03:09:48 +00:00
|
|
|
class ProfileWizard extends Component {
|
2020-04-16 23:58:36 +00:00
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
2020-07-15 14:52:21 +00:00
|
|
|
this.cachedActivePlugins = props.activePlugins;
|
2019-05-28 03:09:48 +00:00
|
|
|
this.goToNextStep = this.goToNextStep.bind( this );
|
|
|
|
}
|
|
|
|
|
2019-10-29 18:24:24 +00:00
|
|
|
componentDidUpdate( prevProps ) {
|
|
|
|
const { step: prevStep } = prevProps.query;
|
|
|
|
const { step } = this.props.query;
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
isError,
|
|
|
|
isGetProfileItemsRequesting,
|
|
|
|
createNotice,
|
|
|
|
} = this.props;
|
2019-12-20 12:58:38 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const isRequestError =
|
|
|
|
! isGetProfileItemsRequesting && prevProps.isRequesting && isError;
|
2019-12-20 12:58:38 +00:00
|
|
|
if ( isRequestError ) {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
2020-02-14 02:23:21 +00:00
|
|
|
__(
|
|
|
|
'There was a problem finishing the profile wizard.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
2019-12-20 12:58:38 +00:00
|
|
|
);
|
|
|
|
}
|
2019-10-29 18:24:24 +00:00
|
|
|
|
|
|
|
if ( prevStep !== step ) {
|
|
|
|
window.document.documentElement.scrollTop = 0;
|
2020-04-21 09:19:32 +00:00
|
|
|
|
|
|
|
recordEvent( 'storeprofiler_step_view', {
|
|
|
|
step: this.getCurrentStep().key,
|
|
|
|
} );
|
2019-10-29 18:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:25:51 +00:00
|
|
|
componentDidMount() {
|
2020-07-15 14:52:21 +00:00
|
|
|
const { activePlugins, profileItems, updateProfileItems } = this.props;
|
2020-03-03 09:44:26 +00:00
|
|
|
|
2020-05-06 12:56:23 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-admin-is-loading' );
|
2019-05-17 03:04:52 +00:00
|
|
|
document.documentElement.classList.remove( 'wp-toolbar' );
|
2019-08-21 05:58:47 +00:00
|
|
|
document.body.classList.add( 'woocommerce-onboarding' );
|
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' );
|
2020-03-03 09:44:26 +00:00
|
|
|
|
2020-04-21 09:19:32 +00:00
|
|
|
recordEvent( 'storeprofiler_step_view', {
|
|
|
|
step: this.getCurrentStep().key,
|
|
|
|
} );
|
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
// Track plugins if already installed.
|
|
|
|
if (
|
2020-07-15 14:52:21 +00:00
|
|
|
activePlugins.includes( 'woocommerce-services' ) &&
|
|
|
|
activePlugins.includes( 'jetpack' ) &&
|
2020-03-03 09:44:26 +00:00
|
|
|
profileItems.plugins !== 'already-installed'
|
|
|
|
) {
|
|
|
|
recordEvent(
|
|
|
|
'wcadmin_storeprofiler_already_installed_plugins',
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
updateProfileItems( { plugins: 'already-installed' } );
|
|
|
|
}
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2019-05-17 03:04:52 +00:00
|
|
|
document.documentElement.classList.add( 'wp-toolbar' );
|
2019-08-21 05:58:47 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-onboarding' );
|
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-11-06 00:26:08 +00:00
|
|
|
getSteps() {
|
2020-07-15 14:52:21 +00:00
|
|
|
const { profileItems, query } = this.props;
|
|
|
|
const { step } = query;
|
2019-11-06 00:26:08 +00:00
|
|
|
const steps = [];
|
|
|
|
|
|
|
|
steps.push( {
|
|
|
|
key: 'store-details',
|
|
|
|
container: StoreDetails,
|
|
|
|
label: __( 'Store Details', 'woocommerce-admin' ),
|
|
|
|
isComplete:
|
2020-02-14 02:23:21 +00:00
|
|
|
profileItems.hasOwnProperty( 'setup_client' ) &&
|
|
|
|
profileItems.setup_client !== null,
|
2019-11-06 00:26:08 +00:00
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'industry',
|
|
|
|
container: Industry,
|
|
|
|
label: __( 'Industry', 'woocommerce-admin' ),
|
2020-02-14 02:23:21 +00:00
|
|
|
isComplete:
|
|
|
|
profileItems.hasOwnProperty( 'industry' ) &&
|
|
|
|
profileItems.industry !== null,
|
2019-11-06 00:26:08 +00:00
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'product-types',
|
|
|
|
container: ProductTypes,
|
|
|
|
label: __( 'Product Types', 'woocommerce-admin' ),
|
|
|
|
isComplete:
|
2020-02-14 02:23:21 +00:00
|
|
|
profileItems.hasOwnProperty( 'product_types' ) &&
|
|
|
|
profileItems.product_types !== null,
|
2019-11-06 00:26:08 +00:00
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'business-details',
|
|
|
|
container: BusinessDetails,
|
|
|
|
label: __( 'Business Details', 'woocommerce-admin' ),
|
|
|
|
isComplete:
|
2020-02-14 02:23:21 +00:00
|
|
|
profileItems.hasOwnProperty( 'product_count' ) &&
|
|
|
|
profileItems.product_count !== null,
|
2019-11-06 00:26:08 +00:00
|
|
|
} );
|
|
|
|
steps.push( {
|
|
|
|
key: 'theme',
|
|
|
|
container: Theme,
|
|
|
|
label: __( 'Theme', 'woocommerce-admin' ),
|
2020-02-14 02:23:21 +00:00
|
|
|
isComplete:
|
|
|
|
profileItems.hasOwnProperty( 'theme' ) &&
|
|
|
|
profileItems.theme !== null,
|
2019-11-06 00:26:08 +00:00
|
|
|
} );
|
2020-03-03 09:44:26 +00:00
|
|
|
|
|
|
|
if (
|
2020-07-15 14:52:21 +00:00
|
|
|
! this.cachedActivePlugins.includes( 'woocommerce-services' ) ||
|
|
|
|
! this.cachedActivePlugins.includes( 'jetpack' ) ||
|
|
|
|
step === 'benefits'
|
2020-03-03 09:44:26 +00:00
|
|
|
) {
|
|
|
|
steps.push( {
|
|
|
|
key: 'benefits',
|
|
|
|
container: Benefits,
|
|
|
|
} );
|
|
|
|
}
|
2019-11-06 00:26:08 +00:00
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2019-05-28 03:09:48 +00:00
|
|
|
getCurrentStep() {
|
2019-05-17 03:04:52 +00:00
|
|
|
const { step } = this.props.query;
|
2020-02-14 02:23:21 +00:00
|
|
|
const currentStep = this.getSteps().find( ( s ) => s.key === step );
|
2019-05-17 03:04:52 +00:00
|
|
|
|
|
|
|
if ( ! currentStep ) {
|
2019-11-06 00:26:08 +00:00
|
|
|
return this.getSteps()[ 0 ];
|
2019-05-17 03:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return currentStep;
|
|
|
|
}
|
|
|
|
|
2019-05-31 04:51:33 +00:00
|
|
|
async goToNextStep() {
|
2020-07-15 14:52:21 +00:00
|
|
|
const { activePlugins, dismissedTasks, updateOptions } = this.props;
|
2019-05-28 03:09:48 +00:00
|
|
|
const currentStep = this.getCurrentStep();
|
2020-02-14 02:23:21 +00:00
|
|
|
const currentStepIndex = this.getSteps().findIndex(
|
|
|
|
( s ) => s.key === currentStep.key
|
|
|
|
);
|
2020-02-20 11:59:02 +00:00
|
|
|
|
|
|
|
recordEvent( 'storeprofiler_step_complete', {
|
|
|
|
step: currentStep.key,
|
|
|
|
} );
|
|
|
|
|
2020-07-14 10:46:25 +00:00
|
|
|
if ( dismissedTasks.length ) {
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_task_list_dismissed_tasks: [],
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2020-07-15 14:52:21 +00:00
|
|
|
// Update the activePlugins cache in case plugins were installed
|
|
|
|
// in the current step that affect the visibility of the next step.
|
|
|
|
this.cachedActivePlugins = activePlugins;
|
|
|
|
|
2019-11-06 00:26:08 +00:00
|
|
|
const nextStep = this.getSteps()[ currentStepIndex + 1 ];
|
2020-02-14 02:23:21 +00:00
|
|
|
if ( typeof nextStep === 'undefined' ) {
|
2020-03-03 09:44:26 +00:00
|
|
|
this.completeProfiler();
|
2019-05-31 04:51:33 +00:00
|
|
|
return;
|
2019-05-28 03:09:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return updateQueryString( { step: nextStep.key } );
|
|
|
|
}
|
|
|
|
|
2020-01-10 01:36:30 +00:00
|
|
|
completeProfiler() {
|
2020-07-15 14:52:21 +00:00
|
|
|
const {
|
|
|
|
activePlugins,
|
|
|
|
getJetpackConnectUrl,
|
|
|
|
getPluginsError,
|
|
|
|
isJetpackConnected,
|
|
|
|
notes,
|
|
|
|
updateNote,
|
|
|
|
updateProfileItems,
|
|
|
|
} = this.props;
|
2020-02-20 11:59:02 +00:00
|
|
|
recordEvent( 'storeprofiler_complete' );
|
2020-07-15 14:52:21 +00:00
|
|
|
const shouldConnectJetpack =
|
|
|
|
activePlugins.includes( 'jetpack' ) && ! isJetpackConnected;
|
2020-01-10 01:36:30 +00:00
|
|
|
|
|
|
|
const profilerNote = notes.find(
|
2020-02-14 02:23:21 +00:00
|
|
|
( note ) => note.name === 'wc-admin-onboarding-profiler-reminder'
|
2020-01-10 01:36:30 +00:00
|
|
|
);
|
|
|
|
if ( profilerNote ) {
|
|
|
|
updateNote( profilerNote.id, { status: 'actioned' } );
|
2019-12-20 12:58:38 +00:00
|
|
|
}
|
2020-07-15 14:52:21 +00:00
|
|
|
|
|
|
|
const promises = [
|
|
|
|
updateProfileItems( { completed: true } ).then( () => {
|
|
|
|
if ( shouldConnectJetpack ) {
|
|
|
|
document.body.classList.add(
|
|
|
|
'woocommerce-admin-is-loading'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} ),
|
|
|
|
];
|
|
|
|
|
|
|
|
let redirectUrl = null;
|
|
|
|
if ( shouldConnectJetpack ) {
|
|
|
|
promises.push(
|
|
|
|
getJetpackConnectUrl( {
|
|
|
|
redirect_url: getAdminLink( 'admin.php?page=wc-admin' ),
|
|
|
|
} ).then( ( jetpackConnectUrl ) => {
|
|
|
|
const error = getPluginsError( 'getJetpackConnectUrl' );
|
|
|
|
if ( error ) {
|
|
|
|
createNoticesFromResponse( error );
|
|
|
|
return;
|
|
|
|
}
|
2020-07-16 15:17:10 +00:00
|
|
|
redirectUrl = jetpackConnectUrl;
|
2020-07-15 14:52:21 +00:00
|
|
|
} )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all( promises ).then( () => {
|
|
|
|
if ( redirectUrl ) {
|
|
|
|
window.location = redirectUrl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getHistory().push( getNewPath( {}, '/', {} ) );
|
|
|
|
} );
|
2019-12-20 12:58:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:17:10 +00:00
|
|
|
skipProfiler() {
|
|
|
|
const { createNotice, updateProfileItems } = this.props;
|
|
|
|
updateProfileItems( { skipped: true } )
|
|
|
|
.then( () => {
|
|
|
|
recordEvent( 'storeprofiler_store_details_skip' );
|
|
|
|
getHistory().push( getNewPath( {}, '/', {} ) );
|
|
|
|
} )
|
|
|
|
.catch( () => {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__(
|
|
|
|
'There was a problem skipping the setup wizard.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
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,
|
2020-07-21 00:12:19 +00:00
|
|
|
skipProfiler: () => {
|
|
|
|
this.skipProfiler();
|
|
|
|
},
|
2019-05-28 03:09:48 +00:00
|
|
|
} );
|
2020-02-14 02:23:21 +00:00
|
|
|
const steps = this.getSteps().map( ( _step ) =>
|
|
|
|
pick( _step, [ 'key', 'label', 'isComplete' ] )
|
|
|
|
);
|
2019-05-27 16:37:02 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<ProfileWizardHeader currentStep={ step.key } steps={ steps } />
|
2020-02-14 02:23:21 +00:00
|
|
|
<div className="woocommerce-profile-wizard__container">
|
|
|
|
{ container }
|
|
|
|
</div>
|
2019-05-27 16:37:02 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-28 03:09:48 +00:00
|
|
|
|
|
|
|
export default compose(
|
2020-02-14 02:23:21 +00:00
|
|
|
withSelect( ( select ) => {
|
2020-05-28 08:51:40 +00:00
|
|
|
const { getNotes } = select( 'wc-api' );
|
2020-07-14 10:46:25 +00:00
|
|
|
const { getOption } = select( OPTIONS_STORE_NAME );
|
2020-06-10 23:49:27 +00:00
|
|
|
const { getProfileItems, getOnboardingError } = select(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
);
|
2020-07-15 14:52:21 +00:00
|
|
|
const {
|
|
|
|
getActivePlugins,
|
|
|
|
getPluginsError,
|
|
|
|
isJetpackConnected,
|
|
|
|
} = select( PLUGINS_STORE_NAME );
|
2020-01-10 01:36:30 +00:00
|
|
|
|
|
|
|
const notesQuery = {
|
|
|
|
page: 1,
|
|
|
|
per_page: QUERY_DEFAULTS.pageSize,
|
|
|
|
type: 'update',
|
|
|
|
status: 'unactioned',
|
|
|
|
};
|
|
|
|
const notes = getNotes( notesQuery );
|
2020-04-16 23:58:36 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
2020-07-14 10:46:25 +00:00
|
|
|
const dismissedTasks =
|
|
|
|
getOption( 'woocommerce_task_list_dismissed_tasks' ) || [];
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-11-06 00:26:08 +00:00
|
|
|
return {
|
2020-07-14 10:46:25 +00:00
|
|
|
dismissedTasks,
|
2020-07-15 14:52:21 +00:00
|
|
|
getJetpackConnectUrl: __experimentalResolveSelect(
|
|
|
|
PLUGINS_STORE_NAME
|
|
|
|
).getJetpackConnectUrl,
|
|
|
|
getPluginsError,
|
2020-05-28 08:51:40 +00:00
|
|
|
isError: Boolean( getOnboardingError( 'updateProfileItems' ) ),
|
2020-07-15 14:52:21 +00:00
|
|
|
isJetpackConnected: isJetpackConnected(),
|
2020-01-10 01:36:30 +00:00
|
|
|
notes,
|
2019-11-06 00:26:08 +00:00
|
|
|
profileItems: getProfileItems(),
|
2020-04-16 23:58:36 +00:00
|
|
|
activePlugins,
|
2019-11-06 00:26:08 +00:00
|
|
|
};
|
2019-05-31 04:51:33 +00:00
|
|
|
} ),
|
2020-02-14 02:23:21 +00:00
|
|
|
withDispatch( ( dispatch ) => {
|
2020-05-28 08:51:40 +00:00
|
|
|
const { updateNote } = dispatch( 'wc-api' );
|
2020-07-14 10:46:25 +00:00
|
|
|
const { updateOptions } = dispatch( OPTIONS_STORE_NAME );
|
2020-05-28 08:51:40 +00:00
|
|
|
const { updateProfileItems } = dispatch( ONBOARDING_STORE_NAME );
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-05-28 03:09:48 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2020-01-10 01:36:30 +00:00
|
|
|
updateNote,
|
2020-07-14 10:46:25 +00:00
|
|
|
updateOptions,
|
2019-05-31 04:51:33 +00:00
|
|
|
updateProfileItems,
|
2019-05-28 03:09:48 +00:00
|
|
|
};
|
2020-04-29 18:01:27 +00:00
|
|
|
} ),
|
|
|
|
window.wcSettings.plugins
|
|
|
|
? withPluginsHydration( {
|
|
|
|
...window.wcSettings.plugins,
|
|
|
|
jetpackStatus: window.wcSettings.dataEndpoints.jetpackStatus,
|
|
|
|
} )
|
|
|
|
: identity
|
2019-05-28 03:09:48 +00:00
|
|
|
)( ProfileWizard );
|