From 1410e7ed29f8bee6c3ca41d9232c6d9919c78dfc Mon Sep 17 00:00:00 2001 From: Justin Shreve Date: Thu, 1 Aug 2019 13:29:35 -0400 Subject: [PATCH] Add a "this store is being setup for a client" store detail field (https://github.com/woocommerce/woocommerce-admin/pull/2727) --- .../profile-wizard/steps/store-details.js | 45 +++++++++++++++---- .../dashboard/profile-wizard/style.scss | 4 ++ ...min-rest-onboarding-profile-controller.php | 7 +++ .../tests/api/onboarding-profile.php | 3 +- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/store-details.js b/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/store-details.js index a5c1a1c64c9..0659893da83 100644 --- a/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/store-details.js +++ b/plugins/woocommerce-admin/client/dashboard/profile-wizard/steps/store-details.js @@ -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 } /> + this.updateValue( 'isClient', value ) } + /> + @@ -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 ); diff --git a/plugins/woocommerce-admin/client/dashboard/profile-wizard/style.scss b/plugins/woocommerce-admin/client/dashboard/profile-wizard/style.scss index fe1dcbce1c7..d3b5612c3c4 100644 --- a/plugins/woocommerce-admin/client/dashboard/profile-wizard/style.scss +++ b/plugins/woocommerce-admin/client/dashboard/profile-wizard/style.scss @@ -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; diff --git a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php index 2754b61e7b3..9b48a8bfb57 100644 --- a/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php +++ b/plugins/woocommerce-admin/includes/api/class-wc-admin-rest-onboarding-profile-controller.php @@ -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 ); diff --git a/plugins/woocommerce-admin/tests/api/onboarding-profile.php b/plugins/woocommerce-admin/tests/api/onboarding-profile.php index f103b6cd956..45e572fae19 100644 --- a/plugins/woocommerce-admin/tests/api/onboarding-profile.php +++ b/plugins/woocommerce-admin/tests/api/onboarding-profile.php @@ -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 ); } /**