2019-05-22 16:19:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-03-09 23:16:21 +00:00
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
2019-12-02 17:39:22 +00:00
|
|
|
import { Button } from '@wordpress/components';
|
2020-03-09 23:16:21 +00:00
|
|
|
import { Component } from '@wordpress/element';
|
2019-05-31 04:51:33 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { withDispatch } from '@wordpress/data';
|
2020-03-09 23:16:21 +00:00
|
|
|
import { filter } from 'lodash';
|
2019-05-22 16:19:56 +00:00
|
|
|
|
|
|
|
/**
|
2019-11-14 14:35:55 +00:00
|
|
|
* WooCommerce dependencies
|
2019-05-22 16:19:56 +00:00
|
|
|
*/
|
2020-04-16 23:58:36 +00:00
|
|
|
import { Card, H, Plugins } from '@woocommerce/components';
|
2020-05-19 00:47:25 +00:00
|
|
|
import { getAdminLink } from '@woocommerce/wc-admin-settings';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { pluginNames, PLUGINS_STORE_NAME } from '@woocommerce/data';
|
2019-08-23 12:56:57 +00:00
|
|
|
|
|
|
|
/**
|
2019-11-14 14:35:55 +00:00
|
|
|
* Internal dependencies
|
2019-08-23 12:56:57 +00:00
|
|
|
*/
|
2020-05-19 00:47:25 +00:00
|
|
|
import Connect from 'dashboard/components/connect';
|
2020-03-09 23:16:21 +00:00
|
|
|
import Logo from './logo';
|
|
|
|
import ManagementIcon from './images/management';
|
|
|
|
import SalesTaxIcon from './images/sales_tax';
|
|
|
|
import ShippingLabels from './images/shipping_labels';
|
|
|
|
import SpeedIcon from './images/speed';
|
2019-05-31 04:51:33 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-07-01 18:13:29 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
2020-05-28 08:51:40 +00:00
|
|
|
import { ONBOARDING_STORE_NAME } from '../../../../packages/data/src';
|
2019-05-22 16:19:56 +00:00
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
class Benefits extends Component {
|
2019-10-10 14:05:13 +00:00
|
|
|
constructor( props ) {
|
|
|
|
super( props );
|
2019-05-22 16:19:56 +00:00
|
|
|
this.state = {
|
2020-05-19 00:47:25 +00:00
|
|
|
isConnecting: false,
|
2020-04-01 15:24:51 +00:00
|
|
|
isInstalling: false,
|
2020-05-19 00:47:25 +00:00
|
|
|
isActioned: false,
|
2019-05-22 16:19:56 +00:00
|
|
|
};
|
2020-04-01 15:24:51 +00:00
|
|
|
|
|
|
|
this.isJetpackActive = props.activePlugins.includes( 'jetpack' );
|
|
|
|
this.isWcsActive = props.activePlugins.includes(
|
|
|
|
'woocommerce-services'
|
|
|
|
);
|
|
|
|
this.pluginsToInstall = [];
|
|
|
|
if ( ! this.isJetpackActive ) {
|
|
|
|
this.pluginsToInstall.push( 'jetpack' );
|
|
|
|
}
|
|
|
|
if ( ! this.isWcsActive ) {
|
|
|
|
this.pluginsToInstall.push( 'woocommerce-services' );
|
|
|
|
}
|
|
|
|
|
2020-04-21 09:19:32 +00:00
|
|
|
recordEvent( 'storeprofiler_plugins_to_install', {
|
|
|
|
plugins: this.pluginsToInstall,
|
|
|
|
} );
|
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
this.startPluginInstall = this.startPluginInstall.bind( this );
|
|
|
|
this.skipPluginInstall = this.skipPluginInstall.bind( this );
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-01 15:24:51 +00:00
|
|
|
componentDidUpdate( prevProps, prevState ) {
|
2020-05-19 00:47:25 +00:00
|
|
|
const { goToNextStep } = this.props;
|
|
|
|
const { isActioned } = this.state;
|
2019-10-17 14:57:29 +00:00
|
|
|
|
2020-05-19 00:47:25 +00:00
|
|
|
// No longer pending or updating profile items, go to next step.
|
2020-04-01 15:24:51 +00:00
|
|
|
if (
|
2020-05-19 00:47:25 +00:00
|
|
|
isActioned &&
|
|
|
|
! this.isPending() &&
|
|
|
|
( prevProps.isRequesting ||
|
|
|
|
prevState.isConnecting ||
|
|
|
|
prevState.isInstalling )
|
2020-04-01 15:24:51 +00:00
|
|
|
) {
|
2020-03-03 09:44:26 +00:00
|
|
|
goToNextStep();
|
2019-08-23 12:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 00:47:25 +00:00
|
|
|
isPending() {
|
|
|
|
const { isActioned, isConnecting, isInstalling } = this.state;
|
|
|
|
const { isRequesting } = this.props;
|
|
|
|
return isActioned && ( isConnecting || isInstalling || isRequesting );
|
|
|
|
}
|
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
async skipPluginInstall() {
|
2019-10-24 16:20:32 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
isProfileItemsError,
|
|
|
|
updateProfileItems,
|
|
|
|
} = this.props;
|
2019-07-01 18:13:29 +00:00
|
|
|
|
2020-04-01 15:24:51 +00:00
|
|
|
const plugins = this.isJetpackActive ? 'skipped-wcs' : 'skipped';
|
2019-10-17 14:57:29 +00:00
|
|
|
await updateProfileItems( { plugins } );
|
2020-05-19 00:47:25 +00:00
|
|
|
this.setState( { isActioned: true } );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2019-10-10 14:05:13 +00:00
|
|
|
if ( isProfileItemsError ) {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
2020-02-14 02:23:21 +00:00
|
|
|
__(
|
|
|
|
'There was a problem updating your preferences.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
2019-07-23 03:26:46 +00:00
|
|
|
);
|
2019-10-10 14:05:13 +00:00
|
|
|
} else {
|
2020-03-03 09:44:26 +00:00
|
|
|
recordEvent( 'storeprofiler_install_plugins', {
|
|
|
|
install: false,
|
2020-02-14 02:23:21 +00:00
|
|
|
plugins,
|
|
|
|
} );
|
2019-05-31 04:51:33 +00:00
|
|
|
}
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
async startPluginInstall() {
|
2020-04-01 15:24:51 +00:00
|
|
|
const { updateProfileItems, updateOptions } = this.props;
|
2019-07-01 18:13:29 +00:00
|
|
|
|
2020-05-19 00:47:25 +00:00
|
|
|
this.setState( { isActioned: true, isInstalling: true } );
|
2020-03-03 09:44:26 +00:00
|
|
|
|
2019-10-03 16:03:29 +00:00
|
|
|
await updateOptions( {
|
|
|
|
woocommerce_setup_jetpack_opted_in: true,
|
|
|
|
} );
|
2019-10-17 14:57:29 +00:00
|
|
|
|
2020-04-01 15:24:51 +00:00
|
|
|
const plugins = this.isJetpackActive ? 'installed-wcs' : 'installed';
|
2020-03-03 09:44:26 +00:00
|
|
|
recordEvent( 'storeprofiler_install_plugins', {
|
|
|
|
install: true,
|
|
|
|
plugins,
|
|
|
|
} );
|
|
|
|
updateProfileItems( { plugins } );
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderBenefit( benefit ) {
|
|
|
|
const { description, icon, title } = benefit;
|
|
|
|
|
|
|
|
return (
|
2020-03-09 23:16:21 +00:00
|
|
|
<div
|
|
|
|
className="woocommerce-profile-wizard__benefit-card"
|
|
|
|
key={ title }
|
|
|
|
>
|
2019-05-22 16:19:56 +00:00
|
|
|
{ icon }
|
2020-03-09 23:16:21 +00:00
|
|
|
<div className="woocommerce-profile-wizard__benefit-card-content">
|
|
|
|
<H className="woocommerce-profile-wizard__benefit-card-title">
|
2020-02-14 02:23:21 +00:00
|
|
|
{ title }
|
|
|
|
</H>
|
2019-05-22 16:19:56 +00:00
|
|
|
<p>{ description }</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-23 12:56:57 +00:00
|
|
|
getBenefits() {
|
|
|
|
return [
|
|
|
|
{
|
2020-03-09 23:16:21 +00:00
|
|
|
title: __( 'Store management on the go', 'woocommerce-admin' ),
|
|
|
|
icon: <ManagementIcon />,
|
2019-08-23 12:56:57 +00:00
|
|
|
description: __(
|
2020-03-09 23:16:21 +00:00
|
|
|
'Your store in your pocket. Manage orders, receive sales notifications, and more. Only with a Jetpack connection.',
|
2019-08-23 12:56:57 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2020-04-01 15:24:51 +00:00
|
|
|
visible: ! this.isJetpackActive,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
2020-03-09 23:16:21 +00:00
|
|
|
title: __( 'Automated sales taxes', 'woocommerce-admin' ),
|
2019-08-23 12:56:57 +00:00
|
|
|
icon: <SalesTaxIcon />,
|
|
|
|
description: __(
|
2020-03-09 23:16:21 +00:00
|
|
|
'Ensure that the correct rate of tax is charged on all of your orders automatically, and print shipping labels at home.',
|
2019-08-23 12:56:57 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2020-04-01 15:24:51 +00:00
|
|
|
visible: ! this.isWcsActive || ! this.isJetpackActive,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
2020-03-09 23:16:21 +00:00
|
|
|
title: __( 'Improved speed & security', 'woocommerce-admin' ),
|
2019-08-23 12:56:57 +00:00
|
|
|
icon: <SpeedIcon />,
|
|
|
|
description: __(
|
2020-03-09 23:16:21 +00:00
|
|
|
'Automatically block brute force attacks and speed up your store using our powerful, global server network to cache images.',
|
2019-08-23 12:56:57 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2020-04-01 15:24:51 +00:00
|
|
|
visible: ! this.isJetpackActive,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
{
|
2020-02-14 02:23:21 +00:00
|
|
|
title: __(
|
2020-03-09 23:16:21 +00:00
|
|
|
'Print shipping labels at home',
|
2020-02-14 02:23:21 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2020-03-09 23:16:21 +00:00
|
|
|
icon: <ShippingLabels />,
|
2019-08-23 12:56:57 +00:00
|
|
|
description: __(
|
2020-03-09 23:16:21 +00:00
|
|
|
'Save time at the post office by printing shipping labels for your orders at home.',
|
2019-08-23 12:56:57 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2020-04-01 15:24:51 +00:00
|
|
|
visible: this.isJetpackActive && ! this.isWcsActive,
|
2019-08-23 12:56:57 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
renderBenefits() {
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-profile-wizard__benefits">
|
2020-02-14 02:23:21 +00:00
|
|
|
{ filter(
|
|
|
|
this.getBenefits(),
|
|
|
|
( benefit ) => benefit.visible
|
|
|
|
).map( ( benefit ) => this.renderBenefit( benefit ) ) }
|
2019-08-23 12:56:57 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-22 16:19:56 +00:00
|
|
|
render() {
|
2020-05-19 00:47:25 +00:00
|
|
|
const { isConnecting, isInstalling } = this.state;
|
|
|
|
const { isJetpackConnected, isRequesting } = this.props;
|
2019-10-10 14:05:13 +00:00
|
|
|
|
2020-04-01 15:24:51 +00:00
|
|
|
const pluginNamesString = this.pluginsToInstall
|
2020-02-14 02:23:21 +00:00
|
|
|
.map( ( pluginSlug ) => pluginNames[ pluginSlug ] )
|
2020-03-09 23:16:21 +00:00
|
|
|
.join( ' ' + __( 'and', 'woocommerce-admin' ) + ' ' );
|
2019-05-22 16:19:56 +00:00
|
|
|
|
|
|
|
return (
|
2020-03-09 23:16:21 +00:00
|
|
|
<Card className="woocommerce-profile-wizard__benefits-card">
|
|
|
|
<Logo />
|
2019-05-27 16:37:02 +00:00
|
|
|
<H className="woocommerce-profile-wizard__header-title">
|
2020-03-09 23:16:21 +00:00
|
|
|
{ sprintf(
|
|
|
|
__( 'Enhance your store with %s', 'woocommerce-admin' ),
|
|
|
|
pluginNamesString
|
2020-02-14 02:23:21 +00:00
|
|
|
) }
|
2019-05-27 16:37:02 +00:00
|
|
|
</H>
|
|
|
|
|
2020-03-09 23:16:21 +00:00
|
|
|
{ this.renderBenefits() }
|
2019-10-03 16:03:29 +00:00
|
|
|
|
2020-03-09 23:16:21 +00:00
|
|
|
<div className="woocommerce-profile-wizard__card-actions">
|
2019-05-28 14:05:55 +00:00
|
|
|
<Button
|
|
|
|
isPrimary
|
2020-05-19 00:47:25 +00:00
|
|
|
isBusy={
|
|
|
|
this.isPending() && ( isInstalling || isConnecting )
|
|
|
|
}
|
|
|
|
disabled={ this.isPending() }
|
2020-03-03 09:44:26 +00:00
|
|
|
onClick={ this.startPluginInstall }
|
2019-05-30 06:31:07 +00:00
|
|
|
className="woocommerce-profile-wizard__continue"
|
2019-05-28 14:05:55 +00:00
|
|
|
>
|
2020-03-09 23:16:21 +00:00
|
|
|
{ __( 'Yes please!', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
isDefault
|
2020-05-19 00:47:25 +00:00
|
|
|
isBusy={
|
|
|
|
this.isPending() && ! isInstalling && ! isConnecting
|
|
|
|
}
|
|
|
|
disabled={ this.isPending() }
|
2020-03-09 23:16:21 +00:00
|
|
|
className="woocommerce-profile-wizard__skip"
|
|
|
|
onClick={ this.skipPluginInstall }
|
|
|
|
>
|
|
|
|
{ __( 'No thanks', 'woocommerce-admin' ) }
|
2019-05-27 16:37:02 +00:00
|
|
|
</Button>
|
2020-04-01 15:24:51 +00:00
|
|
|
|
|
|
|
{ isInstalling && (
|
|
|
|
<Plugins
|
|
|
|
autoInstall
|
|
|
|
onComplete={ () =>
|
2020-05-19 00:47:25 +00:00
|
|
|
this.setState( {
|
|
|
|
isInstalling: false,
|
|
|
|
isConnecting: ! isJetpackConnected,
|
|
|
|
} )
|
2020-04-01 15:24:51 +00:00
|
|
|
}
|
|
|
|
onError={ () =>
|
2020-05-19 00:47:25 +00:00
|
|
|
this.setState( {
|
|
|
|
isInstalling: false,
|
|
|
|
} )
|
2020-04-01 15:24:51 +00:00
|
|
|
}
|
|
|
|
pluginSlugs={ this.pluginsToInstall }
|
|
|
|
/>
|
|
|
|
) }
|
2020-05-19 00:47:25 +00:00
|
|
|
|
|
|
|
{ /* Make sure we're finished requesting since this will auto redirect us. */ }
|
|
|
|
{ isConnecting && ! isJetpackConnected && ! isRequesting && (
|
|
|
|
<Connect
|
|
|
|
autoConnect
|
|
|
|
onConnect={ () => {
|
|
|
|
recordEvent(
|
|
|
|
'storeprofiler_jetpack_connect_redirect'
|
|
|
|
);
|
|
|
|
} }
|
|
|
|
onError={ () =>
|
|
|
|
this.setState( { isConnecting: false } )
|
|
|
|
}
|
|
|
|
redirectUrl={ getAdminLink(
|
|
|
|
'admin.php?page=wc-admin&reset_profiler=0'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
2020-03-09 23:16:21 +00:00
|
|
|
</div>
|
2019-05-27 16:37:02 +00:00
|
|
|
|
2020-03-09 23:16:21 +00:00
|
|
|
<p className="woocommerce-profile-wizard__benefits-install-notice">
|
|
|
|
{ sprintf(
|
|
|
|
__(
|
|
|
|
'%s %s will be installed & activated for free.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
pluginNamesString,
|
|
|
|
_n(
|
|
|
|
'plugin',
|
|
|
|
'plugins',
|
2020-04-01 15:24:51 +00:00
|
|
|
this.pluginsToInstall.length,
|
2020-03-09 23:16:21 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
</Card>
|
2019-05-22 16:19:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
export default compose(
|
2020-02-14 02:23:21 +00:00
|
|
|
withSelect( ( select ) => {
|
2019-10-24 16:20:32 +00:00
|
|
|
const {
|
2020-05-28 08:51:40 +00:00
|
|
|
getOnboardingError,
|
2019-10-24 16:20:32 +00:00
|
|
|
getProfileItems,
|
2020-05-28 08:51:40 +00:00
|
|
|
isOnboardingRequesting,
|
|
|
|
} = select( ONBOARDING_STORE_NAME );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
2020-05-19 00:47:25 +00:00
|
|
|
const { getActivePlugins, isJetpackConnected } = select(
|
|
|
|
PLUGINS_STORE_NAME
|
|
|
|
);
|
2020-04-16 23:58:36 +00:00
|
|
|
|
2020-05-28 08:51:40 +00:00
|
|
|
const isProfileItemsError = Boolean(
|
|
|
|
getOnboardingError( 'updateProfileItems' )
|
|
|
|
);
|
2019-08-23 12:56:57 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
2019-10-17 14:57:29 +00:00
|
|
|
const profileItems = getProfileItems();
|
2019-08-23 12:56:57 +00:00
|
|
|
|
|
|
|
return {
|
2020-04-01 15:24:51 +00:00
|
|
|
activePlugins,
|
2019-08-23 12:56:57 +00:00
|
|
|
isProfileItemsError,
|
2019-10-17 14:57:29 +00:00
|
|
|
profileItems,
|
2020-05-19 00:47:25 +00:00
|
|
|
isJetpackConnected: isJetpackConnected(),
|
2020-05-28 08:51:40 +00:00
|
|
|
isRequesting: isOnboardingRequesting( 'updateProfileItems' ),
|
2019-08-23 12:56:57 +00:00
|
|
|
};
|
2019-05-31 04:51:33 +00:00
|
|
|
} ),
|
2020-02-14 02:23:21 +00:00
|
|
|
withDispatch( ( dispatch ) => {
|
2019-10-10 14:05:13 +00:00
|
|
|
const { updateProfileItems, updateOptions } = dispatch( 'wc-api' );
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2019-05-31 04:51:33 +00:00
|
|
|
updateProfileItems,
|
2019-10-03 16:03:29 +00:00
|
|
|
updateOptions,
|
2019-05-31 04:51:33 +00:00
|
|
|
};
|
|
|
|
} )
|
2020-03-03 09:44:26 +00:00
|
|
|
)( Benefits );
|