/** * External dependencies */ import { __, _n, sprintf } from '@wordpress/i18n'; import { Button, Card, CardBody, CardFooter, __experimentalText as Text, } from '@wordpress/components'; import { Component } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { withDispatch, withSelect } from '@wordpress/data'; import { filter } from 'lodash'; import interpolateComponents from 'interpolate-components'; import { H, Link } from '@woocommerce/components'; import { pluginNames, ONBOARDING_STORE_NAME, PLUGINS_STORE_NAME, OPTIONS_STORE_NAME, } from '@woocommerce/data'; import { recordEvent } from '@woocommerce/tracks'; /** * Internal dependencies */ 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'; 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(); } startPluginInstall() { const { createNotice, goToNextStep, installAndActivatePlugins, updateProfileItems, updateOptions, } = this.props; const plugins = this.isJetpackActive ? 'installed-wcs' : 'installed'; recordEvent( 'storeprofiler_install_plugins', { install: true, plugins, } ); Promise.all( [ installAndActivatePlugins( this.pluginsToInstall ), updateProfileItems( { plugins } ), updateOptions( { woocommerce_setup_jetpack_opted_in: true, } ), ] ) .then( goToNextStep ) .catch( ( pluginError, profileError ) => { if ( pluginError ) { createNoticesFromResponse( pluginError ); } if ( profileError ) { createNotice( 'error', __( 'There was a problem updating your preferences.', 'woocommerce-admin' ) ); } goToNextStep(); } ); } renderBenefit( benefit ) { const { description, icon, title } = benefit; return (
{ description }
{ 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: ( ), }, } ) : sprintf( __( '%s %s will be installed & activated for free.', 'woocommerce-admin' ), pluginNamesString, pluralizedPlugins ) }