2019-05-28 14:05:55 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-05-30 06:31:07 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-05-28 14:05:55 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
2019-12-02 17:39:22 +00:00
|
|
|
import { Button, CheckboxControl } from '@wordpress/components';
|
2019-05-30 06:31:07 +00:00
|
|
|
import { compose } from '@wordpress/compose';
|
2019-11-05 00:05:20 +00:00
|
|
|
import { filter, get, includes } from 'lodash';
|
2019-05-30 06:31:07 +00:00
|
|
|
import { withDispatch } from '@wordpress/data';
|
|
|
|
|
2019-09-23 21:47:08 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce Dependencies
|
|
|
|
*/
|
|
|
|
import { getSetting } from '@woocommerce/wc-admin-settings';
|
|
|
|
|
2019-05-30 06:31:07 +00:00
|
|
|
/**
|
|
|
|
* 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-05-28 14:05:55 +00:00
|
|
|
|
2019-09-23 21:47:08 +00:00
|
|
|
const onboarding = getSetting( 'onboarding', {} );
|
|
|
|
|
2019-05-28 14:05:55 +00:00
|
|
|
class Industry extends Component {
|
2019-11-05 00:05:20 +00:00
|
|
|
constructor( props ) {
|
|
|
|
const profileItems = get( props, 'profileItems', {} );
|
|
|
|
|
2019-05-28 14:05:55 +00:00
|
|
|
super();
|
|
|
|
this.state = {
|
2019-07-15 11:09:31 +00:00
|
|
|
error: null,
|
2019-11-05 00:05:20 +00:00
|
|
|
selected: profileItems.industry || [],
|
2019-05-28 14:05:55 +00:00
|
|
|
};
|
2019-05-30 06:31:07 +00:00
|
|
|
this.onContinue = this.onContinue.bind( this );
|
|
|
|
this.onChange = this.onChange.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
async onContinue() {
|
2019-07-15 11:09:31 +00:00
|
|
|
await this.validateField();
|
|
|
|
if ( this.state.error ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
goToNextStep,
|
|
|
|
isError,
|
|
|
|
updateProfileItems,
|
|
|
|
} = this.props;
|
2019-05-30 06:31:07 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
recordEvent( 'storeprofiler_store_industry_continue', {
|
|
|
|
store_industry: this.state.selected,
|
|
|
|
} );
|
2019-05-30 06:31:07 +00:00
|
|
|
await updateProfileItems( { industry: this.state.selected } );
|
|
|
|
|
|
|
|
if ( ! isError ) {
|
|
|
|
goToNextStep();
|
|
|
|
} else {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice(
|
|
|
|
'error',
|
2020-02-14 02:23:21 +00:00
|
|
|
__(
|
|
|
|
'There was a problem updating your industries.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
)
|
2019-07-23 03:26:46 +00:00
|
|
|
);
|
2019-05-30 06:31:07 +00:00
|
|
|
}
|
2019-05-28 14:05:55 +00:00
|
|
|
}
|
2019-05-30 06:31:07 +00:00
|
|
|
|
2019-07-15 11:09:31 +00:00
|
|
|
async validateField() {
|
|
|
|
const error = this.state.selected.length
|
|
|
|
? null
|
|
|
|
: __( 'Please select at least one industry', 'woocommerce-admin' );
|
|
|
|
this.setState( { error } );
|
|
|
|
}
|
|
|
|
|
2019-05-30 06:31:07 +00:00
|
|
|
onChange( slug ) {
|
2019-07-15 11:09:31 +00:00
|
|
|
this.setState(
|
2020-02-14 02:23:21 +00:00
|
|
|
( state ) => {
|
2019-07-15 11:09:31 +00:00
|
|
|
if ( includes( state.selected, slug ) ) {
|
|
|
|
return {
|
|
|
|
selected:
|
2020-02-14 02:23:21 +00:00
|
|
|
filter( state.selected, ( value ) => {
|
2019-07-15 11:09:31 +00:00
|
|
|
return value !== slug;
|
|
|
|
} ) || [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const newSelected = state.selected;
|
|
|
|
newSelected.push( slug );
|
2019-05-30 06:31:07 +00:00
|
|
|
return {
|
2019-07-15 11:09:31 +00:00
|
|
|
selected: newSelected,
|
2019-05-30 06:31:07 +00:00
|
|
|
};
|
2019-07-15 11:09:31 +00:00
|
|
|
},
|
|
|
|
() => this.validateField()
|
|
|
|
);
|
2019-05-30 06:31:07 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 14:05:55 +00:00
|
|
|
render() {
|
2019-09-23 21:47:08 +00:00
|
|
|
const { industries } = onboarding;
|
2019-10-04 13:46:27 +00:00
|
|
|
const { error, selected } = this.state;
|
2019-11-05 00:05:20 +00:00
|
|
|
|
2019-05-28 14:05:55 +00:00
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-05-30 06:31:07 +00:00
|
|
|
<H className="woocommerce-profile-wizard__header-title">
|
2020-02-14 02:23:21 +00:00
|
|
|
{ __(
|
|
|
|
'In which industry does the store operate?',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
2019-05-30 06:31:07 +00:00
|
|
|
</H>
|
2019-07-10 23:19:32 +00:00
|
|
|
<p className="woocommerce-profile-wizard__intro-paragraph">
|
|
|
|
{ __( 'Choose any that apply' ) }
|
|
|
|
</p>
|
2019-11-04 00:23:26 +00:00
|
|
|
<Card>
|
2019-05-30 06:31:07 +00:00
|
|
|
<div className="woocommerce-profile-wizard__checkbox-group">
|
2020-02-14 02:23:21 +00:00
|
|
|
{ Object.keys( industries ).map( ( slug ) => {
|
2019-05-30 06:31:07 +00:00
|
|
|
return (
|
|
|
|
<CheckboxControl
|
|
|
|
key={ slug }
|
|
|
|
label={ industries[ slug ] }
|
|
|
|
onChange={ () => this.onChange( slug ) }
|
2019-11-05 00:05:20 +00:00
|
|
|
checked={ selected.includes( slug ) }
|
2019-12-02 17:39:22 +00:00
|
|
|
className="woocommerce-profile-wizard__checkbox"
|
2019-05-30 06:31:07 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
2020-02-14 02:23:21 +00:00
|
|
|
{ error && (
|
|
|
|
<span className="woocommerce-profile-wizard__error">
|
|
|
|
{ error }
|
|
|
|
</span>
|
|
|
|
) }
|
2019-05-30 06:31:07 +00:00
|
|
|
</div>
|
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
<Button
|
|
|
|
isPrimary
|
|
|
|
onClick={ this.onContinue }
|
|
|
|
disabled={ ! selected.length }
|
|
|
|
>
|
2019-07-15 11:09:31 +00:00
|
|
|
{ __( 'Continue', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
2019-05-30 06:31:07 +00:00
|
|
|
</Card>
|
2019-05-28 14:05:55 +00:00
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-30 06:31:07 +00:00
|
|
|
export default compose(
|
2020-02-14 02:23:21 +00:00
|
|
|
withSelect( ( select ) => {
|
2019-11-05 00:05:20 +00:00
|
|
|
const { getProfileItems, getProfileItemsError } = select( 'wc-api' );
|
2019-05-30 06:31:07 +00:00
|
|
|
|
2019-11-05 00:05:20 +00:00
|
|
|
return {
|
|
|
|
isError: Boolean( getProfileItemsError() ),
|
|
|
|
profileItems: getProfileItems(),
|
|
|
|
};
|
2019-05-30 06:31:07 +00:00
|
|
|
} ),
|
2020-02-14 02:23:21 +00:00
|
|
|
withDispatch( ( dispatch ) => {
|
2019-07-23 03:26:46 +00:00
|
|
|
const { updateProfileItems } = dispatch( 'wc-api' );
|
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
2019-05-30 06:31:07 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-23 03:26:46 +00:00
|
|
|
createNotice,
|
2019-05-30 06:31:07 +00:00
|
|
|
updateProfileItems,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Industry );
|