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:
Justin Shreve 2019-08-01 13:29:35 -04:00 committed by GitHub
parent 307338a50f
commit 1410e7ed29
4 changed files with 49 additions and 10 deletions

View File

@ -3,7 +3,7 @@
* External dependencies * External dependencies
*/ */
import { __ } from '@wordpress/i18n'; 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 { Component, Fragment } from '@wordpress/element';
import { compose } from '@wordpress/compose'; import { compose } from '@wordpress/compose';
import { decodeEntities } from '@wordpress/html-entities'; import { decodeEntities } from '@wordpress/html-entities';
@ -30,6 +30,7 @@ class StoreDetails extends Component {
city: '', city: '',
countryState: '', countryState: '',
postCode: '', postCode: '',
isClient: false,
}, },
}; };
@ -85,11 +86,26 @@ class StoreDetails extends Component {
return; return;
} }
const { createNotice, goToNextStep, isError, updateSettings } = this.props; const {
const { addressLine1, addressLine2, city, countryState, postCode } = this.state.fields; createNotice,
goToNextStep,
isSettingsError,
updateSettings,
updateProfileItems,
isProfileItemsError,
} = this.props;
const {
addressLine1,
addressLine2,
city,
countryState,
postCode,
isClient,
} = this.state.fields;
recordEvent( 'storeprofiler_store_details_continue', { recordEvent( 'storeprofiler_store_details_continue', {
store_country: countryState.split( ':' )[ 0 ], store_country: countryState.split( ':' )[ 0 ],
setup_client: isClient,
} ); } );
await updateSettings( { await updateSettings( {
@ -102,7 +118,9 @@ class StoreDetails extends Component {
}, },
} ); } );
if ( ! isError ) { await updateProfileItems( { setup_client: isClient } );
if ( ! isSettingsError && ! isProfileItemsError ) {
goToNextStep(); goToNextStep();
} else { } else {
createNotice( createNotice(
@ -202,6 +220,11 @@ class StoreDetails extends Component {
className={ errors.postCode ? 'has-error' : null } 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 }> <Button isPrimary onClick={ this.onContinue }>
{ __( 'Continue', 'woocommerce-admin' ) } { __( 'Continue', 'woocommerce-admin' ) }
</Button> </Button>
@ -213,21 +236,25 @@ class StoreDetails extends Component {
export default compose( export default compose(
withSelect( select => { withSelect( select => {
const { getSettings, getSettingsError, isGetSettingsRequesting } = select( 'wc-api' ); const { getSettings, getSettingsError, isGetSettingsRequesting, getProfileItemsError } = select(
'wc-api'
);
const settings = getSettings( 'general' ); const settings = getSettings( 'general' );
const isError = Boolean( getSettingsError( 'general' ) ); const isSettingsError = Boolean( getSettingsError( 'general' ) );
const isRequesting = isGetSettingsRequesting( 'general' ); const isSettingsRequesting = isGetSettingsRequesting( 'general' );
const isProfileItemsError = Boolean( getProfileItemsError() );
return { getSettings, isError, isRequesting, settings }; return { getSettings, isProfileItemsError, isSettingsError, isSettingsRequesting, settings };
} ), } ),
withDispatch( dispatch => { withDispatch( dispatch => {
const { createNotice } = dispatch( 'core/notices' ); const { createNotice } = dispatch( 'core/notices' );
const { updateSettings } = dispatch( 'wc-api' ); const { updateSettings, updateProfileItems } = dispatch( 'wc-api' );
return { return {
createNotice, createNotice,
updateSettings, updateSettings,
updateProfileItems,
}; };
} ) } )
)( StoreDetails ); )( StoreDetails );

View File

@ -216,6 +216,10 @@
border-color: transparent; border-color: transparent;
} }
.muriel-checkbox label.components-checkbox-control__label {
margin-left: $gap-smaller;
}
.muriel-checkbox input[type='checkbox'] { .muriel-checkbox input[type='checkbox'] {
width: 18px; width: 18px;
height: 18px; height: 18px;

View File

@ -310,6 +310,13 @@ class WC_Admin_REST_Onboarding_Profile_Controller extends WC_REST_Data_Controlle
'readonly' => true, 'readonly' => true,
'validate_callback' => 'rest_validate_request_arg', '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 ); return apply_filters( 'woocommerce_onboarding_profile_properties', $properties );

View File

@ -97,7 +97,7 @@ class WC_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case {
$data = $response->get_data(); $data = $response->get_data();
$properties = $data['schema']['properties']; $properties = $data['schema']['properties'];
$this->assertCount( 11, $properties ); $this->assertCount( 12, $properties );
$this->assertArrayHasKey( 'completed', $properties ); $this->assertArrayHasKey( 'completed', $properties );
$this->assertArrayHasKey( 'skipped', $properties ); $this->assertArrayHasKey( 'skipped', $properties );
$this->assertArrayHasKey( 'account_type', $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( 'business_extensions', $properties );
$this->assertArrayHasKey( 'theme', $properties ); $this->assertArrayHasKey( 'theme', $properties );
$this->assertArrayHasKey( 'items_purchased', $properties ); $this->assertArrayHasKey( 'items_purchased', $properties );
$this->assertArrayHasKey( 'setup_client', $properties );
} }
/** /**