/** * 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 } from '@wordpress/data'; import { filter } from 'lodash'; /** * WooCommerce dependencies */ import { Card, H, Plugins } from '@woocommerce/components'; import { getAdminLink } from '@woocommerce/wc-admin-settings'; import { pluginNames, ONBOARDING_STORE_NAME, PLUGINS_STORE_NAME, } from '@woocommerce/data'; /** * Internal dependencies */ import Connect from 'dashboard/components/connect'; 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 withSelect from 'wc-api/with-select'; import { recordEvent } from 'lib/tracks'; class Benefits extends Component { constructor( props ) { super( props ); this.state = { isConnecting: false, isInstalling: false, }; 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 ); } componentDidUpdate( prevProps, prevState ) { const { goToNextStep } = this.props; // No longer pending or updating profile items, go to next step. if ( ! this.isPending() && ( prevProps.isRequesting || prevState.isConnecting || prevState.isInstalling ) ) { goToNextStep(); } } isPending() { const { isConnecting, isInstalling } = this.state; const { isRequesting } = this.props; return isConnecting || isInstalling || isRequesting; } 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 { updateProfileItems, updateOptions } = this.props; this.setState( { isInstalling: true } ); await updateOptions( { woocommerce_setup_jetpack_opted_in: true, } ); const plugins = this.isJetpackActive ? 'installed-wcs' : 'installed'; recordEvent( 'storeprofiler_install_plugins', { install: true, plugins, } ); updateProfileItems( { plugins } ); } renderBenefit( benefit ) { const { description, icon, title } = benefit; return (
{ description }
{ sprintf( __( '%s %s will be installed & activated for free.', 'woocommerce-admin' ), pluginNamesString, _n( 'plugin', 'plugins', this.pluginsToInstall.length, 'woocommerce-admin' ) ) }