Refactor selling options - OBW - Business Details (https://github.com/woocommerce/woocommerce-admin/pull/8081)
Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com>
This commit is contained in:
parent
2ce17ed7c0
commit
3c424992a4
|
@ -81,6 +81,17 @@ export const prepareExtensionTrackingData = (
|
|||
return installedExtensions;
|
||||
};
|
||||
|
||||
export const isSellingElsewhere = ( selectedOption ) =>
|
||||
[
|
||||
'other',
|
||||
'brick-mortar',
|
||||
'brick-mortar-other',
|
||||
'other-woocommerce',
|
||||
].includes( selectedOption );
|
||||
|
||||
export const isSellingOtherPlatformInPerson = ( selectedOption ) =>
|
||||
[ 'other', 'brick-mortar-other' ].includes( selectedOption );
|
||||
|
||||
class BusinessDetails extends Component {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -219,7 +230,7 @@ class BusinessDetails extends Component {
|
|||
|
||||
if (
|
||||
! values.other_platform.length &&
|
||||
[ 'other', 'brick-mortar-other' ].includes( values.selling_venues )
|
||||
isSellingOtherPlatformInPerson( values.selling_venues )
|
||||
) {
|
||||
errors.other_platform = __(
|
||||
'This field is required',
|
||||
|
@ -229,7 +240,7 @@ class BusinessDetails extends Component {
|
|||
if (
|
||||
! values.other_platform_name.trim().length &&
|
||||
values.other_platform === 'other' &&
|
||||
[ 'other', 'brick-mortar-other' ].includes( values.selling_venues )
|
||||
isSellingOtherPlatformInPerson( values.selling_venues )
|
||||
) {
|
||||
errors.other_platform_name = __(
|
||||
'This field is required',
|
||||
|
@ -239,12 +250,7 @@ class BusinessDetails extends Component {
|
|||
|
||||
if (
|
||||
! values.number_employees.length &&
|
||||
[
|
||||
'other',
|
||||
'brick-mortar',
|
||||
'brick-mortar-other',
|
||||
'other-woocommerce',
|
||||
].includes( values.selling_venues )
|
||||
isSellingElsewhere( values.selling_venues )
|
||||
) {
|
||||
errors.number_employees = __(
|
||||
'This field is required',
|
||||
|
@ -254,12 +260,7 @@ class BusinessDetails extends Component {
|
|||
|
||||
if (
|
||||
! values.revenue.length &&
|
||||
[
|
||||
'other',
|
||||
'brick-mortar',
|
||||
'brick-mortar-other',
|
||||
'other-woocommerce',
|
||||
].includes( values.selling_venues )
|
||||
isSellingElsewhere( values.selling_venues )
|
||||
) {
|
||||
errors.revenue = __(
|
||||
'This field is required',
|
||||
|
@ -391,12 +392,9 @@ class BusinessDetails extends Component {
|
|||
) }
|
||||
/>
|
||||
|
||||
{ [
|
||||
'other',
|
||||
'brick-mortar',
|
||||
'brick-mortar-other',
|
||||
'other-woocommerce',
|
||||
].includes( values.selling_venues ) && (
|
||||
{ isSellingElsewhere(
|
||||
values.selling_venues
|
||||
) && (
|
||||
<SelectControl
|
||||
excludeSelectedOptions={ false }
|
||||
label={ __(
|
||||
|
@ -412,12 +410,9 @@ class BusinessDetails extends Component {
|
|||
/>
|
||||
) }
|
||||
|
||||
{ [
|
||||
'other',
|
||||
'brick-mortar',
|
||||
'brick-mortar-other',
|
||||
'other-woocommerce',
|
||||
].includes( values.selling_venues ) && (
|
||||
{ isSellingElsewhere(
|
||||
values.selling_venues
|
||||
) && (
|
||||
<SelectControl
|
||||
excludeSelectedOptions={ false }
|
||||
label={ __(
|
||||
|
@ -438,10 +433,9 @@ class BusinessDetails extends Component {
|
|||
/>
|
||||
) }
|
||||
|
||||
{ [
|
||||
'other',
|
||||
'brick-mortar-other',
|
||||
].includes( values.selling_venues ) && (
|
||||
{ isSellingOtherPlatformInPerson(
|
||||
values.selling_venues
|
||||
) && (
|
||||
<>
|
||||
<div className="business-competitors">
|
||||
<SelectControl
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
*/
|
||||
import {
|
||||
filterBusinessExtensions,
|
||||
isSellingElsewhere,
|
||||
isSellingOtherPlatformInPerson,
|
||||
prepareExtensionTrackingData,
|
||||
} from '../flows/selective-bundle';
|
||||
import { createInstallExtensionOptions } from '../flows/selective-bundle/selective-extensions-bundle';
|
||||
|
@ -139,4 +141,25 @@ describe( 'BusinessDetails', () => {
|
|||
expect( values ).not.toContain( 'this-should-not-show-at-all' );
|
||||
} );
|
||||
} );
|
||||
|
||||
describe( 'Currently selling elsewhere', () => {
|
||||
test( 'isSellingElsewhere', () => {
|
||||
const sellingElsewhere = isSellingElsewhere( 'other' );
|
||||
const notSellingElsewhere = isSellingElsewhere( 'no' );
|
||||
|
||||
expect( sellingElsewhere ).toBeTruthy();
|
||||
expect( notSellingElsewhere ).toBeFalsy();
|
||||
} );
|
||||
test( 'isSellingOtherPlatformInPerson', () => {
|
||||
const sellingAnotherPlatformAndInPerson = isSellingOtherPlatformInPerson(
|
||||
'brick-mortar-other'
|
||||
);
|
||||
const notSellingAnotherPlatformAndInPerson = isSellingOtherPlatformInPerson(
|
||||
'no'
|
||||
);
|
||||
|
||||
expect( sellingAnotherPlatformAndInPerson ).toBeTruthy();
|
||||
expect( notSellingAnotherPlatformAndInPerson ).toBeFalsy();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue