2019-06-12 03:56:10 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _x, sprintf } from '@wordpress/i18n';
|
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
|
|
|
import { compose } from '@wordpress/compose';
|
2019-07-04 15:56:28 +00:00
|
|
|
import { FormToggle } from '@wordpress/components';
|
2019-06-12 03:56:10 +00:00
|
|
|
import { Button, SelectControl } from 'newspack-components';
|
|
|
|
import { withDispatch } from '@wordpress/data';
|
2019-07-04 15:56:28 +00:00
|
|
|
import { keys, pickBy } from 'lodash';
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { numberFormat } from '@woocommerce/number';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { H, Card } from '@woocommerce/components';
|
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-07-01 18:13:29 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
class BusinessDetails extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
2019-07-15 11:09:31 +00:00
|
|
|
errors: {},
|
|
|
|
fields: {
|
|
|
|
other_platform: '',
|
|
|
|
product_count: '',
|
|
|
|
selling_venues: '',
|
|
|
|
extensions: {
|
|
|
|
facebook: true,
|
|
|
|
mailchimp: true,
|
|
|
|
},
|
2019-07-04 15:56:28 +00:00
|
|
|
},
|
2019-06-12 03:56:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onContinue = this.onContinue.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
async onContinue() {
|
2019-07-15 11:09:31 +00:00
|
|
|
await this.validateForm();
|
|
|
|
if ( Object.keys( this.state.errors ).length ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-10 16:58:51 +00:00
|
|
|
const { addNotice, goToNextStep, isError, updateProfileItems } = this.props;
|
2019-07-15 11:09:31 +00:00
|
|
|
const { extensions, other_platform, product_count, selling_venues } = this.state.fields;
|
|
|
|
const businessExtensions = keys( pickBy( extensions ) );
|
2019-06-12 03:56:10 +00:00
|
|
|
|
2019-07-01 18:13:29 +00:00
|
|
|
recordEvent( 'storeprofiler_store_business_details_continue', {
|
|
|
|
product_number: product_count,
|
|
|
|
already_selling: 'no' !== selling_venues,
|
|
|
|
used_platform: other_platform,
|
2019-07-15 11:09:31 +00:00
|
|
|
install_facebook: extensions.facebook,
|
|
|
|
install_mailchimp: extensions.mailchimp,
|
2019-07-01 18:13:29 +00:00
|
|
|
} );
|
|
|
|
|
2019-07-04 15:56:28 +00:00
|
|
|
await updateProfileItems( {
|
|
|
|
other_platform,
|
|
|
|
product_count,
|
|
|
|
selling_venues,
|
2019-07-15 11:09:31 +00:00
|
|
|
business_extensions: businessExtensions,
|
2019-07-04 15:56:28 +00:00
|
|
|
} );
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
if ( ! isError ) {
|
|
|
|
goToNextStep();
|
|
|
|
} else {
|
2019-07-10 16:58:51 +00:00
|
|
|
addNotice( {
|
|
|
|
status: 'error',
|
|
|
|
message: __( 'There was a problem updating your business details.', 'woocommerce-admin' ),
|
|
|
|
} );
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-15 11:09:31 +00:00
|
|
|
validateField( name ) {
|
|
|
|
const { errors, fields } = this.state;
|
|
|
|
|
|
|
|
switch ( name ) {
|
|
|
|
case 'extensions':
|
|
|
|
break;
|
|
|
|
case 'other_platform':
|
|
|
|
errors.other_platform =
|
|
|
|
[ 'other', 'brick-mortar-other' ].includes( fields.selling_venues ) &&
|
|
|
|
! fields.other_platform.length
|
|
|
|
? __( 'This field is required', 'woocommerce-admin' )
|
|
|
|
: null;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errors[ name ] = ! fields[ name ].length
|
|
|
|
? __( 'This field is required', 'woocommerce-admin' )
|
|
|
|
: null;
|
|
|
|
break;
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-15 11:09:31 +00:00
|
|
|
this.setState( { errors: pickBy( errors ) } );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateValue( name, value ) {
|
|
|
|
const fields = { ...this.state.fields, [ name ]: value };
|
|
|
|
this.setState( { fields }, () => this.validateField( name ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
async validateForm() {
|
|
|
|
const { fields } = this.state;
|
|
|
|
Object.keys( fields ).forEach( fieldName => this.validateField( fieldName ) );
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-07-03 05:53:00 +00:00
|
|
|
setDefaultValue( key, options ) {
|
2019-07-15 11:09:31 +00:00
|
|
|
const { fields } = this.state;
|
|
|
|
|
|
|
|
if ( ! fields[ key ].length ) {
|
|
|
|
this.setState( { fields: { ...fields, [ key ]: options[ 0 ].value } }, () =>
|
|
|
|
this.validateField( key )
|
|
|
|
);
|
2019-07-03 05:53:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-04 15:56:28 +00:00
|
|
|
onExtensionChange( extension ) {
|
2019-07-15 11:09:31 +00:00
|
|
|
const { fields } = this.state;
|
|
|
|
const extensions = {
|
|
|
|
...fields.extensions,
|
|
|
|
[ extension ]: ! fields.extensions[ extension ],
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setState( { fields: { ...fields, extensions } } );
|
2019-07-04 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
renderBusinessExtensionHelpText() {
|
|
|
|
const extensionSlugs = {
|
|
|
|
facebook: __( 'Facebook for WooCommerce', 'woocommerce-admin' ),
|
|
|
|
mailchimp: __( 'Mailchimp for WooCommerce', 'woocommerce-admin' ),
|
|
|
|
};
|
|
|
|
|
2019-07-15 11:09:31 +00:00
|
|
|
const extensions = keys( pickBy( this.state.fields.extensions ) );
|
2019-07-04 15:56:28 +00:00
|
|
|
if ( 0 === extensions.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<p>
|
|
|
|
{ sprintf(
|
|
|
|
__( 'The following plugins will be installed for free: %s' ),
|
|
|
|
extensions
|
|
|
|
.map( extension => {
|
|
|
|
return extensionSlugs[ extension ];
|
|
|
|
} )
|
|
|
|
.join( ', ' )
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 (
|
|
|
|
<div className="woocommerce-profile-wizard__benefits">
|
|
|
|
{ extensionBenefits.map( benefit => (
|
|
|
|
<div className="woocommerce-profile-wizard__benefit" key={ benefit.title }>
|
|
|
|
<div className="woocommerce-profile-wizard__business-extension">
|
|
|
|
<img src={ wcSettings.wcAdminAssetUrl + benefit.icon } alt="" />
|
|
|
|
</div>
|
|
|
|
<div className="woocommerce-profile-wizard__benefit-content">
|
|
|
|
<H className="woocommerce-profile-wizard__benefit-title">{ benefit.title }</H>
|
|
|
|
<p>{ benefit.description }</p>
|
|
|
|
</div>
|
|
|
|
<div className="woocommerce-profile-wizard__benefit-toggle">
|
|
|
|
<FormToggle
|
2019-07-15 11:09:31 +00:00
|
|
|
checked={ this.state.fields.extensions[ benefit.slug ] }
|
2019-07-04 15:56:28 +00:00
|
|
|
onChange={ () => this.onExtensionChange( benefit.slug ) }
|
|
|
|
className="woocommerce-profile-wizard__toggle"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
render() {
|
2019-07-15 11:09:31 +00:00
|
|
|
const { errors, fields } = this.state;
|
|
|
|
const { other_platform, product_count, selling_venues } = fields;
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
const productCountOptions = [
|
|
|
|
{
|
|
|
|
value: '1-10',
|
|
|
|
label: this.getNumberRangeString( 1, 10 ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '11-100',
|
|
|
|
label: this.getNumberRangeString( 11, 100 ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '101-1000',
|
|
|
|
label: this.getNumberRangeString( 101, 1000 ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '1000+',
|
|
|
|
label: this.getNumberRangeString( 1000 ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const sellingVenueOptions = [
|
|
|
|
{
|
|
|
|
value: 'no',
|
|
|
|
label: __( 'No', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'other',
|
|
|
|
label: __( 'Yes, on another platform', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'brick-mortar',
|
|
|
|
label: __( 'Yes, at a brick and mortar store', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'brick-mortar-other',
|
|
|
|
label: __(
|
|
|
|
'Yes, on another platform and at a brick and mortar store',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const otherPlatformOptions = [
|
|
|
|
{
|
|
|
|
value: 'shopify',
|
|
|
|
label: __( 'Shopify', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'bigcommerce',
|
|
|
|
label: __( 'BigCommerce', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'magento',
|
|
|
|
label: __( 'Magento', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'wix',
|
|
|
|
label: __( 'Wix', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'other',
|
|
|
|
label: __( 'Other', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-07-04 15:56:28 +00:00
|
|
|
// Show extensions when the currently selling elsewhere checkbox has been answered.
|
2019-07-15 11:09:31 +00:00
|
|
|
const showExtensions = '' !== selling_venues;
|
2019-07-04 15:56:28 +00:00
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<H className="woocommerce-profile-wizard__header-title">
|
|
|
|
{ __( 'Business details', 'woocommerce-admin' ) }
|
|
|
|
</H>
|
|
|
|
<p>{ __( 'Tell us about the business' ) }</p>
|
|
|
|
|
|
|
|
<Card className="woocommerce-profile-wizard__product-types-card">
|
|
|
|
<SelectControl
|
|
|
|
label={ __( 'How many products will you add?', 'woocommerce-admin' ) }
|
2019-07-15 11:09:31 +00:00
|
|
|
onChange={ value => this.updateValue( 'product_count', value ) }
|
2019-07-03 05:53:00 +00:00
|
|
|
onFocus={ this.setDefaultValue.bind( this, 'product_count', productCountOptions ) }
|
2019-06-12 03:56:10 +00:00
|
|
|
options={ productCountOptions }
|
|
|
|
value={ product_count }
|
2019-07-15 11:09:31 +00:00
|
|
|
help={ errors.product_count }
|
|
|
|
className={ errors.product_count ? 'has-error' : null }
|
2019-06-12 03:56:10 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SelectControl
|
|
|
|
label={ __( 'Currently selling elsewhere?', 'woocommerce-admin' ) }
|
2019-07-15 11:09:31 +00:00
|
|
|
onChange={ value => this.updateValue( 'selling_venues', value ) }
|
2019-07-03 05:53:00 +00:00
|
|
|
onFocus={ this.setDefaultValue.bind( this, 'selling_venues', sellingVenueOptions ) }
|
2019-06-12 03:56:10 +00:00
|
|
|
options={ sellingVenueOptions }
|
|
|
|
value={ selling_venues }
|
2019-07-15 11:09:31 +00:00
|
|
|
help={ errors.selling_venues }
|
|
|
|
className={ errors.selling_venues ? 'has-error' : null }
|
2019-06-12 03:56:10 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
|
|
|
|
{ [ 'other', 'brick-mortar-other' ].includes( selling_venues ) && (
|
|
|
|
<SelectControl
|
|
|
|
label={ __( 'Which platform is the store using?', 'woocommerce-admin' ) }
|
2019-07-15 11:09:31 +00:00
|
|
|
onChange={ value => this.updateValue( 'other_platform', value ) }
|
2019-07-03 05:53:00 +00:00
|
|
|
onFocus={ this.setDefaultValue.bind( this, 'other_platform', otherPlatformOptions ) }
|
2019-06-12 03:56:10 +00:00
|
|
|
options={ otherPlatformOptions }
|
|
|
|
value={ other_platform }
|
2019-07-15 11:09:31 +00:00
|
|
|
help={ errors.other_platform }
|
|
|
|
className={ errors.other_platform ? 'has-error' : null }
|
2019-06-12 03:56:10 +00:00
|
|
|
required
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
|
2019-07-04 15:56:28 +00:00
|
|
|
{ showExtensions && this.renderBusinessExtensions() }
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
className="woocommerce-profile-wizard__continue"
|
|
|
|
onClick={ this.onContinue }
|
|
|
|
>
|
|
|
|
{ __( 'Continue', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Card>
|
2019-07-04 15:56:28 +00:00
|
|
|
|
|
|
|
{ showExtensions && this.renderBusinessExtensionHelpText() }
|
2019-06-12 03:56:10 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
|
|
|
const { getProfileItemsError } = select( 'wc-api' );
|
|
|
|
|
|
|
|
const isError = Boolean( getProfileItemsError() );
|
|
|
|
|
|
|
|
return { isError };
|
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-07-10 16:58:51 +00:00
|
|
|
const { addNotice, updateProfileItems } = dispatch( 'wc-api' );
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-10 16:58:51 +00:00
|
|
|
addNotice,
|
2019-06-12 03:56:10 +00:00
|
|
|
updateProfileItems,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( BusinessDetails );
|