2019-05-28 14:05:55 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* 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-05-30 06:31:07 +00:00
|
|
|
import { Button, CheckboxControl } from 'newspack-components';
|
|
|
|
import { includes, filter } from 'lodash';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import { withDispatch } from '@wordpress/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
class Industry extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.state = {
|
2019-05-30 06:31:07 +00:00
|
|
|
selected: [],
|
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-10 16:58:51 +00:00
|
|
|
const { addNotice, goToNextStep, isError, updateProfileItems } = this.props;
|
2019-05-30 06:31:07 +00:00
|
|
|
|
2019-07-01 18:13:29 +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-10 16:58:51 +00:00
|
|
|
addNotice( {
|
|
|
|
status: 'error',
|
|
|
|
message: __( 'There was a problem updating your industries.', 'woocommerce-admin' ),
|
|
|
|
} );
|
2019-05-30 06:31:07 +00:00
|
|
|
}
|
2019-05-28 14:05:55 +00:00
|
|
|
}
|
2019-05-30 06:31:07 +00:00
|
|
|
|
|
|
|
onChange( slug ) {
|
|
|
|
this.setState( state => {
|
|
|
|
if ( includes( state.selected, slug ) ) {
|
|
|
|
return {
|
|
|
|
selected:
|
|
|
|
filter( state.selected, value => {
|
|
|
|
return value !== slug;
|
|
|
|
} ) || [],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
const newSelected = state.selected;
|
|
|
|
newSelected.push( slug );
|
|
|
|
return {
|
|
|
|
selected: newSelected,
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:05:55 +00:00
|
|
|
render() {
|
2019-05-30 06:31:07 +00:00
|
|
|
const { industries } = wcSettings.onboarding;
|
|
|
|
const { selected } = this.state;
|
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">
|
|
|
|
{ __( 'In which industry does the store operate?', 'woocommerce-admin' ) }
|
|
|
|
</H>
|
2019-07-10 23:19:32 +00:00
|
|
|
<p className="woocommerce-profile-wizard__intro-paragraph">
|
|
|
|
{ __( 'Choose any that apply' ) }
|
|
|
|
</p>
|
2019-05-30 06:31:07 +00:00
|
|
|
<Card className="woocommerce-profile-wizard__industry-card">
|
|
|
|
<div className="woocommerce-profile-wizard__checkbox-group">
|
|
|
|
{ Object.keys( industries ).map( slug => {
|
|
|
|
return (
|
|
|
|
<CheckboxControl
|
|
|
|
key={ slug }
|
|
|
|
label={ industries[ slug ] }
|
|
|
|
onChange={ () => this.onChange( slug ) }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</div>
|
|
|
|
|
2019-05-30 08:36:02 +00:00
|
|
|
{ selected.length > 0 && (
|
|
|
|
<Button isPrimary onClick={ this.onContinue }>
|
|
|
|
{ __( '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(
|
|
|
|
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-05-30 06:31:07 +00:00
|
|
|
|
|
|
|
return {
|
2019-07-10 16:58:51 +00:00
|
|
|
addNotice,
|
2019-05-30 06:31:07 +00:00
|
|
|
updateProfileItems,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( Industry );
|