/**
* External dependencies
*/
import { __, _n, sprintf } from '@wordpress/i18n';
import { Button } from '@wordpress/components';
import { Component } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import { filter } from 'lodash';
/**
* WooCommerce dependencies
*/
import { Card, H } from '@woocommerce/components';
import { getAdminLink } from '@woocommerce/wc-admin-settings';
import {
pluginNames,
ONBOARDING_STORE_NAME,
PLUGINS_STORE_NAME,
OPTIONS_STORE_NAME,
} from '@woocommerce/data';
/**
* Internal dependencies
*/
import Connect from 'dashboard/components/connect';
import { createNoticesFromResponse } from 'lib/notices';
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';
import { recordEvent } from 'lib/tracks';
class Benefits extends Component {
constructor( props ) {
super( props );
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' );
}
recordEvent( 'storeprofiler_plugins_to_install', {
plugins: this.pluginsToInstall,
} );
this.startPluginInstall = this.startPluginInstall.bind( this );
this.skipPluginInstall = this.skipPluginInstall.bind( this );
}
async skipPluginInstall() {
const {
createNotice,
goToNextStep,
isProfileItemsError,
updateProfileItems,
} = this.props;
const plugins = this.isJetpackActive ? 'skipped-wcs' : 'skipped';
await updateProfileItems( { plugins } );
if ( isProfileItemsError ) {
createNotice(
'error',
__(
'There was a problem updating your preferences.',
'woocommerce-admin'
)
);
} else {
recordEvent( 'storeprofiler_install_plugins', {
install: false,
plugins,
} );
}
goToNextStep();
}
async startPluginInstall() {
const {
createNotice,
goToNextStep,
installAndActivatePlugins,
isJetpackConnected,
updateProfileItems,
updateOptions,
} = this.props;
const plugins = this.isJetpackActive ? 'installed-wcs' : 'installed';
recordEvent( 'storeprofiler_install_plugins', {
install: true,
plugins,
} );
await Promise.all( [
installAndActivatePlugins( this.pluginsToInstall ),
updateProfileItems( { plugins } ),
updateOptions( {
woocommerce_setup_jetpack_opted_in: true,
} ),
] ).catch( ( pluginError, profileError ) => {
if ( pluginError ) {
createNoticesFromResponse( pluginError );
}
if ( profileError ) {
createNotice(
'error',
__(
'There was a problem updating your preferences.',
'woocommerce-admin'
)
);
}
} );
if ( isJetpackConnected ) {
goToNextStep();
}
}
renderBenefit( benefit ) {
const { description, icon, title } = benefit;
return (
{ icon }
{ title }
{ description }
);
}
getBenefits() {
return [
{
title: __( 'Store management on the go', 'woocommerce-admin' ),
icon: ,
description: __(
'Your store in your pocket. Manage orders, receive sales notifications, and more. Only with a Jetpack connection.',
'woocommerce-admin'
),
visible: ! this.isJetpackActive,
},
{
title: __( 'Automated sales taxes', 'woocommerce-admin' ),
icon: ,
description: __(
'Ensure that the correct rate of tax is charged on all of your orders automatically, and print shipping labels at home.',
'woocommerce-admin'
),
visible: ! this.isWcsActive || ! this.isJetpackActive,
},
{
title: __( 'Improved speed & security', 'woocommerce-admin' ),
icon: ,
description: __(
'Automatically block brute force attacks and speed up your store using our powerful, global server network to cache images.',
'woocommerce-admin'
),
visible: ! this.isJetpackActive,
},
{
title: __(
'Print shipping labels at home',
'woocommerce-admin'
),
icon: ,
description: __(
'Save time at the post office by printing shipping labels for your orders at home.',
'woocommerce-admin'
),
visible: this.isJetpackActive && ! this.isWcsActive,
},
];
}
renderBenefits() {
return (