2019-05-07 19:25:51 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-05-30 07:15:39 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2021-03-16 16:58:31 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2021-03-12 03:36:23 +00:00
|
|
|
import { Component, createElement } 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-09-03 21:45:40 +00:00
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
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-08-13 13:23:38 +00:00
|
|
|
NOTES_STORE_NAME,
|
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,
|
2020-09-03 21:45:40 +00:00
|
|
|
QUERY_DEFAULTS,
|
2020-04-27 14:56:15 +00:00
|
|
|
} from '@woocommerce/data';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2022-02-11 14:03:37 +00:00
|
|
|
import { getAdminLink, getSetting } from '@woocommerce/settings';
|
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
|
|
|
*/
|
2021-01-06 22:08:57 +00:00
|
|
|
import { BusinessDetailsStep } from './steps/business-details';
|
2019-06-12 03:56:10 +00:00
|
|
|
import Industry from './steps/industry';
|
|
|
|
import ProductTypes from './steps/product-types';
|
|
|
|
import ProfileWizardHeader from './header';
|
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';
|
2022-01-06 12:53:30 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2019-05-07 19:25:51 +00:00
|
|
|
import './style.scss';
|
2019-05-17 03:04:52 +00:00
|
|
|
|
2021-03-16 16:58:31 +00:00
|
|
|
const STEPS_FILTER = 'woocommerce_admin_profile_wizard_steps';
|
|
|
|
|
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
|
|
|
__(
|
2021-02-10 23:57:51 +00:00
|
|
|
'There was a problem finishing the setup wizard',
|
2020-02-14 02:23:21 +00:00
|
|
|
'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,
|
2022-02-11 14:03:37 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
2020-04-21 09:19:32 +00:00
|
|
|
} );
|
2019-10-29 18:24:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 19:25:51 +00:00
|
|
|
componentDidMount() {
|
2020-05-06 12:56:23 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-admin-is-loading' );
|
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' );
|
2021-02-19 13:20:32 +00:00
|
|
|
document.body.classList.add( 'is-wp-toolbar-disabled' );
|
2020-03-03 09:44:26 +00:00
|
|
|
|
2020-04-21 09:19:32 +00:00
|
|
|
recordEvent( 'storeprofiler_step_view', {
|
|
|
|
step: this.getCurrentStep().key,
|
2022-02-11 14:03:37 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
2020-04-21 09:19:32 +00:00
|
|
|
} );
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
document.body.classList.remove( 'woocommerce-profile-wizard__body' );
|
2019-07-22 04:53:13 +00:00
|
|
|
document.body.classList.remove( 'woocommerce-admin-full-screen' );
|
2021-02-19 13:20:32 +00:00
|
|
|
document.body.classList.remove( 'is-wp-toolbar-disabled' );
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-06 00:26:08 +00:00
|
|
|
getSteps() {
|
2021-06-03 08:33:54 +00:00
|
|
|
const { profileItems } = this.props;
|
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( {
|
2022-02-08 18:29:17 +00:00
|
|
|
key: 'business-details',
|
2021-01-06 22:08:57 +00:00
|
|
|
container: BusinessDetailsStep,
|
2019-11-06 00:26:08 +00:00
|
|
|
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
|
|
|
} );
|
2022-02-11 14:38:38 +00:00
|
|
|
/**
|
|
|
|
* Filter for Onboarding steps configuration.
|
|
|
|
*
|
|
|
|
* @filter woocommerce_admin_profile_wizard_steps
|
|
|
|
* @param {Array.<Object>} steps Array of steps for Onboarding Wizard.
|
|
|
|
*/
|
2021-03-16 16:58:31 +00:00
|
|
|
return applyFilters( STEPS_FILTER, steps );
|
2019-11-06 00:26:08 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-02-08 18:29:17 +00:00
|
|
|
/**
|
|
|
|
* @param {Object} tracksArgs optional track arguments for the storeprofiler_step_complete track.
|
|
|
|
*/
|
|
|
|
async goToNextStep( tracksArgs = {} ) {
|
2021-11-15 20:57:13 +00:00
|
|
|
const { activePlugins } = 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,
|
2022-02-11 14:03:37 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
2022-02-08 18:29:17 +00:00
|
|
|
...tracksArgs,
|
2020-02-20 11:59:02 +00:00
|
|
|
} );
|
|
|
|
|
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-08-20 04:02:01 +00:00
|
|
|
|
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,
|
|
|
|
isJetpackConnected,
|
|
|
|
notes,
|
|
|
|
updateNote,
|
|
|
|
updateProfileItems,
|
2020-08-20 04:02:01 +00:00
|
|
|
connectToJetpack,
|
2020-07-15 14:52:21 +00:00
|
|
|
} = this.props;
|
2020-02-20 11:59:02 +00:00
|
|
|
recordEvent( 'storeprofiler_complete' );
|
2020-08-10 12:18:09 +00:00
|
|
|
|
2020-07-15 14:52:21 +00:00
|
|
|
const shouldConnectJetpack =
|
2021-03-12 03:36:23 +00:00
|
|
|
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
|
|
|
|
2020-09-03 02:56:52 +00:00
|
|
|
updateProfileItems( { completed: true } ).then( () => {
|
2020-11-06 19:52:57 +00:00
|
|
|
const homescreenUrl = new URL(
|
|
|
|
getNewPath( {}, '/', {} ),
|
|
|
|
window.location.href
|
|
|
|
).href;
|
|
|
|
|
2020-09-03 02:56:52 +00:00
|
|
|
if ( shouldConnectJetpack ) {
|
|
|
|
document.body.classList.add( 'woocommerce-admin-is-loading' );
|
|
|
|
|
2020-11-06 19:52:57 +00:00
|
|
|
connectToJetpack( () => {
|
|
|
|
return homescreenUrl;
|
|
|
|
} );
|
2020-09-03 02:56:52 +00:00
|
|
|
} else {
|
2020-11-06 19:52:57 +00:00
|
|
|
window.location.href = homescreenUrl;
|
2020-09-03 02:56:52 +00:00
|
|
|
}
|
|
|
|
} );
|
2019-12-20 12:58:38 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 15:17:10 +00:00
|
|
|
skipProfiler() {
|
|
|
|
const { createNotice, updateProfileItems } = this.props;
|
2020-11-06 19:52:57 +00:00
|
|
|
|
2020-07-16 15:17:10 +00:00
|
|
|
updateProfileItems( { skipped: true } )
|
|
|
|
.then( () => {
|
|
|
|
recordEvent( 'storeprofiler_store_details_skip' );
|
|
|
|
getHistory().push( getNewPath( {}, '/', {} ) );
|
|
|
|
} )
|
|
|
|
.catch( () => {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__(
|
2021-02-10 23:57:51 +00:00
|
|
|
'There was a problem skipping the setup wizard',
|
2020-07-16 15:17:10 +00:00
|
|
|
'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();
|
2020-07-21 21:03:34 +00:00
|
|
|
const stepKey = step.key;
|
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' ] )
|
|
|
|
);
|
2020-07-21 21:03:34 +00:00
|
|
|
const classNames = `woocommerce-profile-wizard__container ${ stepKey }`;
|
2019-05-27 16:37:02 +00:00
|
|
|
|
|
|
|
return (
|
2021-03-12 03:36:23 +00:00
|
|
|
<>
|
2020-07-21 21:03:34 +00:00
|
|
|
<ProfileWizardHeader currentStep={ stepKey } steps={ steps } />
|
|
|
|
<div className={ classNames }>{ container }</div>
|
2021-03-12 03:36:23 +00:00
|
|
|
</>
|
2019-05-27 16:37:02 +00:00
|
|
|
);
|
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-08-13 13:23:38 +00:00
|
|
|
const { getNotes } = select( NOTES_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 );
|
2021-01-06 22:08:57 +00:00
|
|
|
|
|
|
|
const profileItems = getProfileItems();
|
|
|
|
|
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();
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-11-06 00:26:08 +00:00
|
|
|
return {
|
2020-07-15 14:52:21 +00:00
|
|
|
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,
|
2021-03-12 03:36:23 +00:00
|
|
|
profileItems,
|
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-08-20 04:02:01 +00:00
|
|
|
const {
|
|
|
|
connectToJetpackWithFailureRedirect,
|
|
|
|
createErrorNotice,
|
|
|
|
} = dispatch( PLUGINS_STORE_NAME );
|
2020-08-13 13:23:38 +00:00
|
|
|
const { updateNote } = dispatch( NOTES_STORE_NAME );
|
2020-07-14 10:46:25 +00:00
|
|
|
const { updateOptions } = dispatch( OPTIONS_STORE_NAME );
|
2020-11-24 19:36:04 +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
|
|
|
|
2020-08-20 04:02:01 +00:00
|
|
|
const connectToJetpack = ( failureRedirect ) => {
|
|
|
|
connectToJetpackWithFailureRedirect(
|
|
|
|
failureRedirect,
|
2020-09-18 02:22:52 +00:00
|
|
|
createErrorNotice,
|
|
|
|
getAdminLink
|
2020-08-20 04:02:01 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-05-28 03:09:48 +00:00
|
|
|
return {
|
2020-08-20 04:02:01 +00:00
|
|
|
connectToJetpack,
|
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
|
|
|
} ),
|
2022-01-06 12:53:30 +00:00
|
|
|
getAdminSetting( 'plugins' )
|
2020-04-29 18:01:27 +00:00
|
|
|
? withPluginsHydration( {
|
2022-01-06 12:53:30 +00:00
|
|
|
...getAdminSetting( 'plugins' ),
|
|
|
|
jetpackStatus: getAdminSetting( 'dataEndpoints', {} )
|
|
|
|
.jetpackStatus,
|
2020-04-29 18:01:27 +00:00
|
|
|
} )
|
|
|
|
: identity
|
2019-05-28 03:09:48 +00:00
|
|
|
)( ProfileWizard );
|