diff --git a/plugins/woocommerce-admin/client/dashboard/index.js b/plugins/woocommerce-admin/client/dashboard/index.js index f4ad0a1f3e2..1363aabb617 100644 --- a/plugins/woocommerce-admin/client/dashboard/index.js +++ b/plugins/woocommerce-admin/client/dashboard/index.js @@ -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; diff --git a/plugins/woocommerce-admin/client/layout/style.scss b/plugins/woocommerce-admin/client/layout/style.scss index 462399551c1..c25c6b23785 100644 --- a/plugins/woocommerce-admin/client/layout/style.scss +++ b/plugins/woocommerce-admin/client/layout/style.scss @@ -31,6 +31,7 @@ #adminmenumain, #wpfooter, #wpadminbar, + #wpbody-content, .woocommerce-layout__header, .update-nag, .woocommerce-store-alerts,