/** @format */ /** * External dependencies */ import { __, _x, sprintf } from '@wordpress/i18n'; import { Component, Fragment } from '@wordpress/element'; import { compose } from '@wordpress/compose'; import { FormToggle } from '@wordpress/components'; import { Button, SelectControl } from 'newspack-components'; import { withDispatch } from '@wordpress/data'; import { keys, pickBy } from 'lodash'; /** * WooCommerce dependencies */ import { numberFormat } from '@woocommerce/number'; /** * Internal dependencies */ import { H, Card } from '@woocommerce/components'; import withSelect from 'wc-api/with-select'; import { recordEvent } from 'lib/tracks'; class BusinessDetails extends Component { constructor() { super(); this.state = { other_platform: '', product_count: '', selling_venues: '', extensions: { facebook: true, mailchimp: true, }, }; this.onContinue = this.onContinue.bind( this ); } async onContinue() { const { addNotice, goToNextStep, isError, updateProfileItems } = this.props; const { other_platform, product_count, selling_venues } = this.state; const extensions = keys( pickBy( this.state.extensions ) ); recordEvent( 'storeprofiler_store_business_details_continue', { product_number: product_count, already_selling: 'no' !== selling_venues, used_platform: other_platform, install_facebook: this.state.extensions.facebook, install_mailchimp: this.state.extensions.mailchimp, } ); await updateProfileItems( { other_platform, product_count, selling_venues, business_extensions: extensions, } ); if ( ! isError ) { goToNextStep(); } else { addNotice( { status: 'error', message: __( 'There was a problem updating your business details.', 'woocommerce-admin' ), } ); } } isValidForm() { const { other_platform, product_count, selling_venues } = this.state; const other_platform_valid = [ 'other', 'brick-mortar-other' ].includes( selling_venues ) ? other_platform.length : true; if ( other_platform_valid && product_count.length && selling_venues.length ) { return true; } return false; } getNumberRangeString( min, max = false ) { if ( ! max ) { return sprintf( _x( '%s+', 'store product count', 'woocommerce-admin' ), numberFormat( min ) ); } return sprintf( _x( '%s - %s', 'store product count', 'woocommerce-admin' ), numberFormat( min ), numberFormat( max ) ); } setDefaultValue( key, options ) { if ( ! this.state[ key ].length ) { this.setState( { [ key ]: options[ 0 ].value } ); } } onExtensionChange( extension ) { this.setState( { extensions: { ...this.state.extensions, [ extension ]: ! this.state.extensions[ extension ], }, } ); } renderBusinessExtensionHelpText() { const extensionSlugs = { facebook: __( 'Facebook for WooCommerce', 'woocommerce-admin' ), mailchimp: __( 'Mailchimp for WooCommerce', 'woocommerce-admin' ), }; const extensions = keys( pickBy( this.state.extensions ) ); if ( 0 === extensions.length ) { return null; } return (
{ sprintf( __( 'The following plugins will be installed for free: %s' ), extensions .map( extension => { return extensionSlugs[ extension ]; } ) .join( ', ' ) ) }
); } renderBusinessExtensions() { const extensionBenefits = [ { slug: 'facebook', title: __( 'Market on Facebook', 'woocommerce-admin' ), icon: 'onboarding/facebook.png', description: __( 'Grow your business by targeting the right people and driving sales with Facebook.', 'woocommerce-admin' ), }, { slug: 'mailchimp', title: __( 'Contact customers with Mailchimp', 'woocommerce-admin' ), icon: 'onboarding/mailchimp.png', description: __( 'Send targeted campaigns, recover abandoned carts and much more with Mailchimp.', 'woocommerce-admin' ), }, ]; return ({ benefit.description }
{ __( 'Tell us about the business' ) }