2019-05-22 16:19:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-03-09 23:16:21 +00:00
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
2021-01-07 23:57:09 +00:00
|
|
|
import { Button, Card, CardBody, CardFooter } 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';
|
2020-07-15 14:52:21 +00:00
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
2020-03-09 23:16:21 +00:00
|
|
|
import { filter } from 'lodash';
|
2020-07-22 00:11:11 +00:00
|
|
|
import interpolateComponents from 'interpolate-components';
|
2020-12-21 19:34:22 +00:00
|
|
|
import { H, Link } from '@woocommerce/components';
|
2020-05-29 10:01:14 +00:00
|
|
|
import {
|
|
|
|
pluginNames,
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
PLUGINS_STORE_NAME,
|
2020-06-11 19:22:20 +00:00
|
|
|
OPTIONS_STORE_NAME,
|
2020-05-29 10:01:14 +00:00
|
|
|
} from '@woocommerce/data';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2021-01-07 23:57:09 +00:00
|
|
|
import { Text } from '@woocommerce/experimental';
|
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-08-13 02:05:22 +00:00
|
|
|
import { createNoticesFromResponse } from '../../../lib/notices';
|
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-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 );
|
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-03-03 09:44:26 +00:00
|
|
|
async skipPluginInstall() {
|
2019-10-24 16:20:32 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
2020-05-29 15:18:15 +00:00
|
|
|
goToNextStep,
|
2019-10-24 16:20:32 +00:00
|
|
|
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 } );
|
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
|
|
|
__(
|
2021-02-10 23:57:51 +00:00
|
|
|
'There was a problem updating your preferences',
|
2020-02-14 02:23:21 +00:00
|
|
|
'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
|
|
|
}
|
2020-05-29 15:18:15 +00:00
|
|
|
|
|
|
|
goToNextStep();
|
2019-05-22 16:19:56 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 12:01:33 +00:00
|
|
|
startPluginInstall() {
|
2020-06-12 06:38:33 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
goToNextStep,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
updateProfileItems,
|
|
|
|
updateOptions,
|
|
|
|
} = this.props;
|
2020-04-01 15:24:51 +00:00
|
|
|
const plugins = this.isJetpackActive ? 'installed-wcs' : 'installed';
|
2020-06-12 06:38:33 +00:00
|
|
|
|
2020-03-03 09:44:26 +00:00
|
|
|
recordEvent( 'storeprofiler_install_plugins', {
|
|
|
|
install: true,
|
|
|
|
plugins,
|
|
|
|
} );
|
2020-06-12 06:38:33 +00:00
|
|
|
|
2020-06-25 12:01:33 +00:00
|
|
|
Promise.all( [
|
2020-06-12 06:38:33 +00:00
|
|
|
installAndActivatePlugins( this.pluginsToInstall ),
|
|
|
|
updateProfileItems( { plugins } ),
|
|
|
|
updateOptions( {
|
|
|
|
woocommerce_setup_jetpack_opted_in: true,
|
|
|
|
} ),
|
2020-06-25 12:01:33 +00:00
|
|
|
] )
|
2020-07-15 14:52:21 +00:00
|
|
|
.then( goToNextStep )
|
2020-06-25 12:01:33 +00:00
|
|
|
.catch( ( pluginError, profileError ) => {
|
|
|
|
if ( pluginError ) {
|
|
|
|
createNoticesFromResponse( pluginError );
|
|
|
|
}
|
|
|
|
if ( profileError ) {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__(
|
2021-02-10 23:57:51 +00:00
|
|
|
'There was a problem updating your preferences',
|
2020-06-25 12:01:33 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
goToNextStep();
|
|
|
|
} );
|
|
|
|
}
|
2020-06-12 06:38:33 +00:00
|
|
|
|
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-06-12 06:38:33 +00:00
|
|
|
const {
|
|
|
|
activePlugins,
|
|
|
|
isInstallingActivating,
|
2020-12-01 22:56:17 +00:00
|
|
|
isUpdatingProfileItems,
|
2020-06-12 06:38:33 +00:00
|
|
|
} = 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' ) + ' ' );
|
2020-06-12 06:38:33 +00:00
|
|
|
const pluginsRemaining = this.pluginsToInstall.filter(
|
|
|
|
( plugin ) => ! activePlugins.includes( plugin )
|
|
|
|
);
|
|
|
|
const isInstallAction =
|
|
|
|
isInstallingActivating || ! pluginsRemaining.length;
|
2020-07-22 00:11:11 +00:00
|
|
|
const isAcceptingTos = ! this.isWcsActive;
|
|
|
|
const pluralizedPlugins = _n(
|
|
|
|
'plugin',
|
|
|
|
'plugins',
|
|
|
|
this.pluginsToInstall.length,
|
|
|
|
'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">
|
2020-12-21 19:34:22 +00:00
|
|
|
<CardBody justify="center">
|
|
|
|
<Logo />
|
|
|
|
<div className="woocommerce-profile-wizard__step-header">
|
|
|
|
<Text variant="title.small" as="h2">
|
|
|
|
{ sprintf(
|
|
|
|
__(
|
|
|
|
'Enhance your store with %s',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
pluginNamesString
|
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</div>
|
2019-10-03 16:03:29 +00:00
|
|
|
|
2020-12-21 19:34:22 +00:00
|
|
|
{ this.renderBenefits() }
|
|
|
|
</CardBody>
|
|
|
|
<CardFooter isBorderless justify="center">
|
2019-05-28 14:05:55 +00:00
|
|
|
<Button
|
|
|
|
isPrimary
|
2020-06-12 06:38:33 +00:00
|
|
|
isBusy={ isInstallAction }
|
2020-12-01 22:56:17 +00:00
|
|
|
disabled={ isUpdatingProfileItems || isInstallAction }
|
2020-03-03 09:44:26 +00:00
|
|
|
onClick={ this.startPluginInstall }
|
2019-05-28 14:05:55 +00:00
|
|
|
>
|
2020-03-09 23:16:21 +00:00
|
|
|
{ __( 'Yes please!', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
<Button
|
2020-06-11 19:22:20 +00:00
|
|
|
isSecondary
|
2020-12-01 22:56:17 +00:00
|
|
|
isBusy={ isUpdatingProfileItems && ! isInstallAction }
|
|
|
|
disabled={ isUpdatingProfileItems || isInstallAction }
|
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-12-21 19:34:22 +00:00
|
|
|
</CardFooter>
|
2019-05-27 16:37:02 +00:00
|
|
|
|
2020-12-21 19:34:22 +00:00
|
|
|
<CardFooter isBorderless justify="center">
|
|
|
|
<p className="woocommerce-profile-wizard__benefits-install-notice">
|
|
|
|
{ isAcceptingTos
|
|
|
|
? interpolateComponents( {
|
|
|
|
mixedString: sprintf(
|
|
|
|
__(
|
|
|
|
'%s %s will be installed & activated for free, and you agree to our {{link}}Terms of Service{{/link}}.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
pluginNamesString,
|
|
|
|
pluralizedPlugins
|
|
|
|
),
|
|
|
|
components: {
|
|
|
|
link: (
|
|
|
|
<Link
|
|
|
|
href="https://wordpress.com/tos/"
|
|
|
|
target="_blank"
|
|
|
|
type="external"
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
},
|
|
|
|
} )
|
|
|
|
: sprintf(
|
2020-07-22 00:11:11 +00:00
|
|
|
__(
|
2020-12-21 19:34:22 +00:00
|
|
|
'%s %s will be installed & activated for free.',
|
2020-07-22 00:11:11 +00:00
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
pluginNamesString,
|
|
|
|
pluralizedPlugins
|
2020-12-21 19:34:22 +00:00
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
</CardFooter>
|
2020-03-09 23:16:21 +00:00
|
|
|
</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-07-15 14:52:21 +00:00
|
|
|
const { getActivePlugins, isPluginsRequesting } = select(
|
|
|
|
PLUGINS_STORE_NAME
|
|
|
|
);
|
2019-08-23 12:56:57 +00:00
|
|
|
|
|
|
|
return {
|
2020-06-12 06:38:33 +00:00
|
|
|
activePlugins: getActivePlugins(),
|
|
|
|
isProfileItemsError: Boolean(
|
|
|
|
getOnboardingError( 'updateProfileItems' )
|
|
|
|
),
|
|
|
|
profileItems: getProfileItems(),
|
2020-12-01 22:56:17 +00:00
|
|
|
isUpdatingProfileItems: isOnboardingRequesting(
|
|
|
|
'updateProfileItems'
|
|
|
|
),
|
2020-06-12 06:38:33 +00:00
|
|
|
isInstallingActivating:
|
|
|
|
isPluginsRequesting( 'installPlugins' ) ||
|
|
|
|
isPluginsRequesting( 'activatePlugins' ) ||
|
|
|
|
isPluginsRequesting( 'getJetpackConnectUrl' ),
|
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 ) => {
|
2020-06-12 06:38:33 +00:00
|
|
|
const { installAndActivatePlugins } = dispatch( PLUGINS_STORE_NAME );
|
2020-05-29 10:01:14 +00:00
|
|
|
const { updateProfileItems } = dispatch( ONBOARDING_STORE_NAME );
|
2020-06-10 23:49:27 +00:00
|
|
|
const { updateOptions } = dispatch( OPTIONS_STORE_NAME );
|
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,
|
2020-06-12 06:38:33 +00:00
|
|
|
installAndActivatePlugins,
|
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 );
|