* 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 <contacto@fernandomarichal.com>
This commit is contained in:
Fernando 2021-11-29 17:00:38 -03:00 committed by GitHub
parent c3a050254d
commit a90e9de61a
9 changed files with 97 additions and 5 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: Add
OBW - Add number of employees field #7963

View File

@ -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' ),
},
];

View File

@ -29,6 +29,7 @@ import { recordEvent } from '@woocommerce/tracks';
import { CurrencyContext } from '~/lib/currency-context'; import { CurrencyContext } from '~/lib/currency-context';
import { createNoticesFromResponse } from '~/lib/notices'; import { createNoticesFromResponse } from '~/lib/notices';
import { platformOptions } from '../../data/platform-options'; import { platformOptions } from '../../data/platform-options';
import { employeeOptions } from '../../data/employee-options';
import { sellingVenueOptions } from '../../data/selling-venue-options'; import { sellingVenueOptions } from '../../data/selling-venue-options';
import { getRevenueOptions } from '../../data/revenue-options'; import { getRevenueOptions } from '../../data/revenue-options';
import { getProductCountOptions } from '../../data/product-options'; import { getProductCountOptions } from '../../data/product-options';
@ -154,6 +155,7 @@ class BusinessDetails extends Component {
const { updateProfileItems, createNotice } = this.props; const { updateProfileItems, createNotice } = this.props;
const { const {
number_employees: numberEmployees,
other_platform: otherPlatform, other_platform: otherPlatform,
other_platform_name: otherPlatformName, other_platform_name: otherPlatformName,
product_count: productCount, product_count: productCount,
@ -163,6 +165,7 @@ class BusinessDetails extends Component {
} = this.state.savedValues; } = this.state.savedValues;
const updates = { const updates = {
number_employees: numberEmployees,
other_platform: otherPlatform, other_platform: otherPlatform,
other_platform_name: other_platform_name:
otherPlatform === 'other' ? otherPlatformName : '', otherPlatform === 'other' ? otherPlatformName : '',
@ -177,10 +180,7 @@ class BusinessDetails extends Component {
const finalUpdates = Object.entries( updates ).reduce( const finalUpdates = Object.entries( updates ).reduce(
( acc, [ key, val ] ) => { ( acc, [ key, val ] ) => {
if ( val !== '' ) { if ( val !== '' ) {
return { acc[ key ] = val;
...acc,
[ key ]: val,
};
} }
return acc; 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 ( if (
! values.revenue.length && ! values.revenue.length &&
[ [
@ -260,6 +275,7 @@ class BusinessDetails extends Component {
} }
trackBusinessDetailsStep( { trackBusinessDetailsStep( {
number_employees: numberEmployees,
other_platform: otherPlatform, other_platform: otherPlatform,
other_platform_name: otherPlatformName, other_platform_name: otherPlatformName,
product_count: productCount, product_count: productCount,
@ -270,6 +286,7 @@ class BusinessDetails extends Component {
const { getCurrencyConfig } = this.context; const { getCurrencyConfig } = this.context;
recordEvent( 'storeprofiler_store_business_details_continue_variant', { recordEvent( 'storeprofiler_store_business_details_continue_variant', {
number_employees: numberEmployees,
already_selling: sellingVenues, already_selling: sellingVenues,
currency: getCurrencyConfig().code, currency: getCurrencyConfig().code,
product_number: productCount, product_number: productCount,
@ -357,6 +374,26 @@ class BusinessDetails extends Component {
{ ...getInputProps( 'selling_venues' ) } { ...getInputProps( 'selling_venues' ) }
/> />
{ [
'other',
'brick-mortar',
'brick-mortar-other',
'other-woocommerce',
].includes( values.selling_venues ) && (
<SelectControl
excludeSelectedOptions={ false }
label={ __(
'How many employees do you have?',
'woocommerce-admin'
) }
options={ employeeOptions }
required
{ ...getInputProps(
'number_employees'
) }
/>
) }
{ [ { [
'other', 'other',
'brick-mortar', 'brick-mortar',

View File

@ -34,6 +34,7 @@ export const BusinessDetailsStep = ( props ) => {
} }
const initialValues = { const initialValues = {
number_employees: profileItems.number_employees || '',
other_platform: profileItems.other_platform || '', other_platform: profileItems.other_platform || '',
other_platform_name: profileItems.other_platform_name || '', other_platform_name: profileItems.other_platform_name || '',
product_count: profileItems.product_count || '', product_count: profileItems.product_count || '',

View File

@ -10,6 +10,7 @@ export const defaultState = {
business_extensions: null, business_extensions: null,
completed: null, completed: null,
industry: null, industry: null,
number_employees: null,
other_platform: null, other_platform: null,
other_platform_name: null, other_platform_name: null,
product_count: null, product_count: null,

View File

@ -130,6 +130,7 @@ export type ProfileItemsState = {
business_extensions: [ ] | null; business_extensions: [ ] | null;
completed: boolean | null; completed: boolean | null;
industry: Industry[] | null; industry: Industry[] | null;
number_employees: string | null;
other_platform: OtherPlatformSlug | null; other_platform: OtherPlatformSlug | null;
other_platform_name: string | null; other_platform_name: string | null;
product_count: ProductCount | null; product_count: ProductCount | null;

View File

@ -323,6 +323,21 @@ class OnboardingProfile extends \WC_REST_Data_Controller {
'other-woocommerce', '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( 'revenue' => array(
'type' => 'string', 'type' => 'string',
'description' => __( 'Current annual revenue of the store.', 'woocommerce-admin' ), 'description' => __( 'Current annual revenue of the store.', 'woocommerce-admin' ),

View File

@ -262,6 +262,7 @@ class Onboarding {
'product_types' => array(), 'product_types' => array(),
'product_count' => '0', 'product_count' => '0',
'selling_venues' => 'no', 'selling_venues' => 'no',
'number_employees' => '1',
'revenue' => 'none', 'revenue' => 'none',
'other_platform' => 'none', 'other_platform' => 'none',
'business_extensions' => array(), 'business_extensions' => array(),

View File

@ -106,13 +106,14 @@ 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( 15, $properties ); $this->assertCount( 16, $properties );
$this->assertArrayHasKey( 'completed', $properties ); $this->assertArrayHasKey( 'completed', $properties );
$this->assertArrayHasKey( 'skipped', $properties ); $this->assertArrayHasKey( 'skipped', $properties );
$this->assertArrayHasKey( 'industry', $properties ); $this->assertArrayHasKey( 'industry', $properties );
$this->assertArrayHasKey( 'product_types', $properties ); $this->assertArrayHasKey( 'product_types', $properties );
$this->assertArrayHasKey( 'product_count', $properties ); $this->assertArrayHasKey( 'product_count', $properties );
$this->assertArrayHasKey( 'selling_venues', $properties ); $this->assertArrayHasKey( 'selling_venues', $properties );
$this->assertArrayHasKey( 'number_employees', $properties );
$this->assertArrayHasKey( 'revenue', $properties ); $this->assertArrayHasKey( 'revenue', $properties );
$this->assertArrayHasKey( 'other_platform', $properties ); $this->assertArrayHasKey( 'other_platform', $properties );
$this->assertArrayHasKey( 'other_platform_name', $properties ); $this->assertArrayHasKey( 'other_platform_name', $properties );