From a90e9de61a4f6f518a32037ea3637ecce8af3e22 Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 29 Nov 2021 17:00:38 -0300 Subject: [PATCH] OBW - Add number of employees field (https://github.com/woocommerce/woocommerce-admin/pull/7963) * Add number of employees field * Fix "reduce - spread" anti-pattern This commit fixes the "reduce - spread" anti-pattern https://www.richsnapp.com/article/2019/06-09-reduce-spread-anti-pattern * Add changelog Co-authored-by: Fernando Marichal --- plugins/woocommerce-admin/changelogs/add-7854 | 4 ++ .../business-details/data/employee-options.js | 31 +++++++++++++ .../flows/selective-bundle/index.js | 45 +++++++++++++++++-- .../steps/business-details/index.js | 1 + .../packages/data/src/onboarding/reducer.js | 1 + .../packages/data/src/onboarding/selectors.ts | 1 + .../src/API/OnboardingProfile.php | 15 +++++++ .../src/Features/Onboarding.php | 1 + .../tests/api/onboarding-profile.php | 3 +- 9 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 plugins/woocommerce-admin/changelogs/add-7854 create mode 100644 plugins/woocommerce-admin/client/profile-wizard/steps/business-details/data/employee-options.js diff --git a/plugins/woocommerce-admin/changelogs/add-7854 b/plugins/woocommerce-admin/changelogs/add-7854 new file mode 100644 index 00000000000..803c1c83c89 --- /dev/null +++ b/plugins/woocommerce-admin/changelogs/add-7854 @@ -0,0 +1,4 @@ +Significance: minor +Type: Add + +OBW - Add number of employees field #7963 diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/data/employee-options.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/data/employee-options.js new file mode 100644 index 00000000000..ccef301b928 --- /dev/null +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/data/employee-options.js @@ -0,0 +1,31 @@ +/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; + +export const employeeOptions = [ + { + key: '1', + label: __( "It's just me", 'woocommerce-admin' ), + }, + { + key: '<10', + label: __( '< 10', 'woocommerce-admin' ), + }, + { + key: '10-50', + label: '10 - 50', + }, + { + key: '50-250', + label: '50 - 250', + }, + { + key: '+250', + label: __( '+250', 'woocommerce-admin' ), + }, + { + key: 'not specified', + label: __( "I'd rather not say", 'woocommerce-admin' ), + }, +]; diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js index e62d136e188..2612782a8fe 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/flows/selective-bundle/index.js @@ -29,6 +29,7 @@ import { recordEvent } from '@woocommerce/tracks'; import { CurrencyContext } from '~/lib/currency-context'; import { createNoticesFromResponse } from '~/lib/notices'; import { platformOptions } from '../../data/platform-options'; +import { employeeOptions } from '../../data/employee-options'; import { sellingVenueOptions } from '../../data/selling-venue-options'; import { getRevenueOptions } from '../../data/revenue-options'; import { getProductCountOptions } from '../../data/product-options'; @@ -154,6 +155,7 @@ class BusinessDetails extends Component { const { updateProfileItems, createNotice } = this.props; const { + number_employees: numberEmployees, other_platform: otherPlatform, other_platform_name: otherPlatformName, product_count: productCount, @@ -163,6 +165,7 @@ class BusinessDetails extends Component { } = this.state.savedValues; const updates = { + number_employees: numberEmployees, other_platform: otherPlatform, other_platform_name: otherPlatform === 'other' ? otherPlatformName : '', @@ -177,10 +180,7 @@ class BusinessDetails extends Component { const finalUpdates = Object.entries( updates ).reduce( ( acc, [ key, val ] ) => { if ( val !== '' ) { - return { - ...acc, - [ key ]: val, - }; + acc[ key ] = val; } return acc; @@ -237,6 +237,21 @@ class BusinessDetails extends Component { ); } + if ( + ! values.number_employees.length && + [ + 'other', + 'brick-mortar', + 'brick-mortar-other', + 'other-woocommerce', + ].includes( values.selling_venues ) + ) { + errors.number_employees = __( + 'This field is required', + 'woocommerce-admin' + ); + } + if ( ! values.revenue.length && [ @@ -260,6 +275,7 @@ class BusinessDetails extends Component { } trackBusinessDetailsStep( { + number_employees: numberEmployees, other_platform: otherPlatform, other_platform_name: otherPlatformName, product_count: productCount, @@ -270,6 +286,7 @@ class BusinessDetails extends Component { const { getCurrencyConfig } = this.context; recordEvent( 'storeprofiler_store_business_details_continue_variant', { + number_employees: numberEmployees, already_selling: sellingVenues, currency: getCurrencyConfig().code, product_number: productCount, @@ -357,6 +374,26 @@ class BusinessDetails extends Component { { ...getInputProps( 'selling_venues' ) } /> + { [ + 'other', + 'brick-mortar', + 'brick-mortar-other', + 'other-woocommerce', + ].includes( values.selling_venues ) && ( + + ) } + { [ 'other', 'brick-mortar', diff --git a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/index.js b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/index.js index ec32a8c320d..dd4a640caad 100644 --- a/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/index.js +++ b/plugins/woocommerce-admin/client/profile-wizard/steps/business-details/index.js @@ -34,6 +34,7 @@ export const BusinessDetailsStep = ( props ) => { } const initialValues = { + number_employees: profileItems.number_employees || '', other_platform: profileItems.other_platform || '', other_platform_name: profileItems.other_platform_name || '', product_count: profileItems.product_count || '', diff --git a/plugins/woocommerce-admin/packages/data/src/onboarding/reducer.js b/plugins/woocommerce-admin/packages/data/src/onboarding/reducer.js index 848166dded4..77ab0d4401b 100644 --- a/plugins/woocommerce-admin/packages/data/src/onboarding/reducer.js +++ b/plugins/woocommerce-admin/packages/data/src/onboarding/reducer.js @@ -10,6 +10,7 @@ export const defaultState = { business_extensions: null, completed: null, industry: null, + number_employees: null, other_platform: null, other_platform_name: null, product_count: null, diff --git a/plugins/woocommerce-admin/packages/data/src/onboarding/selectors.ts b/plugins/woocommerce-admin/packages/data/src/onboarding/selectors.ts index b231ce0a785..d916a04206d 100644 --- a/plugins/woocommerce-admin/packages/data/src/onboarding/selectors.ts +++ b/plugins/woocommerce-admin/packages/data/src/onboarding/selectors.ts @@ -130,6 +130,7 @@ export type ProfileItemsState = { business_extensions: [ ] | null; completed: boolean | null; industry: Industry[] | null; + number_employees: string | null; other_platform: OtherPlatformSlug | null; other_platform_name: string | null; product_count: ProductCount | null; diff --git a/plugins/woocommerce-admin/src/API/OnboardingProfile.php b/plugins/woocommerce-admin/src/API/OnboardingProfile.php index 8fbec3d545b..c9346f76ea3 100644 --- a/plugins/woocommerce-admin/src/API/OnboardingProfile.php +++ b/plugins/woocommerce-admin/src/API/OnboardingProfile.php @@ -323,6 +323,21 @@ class OnboardingProfile extends \WC_REST_Data_Controller { 'other-woocommerce', ), ), + 'number_employees' => array( + 'type' => 'string', + 'description' => __( 'Number of employees of the store.', 'woocommerce-admin' ), + 'context' => array( 'view' ), + 'readonly' => true, + 'validate_callback' => 'rest_validate_request_arg', + 'enum' => array( + '1', + '<10', + '10-50', + '50-250', + '+250', + 'not specified', + ), + ), 'revenue' => array( 'type' => 'string', 'description' => __( 'Current annual revenue of the store.', 'woocommerce-admin' ), diff --git a/plugins/woocommerce-admin/src/Features/Onboarding.php b/plugins/woocommerce-admin/src/Features/Onboarding.php index f057ffde608..d546b10f037 100644 --- a/plugins/woocommerce-admin/src/Features/Onboarding.php +++ b/plugins/woocommerce-admin/src/Features/Onboarding.php @@ -262,6 +262,7 @@ class Onboarding { 'product_types' => array(), 'product_count' => '0', 'selling_venues' => 'no', + 'number_employees' => '1', 'revenue' => 'none', 'other_platform' => 'none', 'business_extensions' => array(), diff --git a/plugins/woocommerce-admin/tests/api/onboarding-profile.php b/plugins/woocommerce-admin/tests/api/onboarding-profile.php index 6d57269b386..028975fb4ed 100644 --- a/plugins/woocommerce-admin/tests/api/onboarding-profile.php +++ b/plugins/woocommerce-admin/tests/api/onboarding-profile.php @@ -106,13 +106,14 @@ class WC_Tests_API_Onboarding_Profiles extends WC_REST_Unit_Test_Case { $data = $response->get_data(); $properties = $data['schema']['properties']; - $this->assertCount( 15, $properties ); + $this->assertCount( 16, $properties ); $this->assertArrayHasKey( 'completed', $properties ); $this->assertArrayHasKey( 'skipped', $properties ); $this->assertArrayHasKey( 'industry', $properties ); $this->assertArrayHasKey( 'product_types', $properties ); $this->assertArrayHasKey( 'product_count', $properties ); $this->assertArrayHasKey( 'selling_venues', $properties ); + $this->assertArrayHasKey( 'number_employees', $properties ); $this->assertArrayHasKey( 'revenue', $properties ); $this->assertArrayHasKey( 'other_platform', $properties ); $this->assertArrayHasKey( 'other_platform_name', $properties );