2018-04-17 23:51:48 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-10-30 01:49:27 +00:00
|
|
|
import { addQueryArgs } from '@wordpress/url';
|
2019-10-11 12:55:35 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
2019-05-28 14:45:52 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2019-10-30 01:49:27 +00:00
|
|
|
import { get } from 'lodash';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
2019-12-10 20:08:16 +00:00
|
|
|
import { getNewPath, updateQueryString } from '@woocommerce/navigation';
|
2018-04-17 23:51:48 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-03 18:23:17 +00:00
|
|
|
* Internal dependencies
|
2018-04-17 23:51:48 +00:00
|
|
|
*/
|
2018-08-02 23:10:55 +00:00
|
|
|
import './style.scss';
|
2019-04-22 13:23:37 +00:00
|
|
|
import CustomizableDashboard from './customizable';
|
2019-05-07 19:25:51 +00:00
|
|
|
import ProfileWizard from './profile-wizard';
|
2019-05-28 14:45:52 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-11-07 18:31:02 +00:00
|
|
|
import { isOnboardingEnabled } from 'dashboard/utils';
|
2018-04-17 23:51:48 +00:00
|
|
|
|
2019-05-28 14:45:52 +00:00
|
|
|
class Dashboard extends Component {
|
2019-10-30 01:49:27 +00:00
|
|
|
componentDidUpdate( prevProps ) {
|
|
|
|
const profileItems = get( this.props, 'profileItems', {} );
|
|
|
|
const prevProfileItems = get( prevProps, 'profileItems', {} );
|
|
|
|
|
|
|
|
if ( profileItems.completed && ! prevProfileItems.completed ) {
|
|
|
|
updateQueryString( {}, '/', {} );
|
|
|
|
this.redirectToCart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getProductIds() {
|
|
|
|
const productIds = [];
|
|
|
|
const profileItems = get( this.props, 'profileItems', {} );
|
|
|
|
const onboarding = getSetting( 'onboarding', {} );
|
2019-12-10 20:08:16 +00:00
|
|
|
const productTypes = profileItems.product_types || [];
|
2019-10-30 01:49:27 +00:00
|
|
|
|
2019-12-10 20:08:16 +00:00
|
|
|
productTypes.forEach( productType => {
|
2019-10-30 01:49:27 +00:00
|
|
|
if (
|
2019-12-10 20:08:16 +00:00
|
|
|
onboarding.productTypes[ productType ] &&
|
|
|
|
onboarding.productTypes[ productType ].product
|
2019-10-30 01:49:27 +00:00
|
|
|
) {
|
2019-12-10 20:08:16 +00:00
|
|
|
productIds.push( onboarding.productTypes[ productType ].product );
|
2019-10-30 01:49:27 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
const theme = onboarding.themes.find( themeData => themeData.slug === profileItems.theme );
|
|
|
|
|
|
|
|
if ( theme && theme.id && ! theme.is_installed ) {
|
|
|
|
productIds.push( theme.id );
|
|
|
|
}
|
|
|
|
|
|
|
|
return productIds;
|
|
|
|
}
|
|
|
|
|
|
|
|
redirectToCart() {
|
2019-11-07 18:31:02 +00:00
|
|
|
if ( ! isOnboardingEnabled() ) {
|
2019-10-30 01:49:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const productIds = this.getProductIds();
|
2019-12-10 20:08:16 +00:00
|
|
|
const backPath = getNewPath( {}, '/', {} );
|
|
|
|
const { connectNonce } = getSetting( 'onboarding', {} );
|
|
|
|
|
2019-10-30 01:49:27 +00:00
|
|
|
if ( ! productIds.length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.classList.add( 'woocommerce-admin-is-loading' );
|
|
|
|
|
|
|
|
const url = addQueryArgs( 'https://woocommerce.com/cart', {
|
2019-12-10 20:08:16 +00:00
|
|
|
'wccom-site': getSetting( 'siteUrl' ),
|
|
|
|
'wccom-woo-version': getSetting( 'wcVersion' ),
|
2019-10-30 01:49:27 +00:00
|
|
|
'wccom-replace-with': productIds.join( ',' ),
|
2019-12-10 20:08:16 +00:00
|
|
|
'wccom-connect-nonce': connectNonce,
|
|
|
|
'wccom-back': backPath,
|
2019-10-30 01:49:27 +00:00
|
|
|
} );
|
|
|
|
window.location = url;
|
|
|
|
}
|
|
|
|
|
2019-07-05 08:15:49 +00:00
|
|
|
render() {
|
2019-05-28 14:45:52 +00:00
|
|
|
const { path, profileItems, query } = this.props;
|
2019-05-17 03:04:52 +00:00
|
|
|
|
2019-11-07 18:31:02 +00:00
|
|
|
if ( isOnboardingEnabled() && ! profileItems.completed ) {
|
2019-05-17 03:04:52 +00:00
|
|
|
return <ProfileWizard query={ query } />;
|
2019-05-07 19:25:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-08 16:10:05 +00:00
|
|
|
if ( window.wcAdminFeatures[ 'analytics-dashboard/customizable' ] ) {
|
2019-04-22 13:23:37 +00:00
|
|
|
return <CustomizableDashboard query={ query } path={ path } />;
|
|
|
|
}
|
|
|
|
|
2019-10-11 12:55:35 +00:00
|
|
|
return null;
|
2019-04-22 13:23:37 +00:00
|
|
|
}
|
2018-04-17 23:51:48 +00:00
|
|
|
}
|
2019-05-28 14:45:52 +00:00
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
2019-11-07 18:31:02 +00:00
|
|
|
if ( ! isOnboardingEnabled() ) {
|
2019-05-31 14:55:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:45:52 +00:00
|
|
|
const { getProfileItems } = select( 'wc-api' );
|
|
|
|
const profileItems = getProfileItems();
|
|
|
|
|
|
|
|
return { profileItems };
|
|
|
|
} )
|
|
|
|
)( Dashboard );
|