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-07-17 18:46:55 +00:00
|
|
|
import { Button } from 'newspack-components';
|
2019-06-12 03:56:10 +00:00
|
|
|
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';
|
2019-09-23 21:47:08 +00:00
|
|
|
import { getSetting, CURRENCY as currency } from '@woocommerce/wc-admin-settings';
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2019-08-08 05:25:55 +00:00
|
|
|
import { H, Card, SimpleSelectControl, Form } from '@woocommerce/components';
|
2019-06-12 03:56:10 +00:00
|
|
|
import withSelect from 'wc-api/with-select';
|
2019-07-01 18:13:29 +00:00
|
|
|
import { recordEvent } from 'lib/tracks';
|
2019-08-08 15:38:47 +00:00
|
|
|
import { formatCurrency } from '@woocommerce/currency';
|
2019-06-12 03:56:10 +00:00
|
|
|
|
2019-09-23 21:47:08 +00:00
|
|
|
const wcAdminAssetUrl = getSetting( 'wcAdminAssetUrl', '' );
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
class BusinessDetails extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
this.initialValues = {
|
|
|
|
other_platform: '',
|
|
|
|
product_count: '',
|
|
|
|
selling_venues: '',
|
2019-08-08 15:38:47 +00:00
|
|
|
revenue: '',
|
2019-08-08 05:25:55 +00:00
|
|
|
facebook: true,
|
|
|
|
mailchimp: true,
|
2019-06-12 03:56:10 +00:00
|
|
|
};
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
this.extensions = [ 'facebook', 'mailchimp' ];
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
this.onContinue = this.onContinue.bind( this );
|
2019-08-08 05:25:55 +00:00
|
|
|
this.validate = this.validate.bind( this );
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
async onContinue( values ) {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { createNotice, goToNextStep, isError, updateProfileItems } = this.props;
|
2019-08-08 15:38:47 +00:00
|
|
|
const { facebook, mailchimp, other_platform, product_count, revenue, selling_venues } = values;
|
2019-08-08 05:25:55 +00:00
|
|
|
const businessExtensions = this.getBusinessExtensions( values );
|
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,
|
2019-09-23 21:47:08 +00:00
|
|
|
currency: currency.code,
|
2019-08-08 15:38:47 +00:00
|
|
|
revenue,
|
2019-07-01 18:13:29 +00:00
|
|
|
used_platform: other_platform,
|
2019-08-08 05:25:55 +00:00
|
|
|
install_facebook: facebook,
|
|
|
|
install_mailchimp: mailchimp,
|
2019-07-01 18:13:29 +00:00
|
|
|
} );
|
|
|
|
|
2019-08-08 15:38:47 +00:00
|
|
|
const _updates = {
|
2019-07-04 15:56:28 +00:00
|
|
|
other_platform,
|
|
|
|
product_count,
|
2019-08-08 15:38:47 +00:00
|
|
|
revenue,
|
2019-07-04 15:56:28 +00:00
|
|
|
selling_venues,
|
2019-07-15 11:09:31 +00:00
|
|
|
business_extensions: businessExtensions,
|
2019-08-08 15:38:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Remove possible empty values like `revenue` and `other_platform`.
|
|
|
|
const updates = {};
|
|
|
|
Object.keys( _updates ).forEach( key => {
|
|
|
|
if ( _updates[ key ] !== '' ) {
|
|
|
|
updates[ key ] = _updates[ key ];
|
|
|
|
}
|
2019-07-04 15:56:28 +00:00
|
|
|
} );
|
2019-06-12 03:56:10 +00:00
|
|
|
|
2019-08-08 15:38:47 +00:00
|
|
|
await updateProfileItems( updates );
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
if ( ! isError ) {
|
|
|
|
goToNextStep();
|
|
|
|
} else {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__( 'There was a problem updating your business details.', 'woocommerce-admin' )
|
|
|
|
);
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
validate( values ) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
Object.keys( values ).map( name => {
|
|
|
|
if ( 'other_platform' === name ) {
|
|
|
|
if (
|
|
|
|
! values.other_platform.length &&
|
|
|
|
[ 'other', 'brick-mortar-other' ].includes( values.selling_venues )
|
|
|
|
) {
|
|
|
|
errors.other_platform = __( 'This field is required', 'woocommerce-admin' );
|
|
|
|
}
|
2019-08-08 15:38:47 +00:00
|
|
|
} else if ( 'revenue' === name ) {
|
|
|
|
if (
|
|
|
|
! values.revenue.length &&
|
|
|
|
[ 'other', 'brick-mortar', 'brick-mortar-other' ].includes( values.selling_venues )
|
|
|
|
) {
|
|
|
|
errors.revenue = __( 'This field is required', 'woocommerce-admin' );
|
|
|
|
}
|
2019-08-08 05:25:55 +00:00
|
|
|
} else if ( ! this.extensions.includes( name ) && ! values[ name ].length ) {
|
|
|
|
errors[ name ] = __( 'This field is required', 'woocommerce-admin' );
|
|
|
|
}
|
|
|
|
} );
|
2019-07-15 11:09:31 +00:00
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
return errors;
|
2019-07-15 11:09:31 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
getBusinessExtensions( values ) {
|
|
|
|
return keys( pickBy( values ) ).filter( name => this.extensions.includes( name ) );
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
|
2019-08-08 15:38:47 +00:00
|
|
|
getNumberRangeString( min, max = false, format = numberFormat ) {
|
2019-06-12 03:56:10 +00:00
|
|
|
if ( ! max ) {
|
2019-08-08 15:38:47 +00:00
|
|
|
return sprintf( _x( '%s+', 'store product count', 'woocommerce-admin' ), format( min ) );
|
2019-06-12 03:56:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(
|
|
|
|
_x( '%s - %s', 'store product count', 'woocommerce-admin' ),
|
2019-08-08 15:38:47 +00:00
|
|
|
format( min ),
|
|
|
|
format( max )
|
2019-06-12 03:56:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
renderBusinessExtensionHelpText( values ) {
|
|
|
|
const extensions = this.getBusinessExtensions( values );
|
2019-07-04 15:56:28 +00:00
|
|
|
const extensionSlugs = {
|
|
|
|
facebook: __( 'Facebook for WooCommerce', 'woocommerce-admin' ),
|
|
|
|
mailchimp: __( 'Mailchimp for WooCommerce', 'woocommerce-admin' ),
|
|
|
|
};
|
|
|
|
|
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
renderBusinessExtensions( values, getInputProps ) {
|
2019-07-04 15:56:28 +00:00
|
|
|
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'
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
2019-08-08 05:25:55 +00:00
|
|
|
|
2019-07-04 15:56:28 +00:00
|
|
|
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">
|
2019-09-23 21:47:08 +00:00
|
|
|
<img src={ wcAdminAssetUrl + benefit.icon } alt="" />
|
2019-07-04 15:56:28 +00:00
|
|
|
</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">
|
2019-09-03 17:08:02 +00:00
|
|
|
<FormToggle checked={ values[ benefit.slug ] } { ...getInputProps( benefit.slug ) } />
|
2019-07-04 15:56:28 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) ) }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
render() {
|
|
|
|
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 ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-08-08 15:38:47 +00:00
|
|
|
const revenueOptions = [
|
|
|
|
{
|
|
|
|
value: 'none',
|
|
|
|
label: sprintf(
|
|
|
|
_x( "%s (I'm just getting started)", '$0 revenue amount', 'woocommerce-admin' ),
|
|
|
|
formatCurrency( 0 )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'up-to-2500',
|
|
|
|
label: sprintf(
|
|
|
|
_x( 'Up to %s', 'Up to a certain revenue amount', 'woocommerce-admin' ),
|
|
|
|
formatCurrency( 2500 )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '2500-10000',
|
|
|
|
label: this.getNumberRangeString( 2500, 10000, formatCurrency ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '10000-50000',
|
|
|
|
label: this.getNumberRangeString( 10000, 50000, formatCurrency ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: '50000-250000',
|
|
|
|
label: this.getNumberRangeString( 50000, 250000, formatCurrency ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'more-than-250000',
|
|
|
|
label: sprintf(
|
|
|
|
_x( 'More than %s', 'More than a certain revenue amount', 'woocommerce-admin' ),
|
|
|
|
formatCurrency( 250000 )
|
|
|
|
),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2019-06-12 03:56:10 +00:00
|
|
|
const sellingVenueOptions = [
|
|
|
|
{
|
|
|
|
value: 'no',
|
|
|
|
label: __( 'No', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'other',
|
|
|
|
label: __( 'Yes, on another platform', 'woocommerce-admin' ),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'brick-mortar',
|
2019-08-08 18:41:26 +00:00
|
|
|
label: __( 'Yes, in person at physical stores and/or events', 'woocommerce-admin' ),
|
2019-06-12 03:56:10 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 'brick-mortar-other',
|
|
|
|
label: __(
|
2019-08-08 18:41:26 +00:00
|
|
|
'Yes, on another platform and in person at physical stores and/or events',
|
2019-06-12 03:56:10 +00:00
|
|
|
'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' ),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
return (
|
2019-08-08 05:25:55 +00:00
|
|
|
<Form
|
|
|
|
initialValues={ this.initialValues }
|
|
|
|
onSubmitCallback={ this.onContinue }
|
|
|
|
validate={ this.validate }
|
|
|
|
>
|
2019-10-04 13:46:27 +00:00
|
|
|
{ ( { getInputProps, handleSubmit, values, isValidForm } ) => {
|
2019-08-08 05:25:55 +00:00
|
|
|
// Show extensions when the currently selling elsewhere checkbox has been answered.
|
|
|
|
const showExtensions = '' !== values.selling_venues;
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<H className="woocommerce-profile-wizard__header-title">
|
2019-08-08 18:41:26 +00:00
|
|
|
{ __( 'Tell us about your business', 'woocommerce-admin' ) }
|
2019-08-08 05:25:55 +00:00
|
|
|
</H>
|
2019-08-08 18:41:26 +00:00
|
|
|
<p>
|
|
|
|
{ __(
|
|
|
|
"We'd love to know if you are just getting started or you already have a business in place.",
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</p>
|
2019-08-08 05:25:55 +00:00
|
|
|
<Card>
|
|
|
|
<Fragment>
|
|
|
|
<SimpleSelectControl
|
2019-08-08 18:41:26 +00:00
|
|
|
label={ __( 'How many products do you plan to add?', 'woocommerce-admin' ) }
|
2019-08-08 05:25:55 +00:00
|
|
|
options={ productCountOptions }
|
|
|
|
required
|
|
|
|
{ ...getInputProps( 'product_count' ) }
|
|
|
|
/>
|
|
|
|
|
|
|
|
<SimpleSelectControl
|
|
|
|
label={ __( 'Currently selling elsewhere?', 'woocommerce-admin' ) }
|
|
|
|
options={ sellingVenueOptions }
|
|
|
|
required
|
|
|
|
{ ...getInputProps( 'selling_venues' ) }
|
|
|
|
/>
|
|
|
|
|
2019-08-08 15:38:47 +00:00
|
|
|
{ [ 'other', 'brick-mortar', 'brick-mortar-other' ].includes(
|
|
|
|
values.selling_venues
|
|
|
|
) && (
|
|
|
|
<SimpleSelectControl
|
|
|
|
label={ __( "What's your current annual revenue?", 'woocommerce-admin' ) }
|
|
|
|
options={ revenueOptions }
|
|
|
|
required
|
|
|
|
{ ...getInputProps( 'revenue' ) }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
|
2019-08-08 05:25:55 +00:00
|
|
|
{ [ 'other', 'brick-mortar-other' ].includes( values.selling_venues ) && (
|
|
|
|
<SimpleSelectControl
|
|
|
|
label={ __( 'Which platform is the store using?', 'woocommerce-admin' ) }
|
|
|
|
options={ otherPlatformOptions }
|
|
|
|
required
|
|
|
|
{ ...getInputProps( 'other_platform' ) }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
|
|
|
|
{ showExtensions && this.renderBusinessExtensions( values, getInputProps ) }
|
|
|
|
|
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
className="woocommerce-profile-wizard__continue"
|
|
|
|
onClick={ handleSubmit }
|
2019-10-04 13:46:27 +00:00
|
|
|
disabled={ ! isValidForm }
|
2019-08-08 05:25:55 +00:00
|
|
|
>
|
|
|
|
{ __( 'Continue', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
{ showExtensions && this.renderBusinessExtensionHelpText( values ) }
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
} }
|
|
|
|
</Form>
|
2019-06-12 03:56:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default compose(
|
|
|
|
withSelect( select => {
|
|
|
|
const { getProfileItemsError } = select( 'wc-api' );
|
|
|
|
|
|
|
|
const isError = Boolean( getProfileItemsError() );
|
|
|
|
|
|
|
|
return { isError };
|
|
|
|
} ),
|
|
|
|
withDispatch( dispatch => {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { updateProfileItems } = dispatch( 'wc-api' );
|
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-06-12 03:56:10 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2019-06-12 03:56:10 +00:00
|
|
|
updateProfileItems,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( BusinessDetails );
|