2021-01-06 22:08:57 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { compose } from '@wordpress/compose';
|
|
|
|
import {
|
|
|
|
Button,
|
2021-02-19 14:20:16 +00:00
|
|
|
Card,
|
|
|
|
CardBody,
|
|
|
|
CardFooter,
|
2021-01-06 22:08:57 +00:00
|
|
|
TabPanel,
|
|
|
|
__experimentalText as Text,
|
2021-08-31 04:39:04 +00:00
|
|
|
FlexItem,
|
|
|
|
CheckboxControl,
|
2021-01-06 22:08:57 +00:00
|
|
|
} from '@wordpress/components';
|
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
2021-02-19 14:20:16 +00:00
|
|
|
import { SelectControl, Form, TextControl } from '@woocommerce/components';
|
2021-01-06 22:08:57 +00:00
|
|
|
import {
|
|
|
|
ONBOARDING_STORE_NAME,
|
|
|
|
PLUGINS_STORE_NAME,
|
|
|
|
SETTINGS_STORE_NAME,
|
|
|
|
} from '@woocommerce/data';
|
2022-02-11 14:03:37 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2021-01-06 22:08:57 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2021-12-21 12:58:15 +00:00
|
|
|
import classnames from 'classnames';
|
2021-01-06 22:08:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-03-10 15:11:37 +00:00
|
|
|
import { CurrencyContext } from '~/lib/currency-context';
|
|
|
|
import { createNoticesFromResponse } from '~/lib/notices';
|
2021-01-06 22:08:57 +00:00
|
|
|
import { platformOptions } from '../../data/platform-options';
|
2021-11-29 20:00:38 +00:00
|
|
|
import { employeeOptions } from '../../data/employee-options';
|
2021-01-06 22:08:57 +00:00
|
|
|
import { sellingVenueOptions } from '../../data/selling-venue-options';
|
|
|
|
import { getRevenueOptions } from '../../data/revenue-options';
|
|
|
|
import { getProductCountOptions } from '../../data/product-options';
|
|
|
|
import { SelectiveExtensionsBundle } from './selective-extensions-bundle';
|
2022-01-24 16:23:12 +00:00
|
|
|
import { getPluginSlug, getPluginTrackKey } from '~/utils';
|
2021-01-06 22:08:57 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
const BUSINESS_DETAILS_TAB_NAME = 'business-details';
|
2022-02-08 18:29:17 +00:00
|
|
|
const BUSINESS_FEATURES_TAB_NAME = 'business-features';
|
2021-01-06 22:08:57 +00:00
|
|
|
|
2022-01-24 16:23:12 +00:00
|
|
|
export const filterBusinessExtensions = (
|
|
|
|
extensionInstallationOptions,
|
|
|
|
alreadyActivatedExtensions = []
|
|
|
|
) => {
|
2021-03-17 08:22:33 +00:00
|
|
|
return (
|
|
|
|
Object.keys( extensionInstallationOptions )
|
|
|
|
.filter(
|
|
|
|
( key ) =>
|
|
|
|
extensionInstallationOptions[ key ] &&
|
2022-01-24 16:23:12 +00:00
|
|
|
key !== 'install_extensions' &&
|
|
|
|
! alreadyActivatedExtensions.includes( key )
|
2021-03-17 08:22:33 +00:00
|
|
|
)
|
2022-01-24 16:23:12 +00:00
|
|
|
.map( getPluginSlug )
|
2021-03-17 08:22:33 +00:00
|
|
|
// remove duplicate
|
|
|
|
.filter( ( item, index, arr ) => arr.indexOf( item ) === index )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2022-01-24 16:23:12 +00:00
|
|
|
const timeFrames = [
|
|
|
|
{ name: '0-2s', max: 2 },
|
|
|
|
{ name: '2-5s', max: 5 },
|
|
|
|
{ name: '5-10s', max: 10 },
|
|
|
|
{ name: '10-15s', max: 15 },
|
|
|
|
{ name: '15-20s', max: 20 },
|
|
|
|
{ name: '20-30s', max: 30 },
|
|
|
|
{ name: '30-60s', max: 60 },
|
|
|
|
{ name: '>60s' },
|
|
|
|
];
|
|
|
|
function getTimeFrame( timeInMs ) {
|
|
|
|
for ( const timeFrame of timeFrames ) {
|
|
|
|
if ( ! timeFrame.max ) {
|
|
|
|
return timeFrame.name;
|
|
|
|
}
|
|
|
|
if ( timeInMs < timeFrame.max * 1000 ) {
|
|
|
|
return timeFrame.name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-18 17:15:19 +00:00
|
|
|
export const prepareExtensionTrackingData = (
|
|
|
|
extensionInstallationOptions
|
|
|
|
) => {
|
|
|
|
const installedExtensions = {};
|
2022-01-24 16:23:12 +00:00
|
|
|
for ( let [ fieldKey, value ] of Object.entries(
|
2021-11-18 17:15:19 +00:00
|
|
|
extensionInstallationOptions
|
|
|
|
) ) {
|
2022-01-24 16:23:12 +00:00
|
|
|
fieldKey = getPluginSlug( fieldKey );
|
|
|
|
const key = getPluginTrackKey( fieldKey );
|
2021-11-18 17:15:19 +00:00
|
|
|
if (
|
|
|
|
fieldKey !== 'install_extensions' &&
|
2022-01-24 16:23:12 +00:00
|
|
|
! installedExtensions[ `install_${ key }` ]
|
2021-11-18 17:15:19 +00:00
|
|
|
) {
|
2022-01-24 16:23:12 +00:00
|
|
|
installedExtensions[ `install_${ key }` ] = value;
|
2021-11-18 17:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return installedExtensions;
|
|
|
|
};
|
|
|
|
|
2022-01-24 16:23:12 +00:00
|
|
|
export const prepareExtensionTrackingInstallationData = (
|
|
|
|
extensionInstallationOptions,
|
|
|
|
installationData
|
|
|
|
) => {
|
|
|
|
const installed = [];
|
|
|
|
const data = {};
|
|
|
|
for ( let [ fieldKey ] of Object.entries( extensionInstallationOptions ) ) {
|
|
|
|
fieldKey = getPluginSlug( fieldKey );
|
|
|
|
const key = getPluginTrackKey( fieldKey );
|
|
|
|
if (
|
|
|
|
installationData &&
|
|
|
|
installationData.data &&
|
|
|
|
installationData.data.install_time &&
|
|
|
|
installationData.data.install_time[ fieldKey ]
|
|
|
|
) {
|
|
|
|
installed.push( key );
|
|
|
|
data[ `install_time_${ key }` ] = getTimeFrame(
|
|
|
|
installationData.data.install_time[ fieldKey ]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.installed_extensions = installed;
|
|
|
|
data.activated_extensions =
|
|
|
|
installationData &&
|
|
|
|
installationData.data &&
|
|
|
|
installationData.data.activated
|
|
|
|
? installationData.data.activated
|
|
|
|
: [];
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|
2022-01-18 13:46:10 +00:00
|
|
|
export const isSellingElsewhere = ( selectedOption ) =>
|
|
|
|
[
|
|
|
|
'other',
|
|
|
|
'brick-mortar',
|
|
|
|
'brick-mortar-other',
|
|
|
|
'other-woocommerce',
|
|
|
|
].includes( selectedOption );
|
|
|
|
|
|
|
|
export const isSellingOtherPlatformInPerson = ( selectedOption ) =>
|
|
|
|
[ 'other', 'brick-mortar-other' ].includes( selectedOption );
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
class BusinessDetails extends Component {
|
2022-02-17 19:15:11 +00:00
|
|
|
constructor( props ) {
|
2021-01-06 22:08:57 +00:00
|
|
|
super();
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isPopoverVisible: false,
|
|
|
|
isValid: false,
|
|
|
|
currentTab: 'business-details',
|
|
|
|
savedValues: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onContinue = this.onContinue.bind( this );
|
|
|
|
this.validate = this.validate.bind( this );
|
2022-02-17 19:15:11 +00:00
|
|
|
props.trackStepValueChanges(
|
|
|
|
props.step.key,
|
|
|
|
{ ...( this.state.savedValues || props.initialValues ) },
|
|
|
|
this.savedValues || props.initialValues,
|
|
|
|
this.persistProfileItems.bind( this )
|
|
|
|
);
|
2021-01-06 22:08:57 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 16:23:12 +00:00
|
|
|
async onContinue(
|
|
|
|
extensionInstallationOptions,
|
|
|
|
installableExtensionsData
|
|
|
|
) {
|
2021-01-06 22:08:57 +00:00
|
|
|
const {
|
|
|
|
createNotice,
|
|
|
|
goToNextStep,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
} = this.props;
|
|
|
|
|
2022-01-24 16:23:12 +00:00
|
|
|
const alreadyActivatedExtensions = installableExtensionsData.reduce(
|
|
|
|
( actExtensions, bundle ) => {
|
|
|
|
const activated = bundle.plugins
|
|
|
|
.filter( ( plugin ) => plugin.is_activated )
|
|
|
|
.map( ( plugin ) => plugin.key );
|
|
|
|
return [ ...actExtensions, ...activated ];
|
|
|
|
},
|
|
|
|
[]
|
|
|
|
);
|
|
|
|
|
2021-03-17 08:22:33 +00:00
|
|
|
const businessExtensions = filterBusinessExtensions(
|
2022-01-24 16:23:12 +00:00
|
|
|
extensionInstallationOptions,
|
|
|
|
alreadyActivatedExtensions
|
2021-01-06 22:08:57 +00:00
|
|
|
);
|
|
|
|
|
2021-11-18 17:15:19 +00:00
|
|
|
const installedExtensions = prepareExtensionTrackingData(
|
|
|
|
extensionInstallationOptions
|
|
|
|
);
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
recordEvent( 'storeprofiler_store_business_features_continue', {
|
|
|
|
all_extensions_installed: Object.values(
|
|
|
|
extensionInstallationOptions
|
|
|
|
).every( ( val ) => val ),
|
2021-11-18 17:15:19 +00:00
|
|
|
...installedExtensions,
|
2021-01-06 22:08:57 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
const promises = [
|
2021-08-16 22:34:33 +00:00
|
|
|
this.persistProfileItems( {
|
2022-04-06 17:01:36 +00:00
|
|
|
business_extensions: [
|
|
|
|
...businessExtensions,
|
|
|
|
...alreadyActivatedExtensions,
|
|
|
|
],
|
2021-01-06 22:08:57 +00:00
|
|
|
} ),
|
|
|
|
];
|
|
|
|
|
|
|
|
if ( businessExtensions.length ) {
|
2022-01-24 16:23:12 +00:00
|
|
|
const installationStartTime = window.performance.now();
|
2021-01-06 22:08:57 +00:00
|
|
|
promises.push(
|
|
|
|
installAndActivatePlugins( businessExtensions )
|
|
|
|
.then( ( response ) => {
|
2022-01-24 16:23:12 +00:00
|
|
|
const totalInstallationTime =
|
|
|
|
window.performance.now() - installationStartTime;
|
|
|
|
const installedExtensionsData = prepareExtensionTrackingInstallationData(
|
|
|
|
extensionInstallationOptions,
|
|
|
|
response
|
|
|
|
);
|
|
|
|
|
|
|
|
recordEvent(
|
|
|
|
'storeprofiler_store_business_features_installed_and_activated',
|
|
|
|
{
|
|
|
|
success: true,
|
|
|
|
total_time: getTimeFrame(
|
|
|
|
totalInstallationTime
|
|
|
|
),
|
|
|
|
...installedExtensionsData,
|
|
|
|
}
|
|
|
|
);
|
2021-01-06 22:08:57 +00:00
|
|
|
createNoticesFromResponse( response );
|
|
|
|
} )
|
|
|
|
.catch( ( error ) => {
|
2022-01-24 16:23:12 +00:00
|
|
|
recordEvent(
|
|
|
|
'storeprofiler_store_business_features_installed_and_activated',
|
|
|
|
{
|
|
|
|
success: false,
|
|
|
|
failed_extensions: Object.keys(
|
|
|
|
error.data || {}
|
|
|
|
).map( ( key ) => getPluginTrackKey( key ) ),
|
|
|
|
}
|
|
|
|
);
|
2021-01-06 22:08:57 +00:00
|
|
|
createNoticesFromResponse( error );
|
|
|
|
throw new Error();
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Promise.all( promises )
|
|
|
|
.then( () => {
|
2022-02-08 18:29:17 +00:00
|
|
|
goToNextStep( { step: BUSINESS_FEATURES_TAB_NAME } );
|
2021-01-06 22:08:57 +00:00
|
|
|
} )
|
|
|
|
.catch( () => {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__(
|
2021-02-10 23:57:51 +00:00
|
|
|
'There was a problem updating your business details',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-08-16 22:34:33 +00:00
|
|
|
async persistProfileItems( additions = {} ) {
|
|
|
|
const { updateProfileItems, createNotice } = this.props;
|
|
|
|
|
|
|
|
const {
|
2021-11-29 20:00:38 +00:00
|
|
|
number_employees: numberEmployees,
|
2021-08-16 22:34:33 +00:00
|
|
|
other_platform: otherPlatform,
|
|
|
|
other_platform_name: otherPlatformName,
|
|
|
|
product_count: productCount,
|
|
|
|
revenue,
|
|
|
|
selling_venues: sellingVenues,
|
2021-08-31 04:39:04 +00:00
|
|
|
setup_client: isSetupClient,
|
2021-08-16 22:34:33 +00:00
|
|
|
} = this.state.savedValues;
|
|
|
|
|
|
|
|
const updates = {
|
2021-11-29 20:00:38 +00:00
|
|
|
number_employees: numberEmployees,
|
2021-08-16 22:34:33 +00:00
|
|
|
other_platform: otherPlatform,
|
|
|
|
other_platform_name:
|
|
|
|
otherPlatform === 'other' ? otherPlatformName : '',
|
|
|
|
product_count: productCount,
|
|
|
|
revenue,
|
|
|
|
selling_venues: sellingVenues,
|
2021-08-31 04:39:04 +00:00
|
|
|
setup_client: isSetupClient,
|
2021-08-16 22:34:33 +00:00
|
|
|
...additions,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Remove possible empty values like `revenue` and `other_platform`.
|
|
|
|
const finalUpdates = Object.entries( updates ).reduce(
|
|
|
|
( acc, [ key, val ] ) => {
|
|
|
|
if ( val !== '' ) {
|
2021-11-29 20:00:38 +00:00
|
|
|
acc[ key ] = val;
|
2021-08-16 22:34:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
);
|
|
|
|
|
|
|
|
return updateProfileItems( finalUpdates ).catch( () => {
|
|
|
|
createNotice(
|
|
|
|
'error',
|
|
|
|
__(
|
|
|
|
'There was a problem updating your business details',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-08-16 22:34:33 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
validate( values ) {
|
|
|
|
const errors = {};
|
|
|
|
|
|
|
|
if ( ! values.product_count.length ) {
|
|
|
|
errors.product_count = __(
|
|
|
|
'This field is required',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! values.selling_venues.length ) {
|
|
|
|
errors.selling_venues = __(
|
|
|
|
'This field is required',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
! values.other_platform.length &&
|
2022-01-18 13:46:10 +00:00
|
|
|
isSellingOtherPlatformInPerson( values.selling_venues )
|
2021-01-06 22:08:57 +00:00
|
|
|
) {
|
|
|
|
errors.other_platform = __(
|
|
|
|
'This field is required',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
if (
|
2021-12-30 02:05:12 +00:00
|
|
|
! values.other_platform_name.trim().length &&
|
2021-01-06 22:08:57 +00:00
|
|
|
values.other_platform === 'other' &&
|
2022-01-18 13:46:10 +00:00
|
|
|
isSellingOtherPlatformInPerson( values.selling_venues )
|
2021-01-06 22:08:57 +00:00
|
|
|
) {
|
|
|
|
errors.other_platform_name = __(
|
|
|
|
'This field is required',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-11-29 20:00:38 +00:00
|
|
|
if (
|
|
|
|
! values.number_employees.length &&
|
2022-01-18 13:46:10 +00:00
|
|
|
isSellingElsewhere( values.selling_venues )
|
2021-11-29 20:00:38 +00:00
|
|
|
) {
|
|
|
|
errors.number_employees = __(
|
|
|
|
'This field is required',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-29 20:00:38 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
if (
|
|
|
|
! values.revenue.length &&
|
2022-01-18 13:46:10 +00:00
|
|
|
isSellingElsewhere( values.selling_venues )
|
2021-01-06 22:08:57 +00:00
|
|
|
) {
|
2022-03-30 09:00:04 +00:00
|
|
|
errors.revenue = __( 'This field is required', 'woocommerce' );
|
2021-01-06 22:08:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( Object.keys( errors ).length === 0 ) {
|
|
|
|
this.setState( { isValid: true } );
|
|
|
|
}
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
}
|
|
|
|
|
2021-03-18 03:36:40 +00:00
|
|
|
trackBusinessDetailsStep( {
|
2021-11-29 20:00:38 +00:00
|
|
|
number_employees: numberEmployees,
|
2021-03-18 03:36:40 +00:00
|
|
|
other_platform: otherPlatform,
|
|
|
|
other_platform_name: otherPlatformName,
|
|
|
|
product_count: productCount,
|
|
|
|
selling_venues: sellingVenues,
|
|
|
|
revenue,
|
2021-08-31 04:39:04 +00:00
|
|
|
setup_client: isSetupClient,
|
2021-03-18 03:36:40 +00:00
|
|
|
} ) {
|
|
|
|
const { getCurrencyConfig } = this.context;
|
|
|
|
|
|
|
|
recordEvent( 'storeprofiler_store_business_details_continue_variant', {
|
2021-11-29 20:00:38 +00:00
|
|
|
number_employees: numberEmployees,
|
2021-03-18 03:36:40 +00:00
|
|
|
already_selling: sellingVenues,
|
|
|
|
currency: getCurrencyConfig().code,
|
|
|
|
product_number: productCount,
|
|
|
|
revenue,
|
|
|
|
used_platform: otherPlatform,
|
|
|
|
used_platform_name: otherPlatformName,
|
2021-08-31 04:39:04 +00:00
|
|
|
setup_client: isSetupClient,
|
2021-03-18 03:36:40 +00:00
|
|
|
} );
|
2022-02-08 18:29:17 +00:00
|
|
|
recordEvent( 'storeprofiler_step_complete', {
|
|
|
|
step: BUSINESS_DETAILS_TAB_NAME,
|
2022-02-11 14:03:37 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
2022-02-08 18:29:17 +00:00
|
|
|
} );
|
2021-03-18 03:36:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-21 12:58:15 +00:00
|
|
|
getSelectControlProps( getInputProps, name = '' ) {
|
|
|
|
const { className, ...props } = getInputProps( name );
|
|
|
|
return {
|
|
|
|
...props,
|
|
|
|
className: classnames(
|
|
|
|
`woocommerce-profile-wizard__${ name.replace( /\_/g, '-' ) }`,
|
|
|
|
className
|
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
renderBusinessDetailsStep() {
|
|
|
|
const {
|
|
|
|
goToNextStep,
|
|
|
|
isInstallingActivating,
|
|
|
|
hasInstallActivateError,
|
|
|
|
} = this.props;
|
|
|
|
|
2021-04-28 02:54:49 +00:00
|
|
|
const { formatAmount, getCurrencyConfig } = this.context;
|
2021-01-06 22:08:57 +00:00
|
|
|
|
|
|
|
const productCountOptions = getProductCountOptions(
|
|
|
|
getCurrencyConfig()
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form
|
|
|
|
initialValues={
|
|
|
|
this.state.savedValues || this.props.initialValues
|
|
|
|
}
|
2021-05-18 04:24:24 +00:00
|
|
|
onSubmit={ ( values ) => {
|
2021-01-06 22:08:57 +00:00
|
|
|
this.setState( {
|
|
|
|
savedValues: values,
|
2022-02-08 18:29:17 +00:00
|
|
|
currentTab: BUSINESS_FEATURES_TAB_NAME,
|
2021-01-06 22:08:57 +00:00
|
|
|
} );
|
2021-03-18 03:36:40 +00:00
|
|
|
|
|
|
|
this.trackBusinessDetailsStep( values );
|
2022-02-08 18:29:17 +00:00
|
|
|
recordEvent( 'storeprofiler_step_view', {
|
|
|
|
step: BUSINESS_FEATURES_TAB_NAME,
|
2022-02-11 14:03:37 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
2022-02-08 18:29:17 +00:00
|
|
|
} );
|
2021-01-06 22:08:57 +00:00
|
|
|
} }
|
2021-05-18 04:24:24 +00:00
|
|
|
onChange={ ( _, values, isValid ) => {
|
2021-01-06 22:08:57 +00:00
|
|
|
this.setState( { savedValues: values, isValid } );
|
2022-02-17 19:15:11 +00:00
|
|
|
this.props.updateCurrentStepValues(
|
|
|
|
this.props.step.key,
|
|
|
|
values
|
|
|
|
);
|
2021-01-06 22:08:57 +00:00
|
|
|
} }
|
|
|
|
validate={ this.validate }
|
|
|
|
>
|
|
|
|
{ ( { getInputProps, handleSubmit, values, isValidForm } ) => {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="woocommerce-profile-wizard__step-header">
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text
|
|
|
|
variant="title.small"
|
|
|
|
as="h2"
|
|
|
|
size="20"
|
|
|
|
lineHeight="28px"
|
|
|
|
>
|
2021-01-06 22:08:57 +00:00
|
|
|
{ __(
|
|
|
|
'Tell us about your business',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
</Text>
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text variant="body" as="p">
|
2021-01-06 22:08:57 +00:00
|
|
|
{ __(
|
|
|
|
"We'd love to know if you are just getting started or you already have a business in place.",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
<Card>
|
2021-02-19 14:20:16 +00:00
|
|
|
<CardBody>
|
2021-01-06 22:08:57 +00:00
|
|
|
<SelectControl
|
2021-03-02 01:06:29 +00:00
|
|
|
excludeSelectedOptions={ false }
|
2021-01-06 22:08:57 +00:00
|
|
|
label={ __(
|
|
|
|
'How many products do you plan to display?',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
options={ productCountOptions }
|
|
|
|
required
|
2021-12-21 12:58:15 +00:00
|
|
|
{ ...this.getSelectControlProps(
|
|
|
|
getInputProps,
|
|
|
|
'product_count'
|
|
|
|
) }
|
2021-01-06 22:08:57 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<SelectControl
|
2021-03-02 01:06:29 +00:00
|
|
|
excludeSelectedOptions={ false }
|
2021-01-06 22:08:57 +00:00
|
|
|
label={ __(
|
|
|
|
'Currently selling elsewhere?',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
options={ sellingVenueOptions }
|
|
|
|
required
|
2021-12-21 12:58:15 +00:00
|
|
|
{ ...this.getSelectControlProps(
|
|
|
|
getInputProps,
|
|
|
|
'selling_venues'
|
|
|
|
) }
|
2021-01-06 22:08:57 +00:00
|
|
|
/>
|
|
|
|
|
2022-01-18 13:46:10 +00:00
|
|
|
{ isSellingElsewhere(
|
|
|
|
values.selling_venues
|
|
|
|
) && (
|
2021-11-29 20:00:38 +00:00
|
|
|
<SelectControl
|
|
|
|
excludeSelectedOptions={ false }
|
|
|
|
label={ __(
|
|
|
|
'How many employees do you have?',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-11-29 20:00:38 +00:00
|
|
|
) }
|
|
|
|
options={ employeeOptions }
|
|
|
|
required
|
2021-12-21 12:58:15 +00:00
|
|
|
{ ...this.getSelectControlProps(
|
|
|
|
getInputProps,
|
2021-11-29 20:00:38 +00:00
|
|
|
'number_employees'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
|
2022-01-18 13:46:10 +00:00
|
|
|
{ isSellingElsewhere(
|
|
|
|
values.selling_venues
|
|
|
|
) && (
|
2021-01-06 22:08:57 +00:00
|
|
|
<SelectControl
|
2021-03-02 01:06:29 +00:00
|
|
|
excludeSelectedOptions={ false }
|
2021-01-06 22:08:57 +00:00
|
|
|
label={ __(
|
|
|
|
"What's your current annual revenue?",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
options={ getRevenueOptions(
|
|
|
|
getCurrencyConfig(),
|
|
|
|
this.props.settings
|
2021-04-28 02:54:49 +00:00
|
|
|
.woocommerce_default_country,
|
|
|
|
formatAmount
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
required
|
2021-12-21 12:58:15 +00:00
|
|
|
{ ...this.getSelectControlProps(
|
|
|
|
getInputProps,
|
|
|
|
'revenue'
|
|
|
|
) }
|
2021-01-06 22:08:57 +00:00
|
|
|
/>
|
|
|
|
) }
|
|
|
|
|
2022-01-18 13:46:10 +00:00
|
|
|
{ isSellingOtherPlatformInPerson(
|
|
|
|
values.selling_venues
|
|
|
|
) && (
|
2021-01-06 22:08:57 +00:00
|
|
|
<>
|
|
|
|
<div className="business-competitors">
|
|
|
|
<SelectControl
|
2021-03-02 01:06:29 +00:00
|
|
|
excludeSelectedOptions={
|
|
|
|
false
|
|
|
|
}
|
2021-01-06 22:08:57 +00:00
|
|
|
label={ __(
|
|
|
|
'Which platform is the store using?',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
options={ platformOptions }
|
|
|
|
required
|
2021-12-21 12:58:15 +00:00
|
|
|
{ ...this.getSelectControlProps(
|
|
|
|
getInputProps,
|
2021-01-06 22:08:57 +00:00
|
|
|
'other_platform'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
{ values.other_platform ===
|
|
|
|
'other' && (
|
|
|
|
<TextControl
|
|
|
|
label={ __(
|
|
|
|
'What is the platform name?',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
required
|
2021-12-21 12:58:15 +00:00
|
|
|
{ ...this.getSelectControlProps(
|
|
|
|
getInputProps,
|
2021-01-06 22:08:57 +00:00
|
|
|
'other_platform_name'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) }
|
2021-02-19 14:20:16 +00:00
|
|
|
</CardBody>
|
2021-08-31 04:39:04 +00:00
|
|
|
<CardFooter isBorderless>
|
|
|
|
<FlexItem>
|
|
|
|
<div className="woocommerce-profile-wizard__client">
|
|
|
|
<CheckboxControl
|
|
|
|
label={ __(
|
|
|
|
"I'm setting up a store for a client",
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-08-31 04:39:04 +00:00
|
|
|
) }
|
|
|
|
{ ...getInputProps(
|
|
|
|
'setup_client'
|
|
|
|
) }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</FlexItem>
|
|
|
|
</CardFooter>
|
|
|
|
<CardFooter justify="center">
|
2021-02-19 14:20:16 +00:00
|
|
|
<Button
|
|
|
|
isPrimary
|
2021-08-16 22:34:33 +00:00
|
|
|
onClick={ async () => {
|
|
|
|
await handleSubmit();
|
|
|
|
this.persistProfileItems();
|
|
|
|
} }
|
2021-02-19 14:20:16 +00:00
|
|
|
disabled={ ! isValidForm }
|
|
|
|
isBusy={ isInstallingActivating }
|
|
|
|
>
|
|
|
|
{ ! hasInstallActivateError
|
2022-03-30 09:00:04 +00:00
|
|
|
? __( 'Continue', 'woocommerce' )
|
|
|
|
: __( 'Retry', 'woocommerce' ) }
|
2021-02-19 14:20:16 +00:00
|
|
|
</Button>
|
|
|
|
{ hasInstallActivateError && (
|
2021-01-06 22:08:57 +00:00
|
|
|
<Button
|
2021-08-16 22:34:33 +00:00
|
|
|
onClick={ () => {
|
|
|
|
this.persistProfileItems();
|
2022-02-08 18:29:17 +00:00
|
|
|
goToNextStep( {
|
|
|
|
step: BUSINESS_FEATURES_TAB_NAME,
|
|
|
|
} );
|
2021-08-16 22:34:33 +00:00
|
|
|
} }
|
2021-01-06 22:08:57 +00:00
|
|
|
>
|
2021-02-19 14:20:16 +00:00
|
|
|
{ __(
|
|
|
|
'Continue without installing',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-02-19 14:20:16 +00:00
|
|
|
) }
|
2021-01-06 22:08:57 +00:00
|
|
|
</Button>
|
2021-02-19 14:20:16 +00:00
|
|
|
) }
|
|
|
|
</CardFooter>
|
2021-01-06 22:08:57 +00:00
|
|
|
</Card>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
} }
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderFreeFeaturesStep() {
|
2021-03-08 14:23:39 +00:00
|
|
|
const { isInstallingActivating, settings, profileItems } = this.props;
|
|
|
|
const country = settings.woocommerce_default_country
|
|
|
|
? settings.woocommerce_default_country
|
|
|
|
: null;
|
2021-01-06 22:08:57 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="woocommerce-profile-wizard__step-header">
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text
|
|
|
|
variant="title.small"
|
|
|
|
as="h2"
|
|
|
|
size="20"
|
|
|
|
lineHeight="28px"
|
|
|
|
>
|
2022-03-30 09:00:04 +00:00
|
|
|
{ __( 'Included business features', 'woocommerce' ) }
|
2021-01-06 22:08:57 +00:00
|
|
|
</Text>
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text variant="body" as="p">
|
2021-01-06 22:08:57 +00:00
|
|
|
{ __(
|
|
|
|
'We recommend enhancing your store with these free extensions',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
</Text>
|
2021-06-28 01:14:59 +00:00
|
|
|
<Text variant="body" as="p">
|
2021-01-06 22:08:57 +00:00
|
|
|
{ __(
|
|
|
|
'No commitment required - you can remove them at any time.',
|
2022-03-30 09:00:04 +00:00
|
|
|
'woocommerce'
|
2021-01-06 22:08:57 +00:00
|
|
|
) }
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<SelectiveExtensionsBundle
|
|
|
|
isInstallingActivating={ isInstallingActivating }
|
|
|
|
onSubmit={ this.onContinue }
|
2021-03-08 14:23:39 +00:00
|
|
|
country={ country }
|
|
|
|
industry={ profileItems.industry }
|
2021-03-17 08:22:33 +00:00
|
|
|
productTypes={ profileItems.product_types }
|
2021-01-06 22:08:57 +00:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-02-04 19:40:58 +00:00
|
|
|
const { initialValues } = this.props;
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
// There is a hack here to help us manage the selected tab programatically.
|
|
|
|
// We set the tab name "current-tab". when its the one we want selected. This tricks
|
|
|
|
// the logic in the TabPanel and allows us to switch which tab has the name "current-tab"
|
|
|
|
// and force it to re-render with a different tab selected.
|
|
|
|
return (
|
|
|
|
<TabPanel
|
|
|
|
activeClass="is-active"
|
|
|
|
initialTabName="current-tab"
|
|
|
|
onSelect={ ( tabName ) => {
|
|
|
|
if ( this.state.currentTab !== tabName ) {
|
2021-02-04 19:40:58 +00:00
|
|
|
this.setState( {
|
|
|
|
currentTab: tabName,
|
2021-06-24 05:04:23 +00:00
|
|
|
savedValues:
|
|
|
|
this.state.savedValues || initialValues,
|
2021-02-04 19:40:58 +00:00
|
|
|
} );
|
2022-02-08 18:29:17 +00:00
|
|
|
recordEvent( 'storeprofiler_step_view', {
|
|
|
|
step: tabName,
|
2022-02-11 14:03:37 +00:00
|
|
|
wc_version: getSetting( 'wcVersion' ),
|
2022-02-08 18:29:17 +00:00
|
|
|
} );
|
2021-01-06 22:08:57 +00:00
|
|
|
}
|
|
|
|
} }
|
|
|
|
tabs={ [
|
|
|
|
{
|
|
|
|
name:
|
|
|
|
this.state.currentTab === BUSINESS_DETAILS_TAB_NAME
|
|
|
|
? 'current-tab'
|
|
|
|
: BUSINESS_DETAILS_TAB_NAME,
|
|
|
|
id: BUSINESS_DETAILS_TAB_NAME,
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Business details', 'woocommerce' ),
|
2021-01-06 22:08:57 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name:
|
2022-02-08 18:29:17 +00:00
|
|
|
this.state.currentTab === BUSINESS_FEATURES_TAB_NAME
|
2021-01-06 22:08:57 +00:00
|
|
|
? 'current-tab'
|
2022-02-08 18:29:17 +00:00
|
|
|
: BUSINESS_FEATURES_TAB_NAME,
|
|
|
|
id: BUSINESS_FEATURES_TAB_NAME,
|
2022-03-30 09:00:04 +00:00
|
|
|
title: __( 'Free features', 'woocommerce' ),
|
2021-01-06 22:08:57 +00:00
|
|
|
className: this.state.isValid ? '' : 'is-disabled',
|
|
|
|
},
|
|
|
|
] }
|
|
|
|
>
|
|
|
|
{ ( tab ) => <>{ this.getTab( tab.id ) }</> }
|
|
|
|
</TabPanel>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getTab( tabId ) {
|
|
|
|
if ( tabId === BUSINESS_DETAILS_TAB_NAME ) {
|
|
|
|
return this.renderBusinessDetailsStep();
|
|
|
|
}
|
|
|
|
return this.renderFreeFeaturesStep();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BusinessDetails.contextType = CurrencyContext;
|
|
|
|
|
2021-06-03 08:33:54 +00:00
|
|
|
export const BusinessFeaturesList = compose(
|
2021-01-06 22:08:57 +00:00
|
|
|
withSelect( ( select ) => {
|
|
|
|
const { getSettings, getSettingsError } = select( SETTINGS_STORE_NAME );
|
|
|
|
const { getProfileItems, getOnboardingError } = select(
|
|
|
|
ONBOARDING_STORE_NAME
|
|
|
|
);
|
|
|
|
const { getPluginsError, isPluginsRequesting } = select(
|
|
|
|
PLUGINS_STORE_NAME
|
|
|
|
);
|
|
|
|
const { general: settings = {} } = getSettings( 'general' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
hasInstallActivateError:
|
|
|
|
getPluginsError( 'installPlugins' ) ||
|
|
|
|
getPluginsError( 'activatePlugins' ),
|
|
|
|
isError: Boolean( getOnboardingError( 'updateProfileItems' ) ),
|
|
|
|
profileItems: getProfileItems(),
|
|
|
|
isSettingsError: Boolean( getSettingsError( 'general' ) ),
|
|
|
|
settings,
|
|
|
|
isInstallingActivating:
|
|
|
|
isPluginsRequesting( 'installPlugins' ) ||
|
|
|
|
isPluginsRequesting( 'activatePlugins' ) ||
|
|
|
|
isPluginsRequesting( 'getJetpackConnectUrl' ),
|
|
|
|
};
|
|
|
|
} ),
|
|
|
|
withDispatch( ( dispatch ) => {
|
|
|
|
const { updateProfileItems } = dispatch( ONBOARDING_STORE_NAME );
|
|
|
|
const { installAndActivatePlugins } = dispatch( PLUGINS_STORE_NAME );
|
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
updateProfileItems,
|
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( BusinessDetails );
|