Onboarding: Redirect to wccom cart if purchases required (https://github.com/woocommerce/woocommerce-admin/pull/3121)

This commit is contained in:
Joshua T Flowers 2019-10-30 09:49:27 +08:00 committed by GitHub
parent 2c81932702
commit 993934606f
2 changed files with 61 additions and 0 deletions

View File

@ -2,8 +2,16 @@
/**
* External dependencies
*/
import { addQueryArgs } from '@wordpress/url';
import { Component } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { get } from 'lodash';
/**
* WooCommerce dependencies
*/
import { getSetting } from '@woocommerce/wc-admin-settings';
import { updateQueryString } from '@woocommerce/navigation';
/**
* Internal dependencies
@ -14,6 +22,58 @@ import ProfileWizard from './profile-wizard';
import withSelect from 'wc-api/with-select';
class Dashboard extends Component {
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', {} );
profileItems.product_types.forEach( product_type => {
if (
onboarding.productTypes[ product_type ] &&
onboarding.productTypes[ product_type ].product
) {
productIds.push( onboarding.productTypes[ product_type ].product );
}
} );
const theme = onboarding.themes.find( themeData => themeData.slug === profileItems.theme );
if ( theme && theme.id && ! theme.is_installed ) {
productIds.push( theme.id );
}
return productIds;
}
redirectToCart() {
if ( ! window.wcAdminFeatures.onboarding ) {
return;
}
const productIds = this.getProductIds();
if ( ! productIds.length ) {
return;
}
document.body.classList.add( 'woocommerce-admin-is-loading' );
const url = addQueryArgs( 'https://woocommerce.com/cart', {
'wccom-back': window.location.href,
'wccom-replace-with': productIds.join( ',' ),
} );
window.location = url;
}
render() {
const { path, profileItems, query } = this.props;

View File

@ -31,6 +31,7 @@
#adminmenumain,
#wpfooter,
#wpadminbar,
#wpbody-content,
.woocommerce-layout__header,
.update-nag,
.woocommerce-store-alerts,