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-03-09 23:16:21 +00:00
|
|
|
import { Card, H } from '@woocommerce/components';
|
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-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';
|
2019-10-24 16:20:32 +00:00
|
|
|
import { pluginNames } from 'wc-api/onboarding/constants';
|
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-03-03 09:44:26 +00:00
|
|
|
isPending: false,
|
2019-05-22 16:19:56 +00:00
|
|
|
};
|
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-03-03 09:44:26 +00:00
|
|
|
componentDidUpdate( prevProps ) {
|
|
|
|
const { goToNextStep, isRequesting } = this.props;
|
|
|
|
const { isPending } = this.state;
|
2019-10-17 14:57:29 +00:00
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
if ( ! isRequesting && prevProps.isRequesting && isPending ) {
|
|
|
|
goToNextStep();
|
|
|
|
this.setState( { isPending: false } );
|
2019-08-23 12:56:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
async skipPluginInstall() {
|
2019-10-24 16:20:32 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
2020-03-03 09:44:26 +00:00
|
|
|
isJetpackActive,
|
2019-10-24 16:20:32 +00:00
|
|
|
isProfileItemsError,
|
|
|
|
updateProfileItems,
|
|
|
|
} = this.props;
|
2019-07-01 18:13:29 +00:00
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
this.setState( { isPending: true } );
|
|
|
|
|
|
|
|
const plugins = isJetpackActive ? 'skipped-wcs' : 'skipped';
|
2019-10-17 14:57:29 +00:00
|
|
|
await updateProfileItems( { plugins } );
|
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() {
|
2019-10-17 14:57:29 +00:00
|
|
|
const {
|
2020-03-03 09:44:26 +00:00
|
|
|
isJetpackActive,
|
2019-10-17 14:57:29 +00:00
|
|
|
updateProfileItems,
|
|
|
|
updateOptions,
|
|
|
|
} = this.props;
|
2019-07-01 18:13:29 +00:00
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
this.setState( { isPending: true } );
|
|
|
|
|
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-03-03 09:44:26 +00:00
|
|
|
const plugins = isJetpackActive ? 'installed-wcs' : 'installed';
|
|
|
|
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() {
|
2020-03-09 23:16:21 +00:00
|
|
|
const { isJetpackActive, isWcsActive } = this.props;
|
2019-08-23 12:56:57 +00:00
|
|
|
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-03-03 09:44:26 +00:00
|
|
|
visible: ! 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-03-09 23:16:21 +00:00
|
|
|
visible: ! isWcsActive || ! 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-03-03 09:44:26 +00:00
|
|
|
visible: ! 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-03-09 23:16:21 +00:00
|
|
|
visible: isJetpackActive && ! 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-03-03 09:44:26 +00:00
|
|
|
const { isJetpackActive, isWcsActive } = this.props;
|
|
|
|
const { isPending } = this.state;
|
2019-10-10 14:05:13 +00:00
|
|
|
|
2019-10-24 16:20:32 +00:00
|
|
|
const pluginsToInstall = [];
|
2020-03-03 09:44:26 +00:00
|
|
|
if ( ! isJetpackActive ) {
|
2019-10-24 16:20:32 +00:00
|
|
|
pluginsToInstall.push( 'jetpack' );
|
|
|
|
}
|
2020-03-03 09:44:26 +00:00
|
|
|
if ( ! isWcsActive ) {
|
2019-10-24 16:20:32 +00:00
|
|
|
pluginsToInstall.push( 'woocommerce-services' );
|
|
|
|
}
|
|
|
|
const pluginNamesString = 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-03-03 09:44:26 +00:00
|
|
|
isBusy={ isPending }
|
|
|
|
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
|
|
|
|
isBusy={ isPending }
|
|
|
|
className="woocommerce-profile-wizard__skip"
|
|
|
|
onClick={ this.skipPluginInstall }
|
|
|
|
>
|
|
|
|
{ __( 'No thanks', 'woocommerce-admin' ) }
|
2019-05-27 16:37:02 +00:00
|
|
|
</Button>
|
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',
|
|
|
|
pluginsToInstall.length,
|
|
|
|
'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 {
|
|
|
|
getProfileItemsError,
|
|
|
|
getActivePlugins,
|
|
|
|
getProfileItems,
|
2020-03-03 09:44:26 +00:00
|
|
|
isGetProfileItemsRequesting,
|
2019-10-24 16:20:32 +00:00
|
|
|
} = select( 'wc-api' );
|
2019-05-31 04:51:33 +00:00
|
|
|
|
|
|
|
const isProfileItemsError = Boolean( getProfileItemsError() );
|
2019-08-23 12:56:57 +00:00
|
|
|
const activePlugins = getActivePlugins();
|
2019-10-17 14:57:29 +00:00
|
|
|
const profileItems = getProfileItems();
|
2020-03-03 09:44:26 +00:00
|
|
|
const isJetpackActive = activePlugins.includes( 'jetpack' );
|
|
|
|
const isWcsActive = activePlugins.includes( 'woocommerce-services' );
|
2019-08-23 12:56:57 +00:00
|
|
|
|
|
|
|
return {
|
2020-03-03 09:44:26 +00:00
|
|
|
isJetpackActive,
|
2019-08-23 12:56:57 +00:00
|
|
|
isProfileItemsError,
|
2020-03-03 09:44:26 +00:00
|
|
|
isWcsActive,
|
2019-10-17 14:57:29 +00:00
|
|
|
profileItems,
|
2020-03-03 09:44:26 +00:00
|
|
|
isRequesting: isGetProfileItemsRequesting(),
|
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 );
|