OBW: allow CBD only for US stores (https://github.com/woocommerce/woocommerce-admin/pull/4117)
* OBW: allow CBD only for US stores * fix if user goes back * industry.js feedback * store-details feedback * better naming
This commit is contained in:
parent
7f1481604c
commit
61f650a2a2
|
@ -12,11 +12,13 @@ import { withDispatch } from '@wordpress/data';
|
|||
* WooCommerce Dependencies
|
||||
*/
|
||||
import { getSetting } from '@woocommerce/wc-admin-settings';
|
||||
import { SETTINGS_STORE_NAME } from '@woocommerce/data';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import { H, Card, TextControl } from '@woocommerce/components';
|
||||
import { getCurrencyRegion } from 'dashboard/utils';
|
||||
import withSelect from 'wc-api/with-select';
|
||||
import { recordEvent } from 'lib/tracks';
|
||||
|
||||
|
@ -25,11 +27,38 @@ const onboarding = getSetting( 'onboarding', {} );
|
|||
class Industry extends Component {
|
||||
constructor( props ) {
|
||||
const profileItems = get( props, 'profileItems', {} );
|
||||
let selected = profileItems.industry || [];
|
||||
|
||||
/**
|
||||
* @todo Remove block on `updateProfileItems` refactor to wp.data dataStores.
|
||||
*
|
||||
* The following block is a side effect of wc-api not being truly async
|
||||
* and is a temporary fix until a refactor to wp.data can take place.
|
||||
*
|
||||
* Calls to `updateProfileItems` in the previous screen happen async
|
||||
* and won't be updated in wc-api's state when this component is initialized.
|
||||
* As such, we need to make sure cbd is not initialized as selected when a
|
||||
* user has changed location to non-US based.
|
||||
*/
|
||||
const { locationSettings } = props;
|
||||
const region = getCurrencyRegion(
|
||||
locationSettings.woocommerce_default_country
|
||||
);
|
||||
|
||||
if ( region !== 'US' ) {
|
||||
const cbdSlug = 'cbd-other-hemp-derived-products';
|
||||
selected = selected.filter( ( industry ) => {
|
||||
return cbdSlug !== industry && cbdSlug !== industry.slug;
|
||||
} );
|
||||
}
|
||||
/**
|
||||
* End block to be removed after refactor.
|
||||
*/
|
||||
|
||||
super();
|
||||
this.state = {
|
||||
error: null,
|
||||
selected: profileItems.industry || [],
|
||||
selected,
|
||||
textInputListContent: {},
|
||||
};
|
||||
this.onContinue = this.onContinue.bind( this );
|
||||
|
@ -130,6 +159,18 @@ class Industry extends Component {
|
|||
render() {
|
||||
const { industries } = onboarding;
|
||||
const { error, selected, textInputListContent } = this.state;
|
||||
const { locationSettings } = this.props;
|
||||
const region = getCurrencyRegion(
|
||||
locationSettings.woocommerce_default_country
|
||||
);
|
||||
const industryKeys = Object.keys( industries );
|
||||
|
||||
const filteredIndustryKeys =
|
||||
region === 'US'
|
||||
? industryKeys
|
||||
: industryKeys.filter(
|
||||
( slug ) => slug !== 'cbd-other-hemp-derived-products'
|
||||
);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
|
@ -144,7 +185,7 @@ class Industry extends Component {
|
|||
</p>
|
||||
<Card>
|
||||
<div className="woocommerce-profile-wizard__checkbox-group">
|
||||
{ Object.keys( industries ).map( ( slug ) => {
|
||||
{ filteredIndustryKeys.map( ( slug ) => {
|
||||
const selectedIndustry = find( selected, { slug } );
|
||||
|
||||
return (
|
||||
|
@ -209,10 +250,13 @@ class Industry extends Component {
|
|||
export default compose(
|
||||
withSelect( ( select ) => {
|
||||
const { getProfileItems, getProfileItemsError } = select( 'wc-api' );
|
||||
const { getSettings } = select( SETTINGS_STORE_NAME );
|
||||
const { general: locationSettings = {} } = getSettings( 'general' );
|
||||
|
||||
return {
|
||||
isError: Boolean( getProfileItemsError() ),
|
||||
profileItems: getProfileItems(),
|
||||
locationSettings,
|
||||
};
|
||||
} ),
|
||||
withDispatch( ( dispatch ) => {
|
||||
|
|
|
@ -86,6 +86,7 @@ class StoreDetails extends Component {
|
|||
updateProfileItems,
|
||||
isProfileItemsError,
|
||||
updateAndPersistSettingsForGroup,
|
||||
profileItems,
|
||||
} = this.props;
|
||||
|
||||
const currencySettings = this.deriveCurrencySettings(
|
||||
|
@ -117,7 +118,30 @@ class StoreDetails extends Component {
|
|||
},
|
||||
} );
|
||||
|
||||
await updateProfileItems( { setup_client: values.isClient } );
|
||||
const profileItemsToUpdate = { setup_client: values.isClient };
|
||||
const region = getCurrencyRegion( values.countryState );
|
||||
|
||||
/**
|
||||
* If a user has already selected cdb industry and returns to change to a
|
||||
* non US store, remove cbd industry.
|
||||
*
|
||||
* NOTE: the following call to `updateProfileItems` does not respect the
|
||||
* `await` and performs an update aysnchronously. This means the following
|
||||
* screen may not be initialized with correct profile settings.
|
||||
*
|
||||
* This comment may be removed when a refactor to wp.data datatores is complete.
|
||||
*/
|
||||
if ( region !== 'US' ) {
|
||||
const cbdSlug = 'cbd-other-hemp-derived-products';
|
||||
const trimmedIndustries = profileItems.industry.filter(
|
||||
( industry ) => {
|
||||
return cbdSlug !== industry && cbdSlug !== industry.slug;
|
||||
}
|
||||
);
|
||||
profileItemsToUpdate.industry = trimmedIndustries;
|
||||
}
|
||||
|
||||
await updateProfileItems( profileItemsToUpdate );
|
||||
|
||||
if ( ! isSettingsError && ! isProfileItemsError ) {
|
||||
goToNextStep();
|
||||
|
|
Loading…
Reference in New Issue