Add a "this store is being setup for a client" store detail field (https://github.com/woocommerce/woocommerce-admin/pull/2727)
This commit is contained in:
parent
307338a50f
commit
1410e7ed29
|
@ -3,7 +3,7 @@
|
|||
* External dependencies
|
||||
*/
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { Button, SelectControl, TextControl } from 'newspack-components';
|
||||
import { Button, SelectControl, TextControl, CheckboxControl } from 'newspack-components';
|
||||
import { Component, Fragment } from '@wordpress/element';
|
||||
import { compose } from '@wordpress/compose';
|
||||
import { decodeEntities } from '@wordpress/html-entities';
|
||||
|
@ -30,6 +30,7 @@ class StoreDetails extends Component {
|
|||
city: '',
|
||||
countryState: '',
|
||||
postCode: '',
|
||||
isClient: false,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -85,11 +86,26 @@ class StoreDetails extends Component {
|
|||
return;
|
||||
}
|
||||
|
||||
const { createNotice, goToNextStep, isError, updateSettings } = this.props;
|
||||
const { addressLine1, addressLine2, city, countryState, postCode } = this.state.fields;
|
||||
const {
|
||||
createNotice,
|
||||
goToNextStep,
|
||||
isSettingsError,
|
||||
updateSettings,
|
||||
updateProfileItems,
|
||||
isProfileItemsError,
|
||||
} = this.props;
|
||||
const {
|
||||
addressLine1,
|
||||
addressLine2,
|
||||
city,
|
||||
countryState,
|
||||
postCode,
|
||||
isClient,
|
||||
} = this.state.fields;
|
||||
|
||||
recordEvent( 'storeprofiler_store_details_continue', {
|
||||
store_country: countryState.split( ':' )[ 0 ],
|
||||
setup_client: isClient,
|
||||
} );
|
||||
|
||||
await updateSettings( {
|
||||
|
@ -102,7 +118,9 @@ class StoreDetails extends Component {
|
|||
},
|
||||
} );
|
||||
|
||||
if ( ! isError ) {
|
||||
await updateProfileItems( { setup_client: isClient } );
|
||||
|
||||
if ( ! isSettingsError && ! isProfileItemsError ) {
|
||||
goToNextStep();
|
||||
} else {
|
||||
createNotice(
|
||||
|
@ -202,6 +220,11 @@ class StoreDetails extends Component {
|
|||
className={ errors.postCode ? 'has-error' : null }
|
||||
/>
|
||||
|
||||
<CheckboxControl
|
||||
label={ __( 'This store is being set up for a client', 'woocommerce-admin' ) }
|
||||
onChange={ value => this.updateValue( 'isClient', value ) }
|
||||
/>
|
||||
|
||||
<Button isPrimary onClick={ this.onContinue }>
|
||||
{ __( 'Continue', 'woocommerce-admin' ) }
|
||||
</Button>
|
||||
|
@ -213,21 +236,25 @@ class StoreDetails extends Component {
|
|||
|
||||
export default compose(
|
||||
withSelect( select => {
|
||||
const { getSettings, getSettingsError, isGetSettingsRequesting } = select( 'wc-api' );
|
||||
const { getSettings, getSettingsError, isGetSettingsRequesting, getProfileItemsError } = select(
|
||||
'wc-api'
|
||||
);
|
||||
|
||||
const settings = getSettings( 'general' );
|
||||
const isError = Boolean( getSettingsError( 'general' ) );
|
||||
const isRequesting = isGetSettingsRequesting( 'general' );
|
||||
const isSettingsError = Boolean( getSettingsError( 'general' ) );
|
||||
const isSettingsRequesting = isGetSettingsRequesting( 'general' );
|
||||
const isProfileItemsError = Boolean( getProfileItemsError() );
|
||||
|
||||
return { getSettings, isError, isRequesting, settings };
|
||||
return { getSettings, isProfileItemsError, isSettingsError, isSettingsRequesting, settings };
|
||||
} ),
|
||||
withDispatch( dispatch => {
|
||||
const { createNotice } = dispatch( 'core/notices' );
|
||||
const { updateSettings } = dispatch( 'wc-api' );
|
||||
const { updateSettings, updateProfileItems } = dispatch( 'wc-api' );
|
||||
|
||||
return {
|
||||
createNotice,
|
||||
updateSettings,
|
||||
updateProfileItems,
|
||||
};
|
||||
} )
|
||||
)( StoreDetails );
|
||||
|
|
|
@ -216,6 +216,10 @@
|
|||
border-color: transparent;
|
||||
}
|
||||
|
||||
.muriel-checkbox label.components-checkbox-control__label {
|
||||
margin-left: $gap-smaller;
|
||||
}
|
||||
|
||||
.muriel-checkbox input[type='checkbox'] {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
|
|
|
@ -310,6 +310,13 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle
|
|||
'readonly' => true,
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
'setup_client' => array(
|
||||
'type' => 'boolean',
|
||||
'description' => __( 'Whether or not this store was setup for a client.', 'woocommerce-admin' ),
|
||||
'context' => array( 'view' ),
|
||||
'readonly' => true,
|
||||
'validate_callback' => 'rest_validate_request_arg',
|
||||
),
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_onboarding_profile_properties', $properties );
|
||||
|
|
|
@ -97,7 +97,7 @@ class WC_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
|
|||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
|
||||
$this->assertCount( 11, $properties );
|
||||
$this->assertCount( 12, $properties );
|
||||
$this->assertArrayHasKey( 'completed', $properties );
|
||||
$this->assertArrayHasKey( 'skipped', $properties );
|
||||
$this->assertArrayHasKey( 'account_type', $properties );
|
||||
|
@ -109,6 +109,7 @@ class WC_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
|
|||
$this->assertArrayHasKey( 'business_extensions', $properties );
|
||||
$this->assertArrayHasKey( 'theme', $properties );
|
||||
$this->assertArrayHasKey( 'items_purchased', $properties );
|
||||
$this->assertArrayHasKey( 'setup_client', $properties );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue