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,
|
2022-07-21 04:57:46 +00:00
|
|
|
Spinner,
|
2021-01-06 22:08:57 +00:00
|
|
|
} from '@wordpress/components';
|
|
|
|
import { withDispatch, withSelect } from '@wordpress/data';
|
2022-08-18 17:36:20 +00:00
|
|
|
import { Form, TextControl, SelectControl } 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';
|
2022-07-21 04:57:46 +00:00
|
|
|
import {
|
|
|
|
SelectiveExtensionsBundle,
|
|
|
|
getInstallableExtensions,
|
|
|
|
} from './selective-extensions-bundle';
|
2022-05-10 00:58:23 +00:00
|
|
|
import { getPluginSlug, getPluginTrackKey, getTimeFrame } 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 )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
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 );
|
|
|
|
|
2022-07-14 05:38:33 +00:00
|
|
|
export const PERSIST_FREE_FEATURES_DATA_STORAGE_KEY =
|
|
|
|
'wc-admin-free-features-tab-values';
|
|
|
|
|
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',
|
2022-07-14 05:38:33 +00:00
|
|
|
savedValues: props.initialValues,
|
2021-01-06 22:08:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onContinue = this.onContinue.bind( this );
|
|
|
|
this.validate = this.validate.bind( this );
|
2022-07-14 05:38:33 +00:00
|
|
|
this.persistValues = this.persistValues.bind( this );
|
|
|
|
this.persistProfileItems.bind( this );
|
|
|
|
|
2022-02-17 19:15:11 +00:00
|
|
|
props.trackStepValueChanges(
|
|
|
|
props.step.key,
|
2022-07-14 05:38:33 +00:00
|
|
|
props.initialValues,
|
|
|
|
this.state.savedValues,
|
|
|
|
this.persistValues
|
2022-02-17 19:15:11 +00:00
|
|
|
);
|
2022-07-21 04:57:46 +00:00
|
|
|
// Refetch the free extensions data
|
|
|
|
props.invalidateResolutionForStoreSelector( 'getFreeExtensions' );
|
2021-01-06 22:08:57 +00:00
|
|
|
}
|
|
|
|
|
2022-01-24 16:23:12 +00:00
|
|
|
async onContinue(
|
|
|
|
extensionInstallationOptions,
|
|
|
|
installableExtensionsData
|
|
|
|
) {
|
2022-06-21 08:37:34 +00:00
|
|
|
const { createNotice, goToNextStep, installAndActivatePlugins } =
|
|
|
|
this.props;
|
2021-01-06 22:08:57 +00:00
|
|
|
|
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;
|
2022-06-21 08:37:34 +00:00
|
|
|
const installedExtensionsData =
|
|
|
|
prepareExtensionTrackingInstallationData(
|
|
|
|
extensionInstallationOptions,
|
|
|
|
response
|
|
|
|
);
|
2022-01-24 16:23:12 +00:00
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-07-14 05:38:33 +00:00
|
|
|
async persistValues() {
|
|
|
|
await this.persistProfileItems();
|
|
|
|
|
|
|
|
try {
|
|
|
|
window.localStorage.setItem(
|
|
|
|
PERSIST_FREE_FEATURES_DATA_STORAGE_KEY,
|
|
|
|
JSON.stringify( this.state.savedValues.freeFeaturesTab )
|
|
|
|
);
|
|
|
|
} catch ( error ) {
|
|
|
|
this.props.createNotice(
|
|
|
|
'error',
|
|
|
|
__(
|
|
|
|
'There was a problem saving free features state',
|
|
|
|
'woocommerce'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-16 22:34:33 +00:00
|
|
|
async persistProfileItems( additions = {} ) {
|
|
|
|
const { updateProfileItems, createNotice } = this.props;
|
2022-07-14 05:38:33 +00:00
|
|
|
const { businessDetailsTab = {} } = this.state.savedValues;
|
2021-08-16 22:34:33 +00:00
|
|
|
|
|
|
|
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,
|
2022-07-14 05:38:33 +00:00
|
|
|
} = businessDetailsTab;
|
2021-08-16 22:34:33 +00:00
|
|
|
|
|
|
|
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,
|
2022-08-26 04:37:08 +00:00
|
|
|
wp_version: getSetting( 'wpVersion' ),
|
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
|
2022-07-14 05:38:33 +00:00
|
|
|
initialValues={ this.state.savedValues.businessDetailsTab }
|
2021-05-18 04:24:24 +00:00
|
|
|
onSubmit={ ( values ) => {
|
2022-07-21 04:57:46 +00:00
|
|
|
if ( this.props.hasInstallableExtensions ) {
|
|
|
|
this.setState( {
|
|
|
|
savedValues: {
|
|
|
|
...this.state.savedValues,
|
|
|
|
businessDetailsTab: values,
|
|
|
|
},
|
|
|
|
currentTab: BUSINESS_FEATURES_TAB_NAME,
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
goToNextStep( {
|
|
|
|
step: BUSINESS_FEATURES_TAB_NAME,
|
|
|
|
} );
|
|
|
|
}
|
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 ) => {
|
2022-07-14 05:38:33 +00:00
|
|
|
const savedValues = {
|
|
|
|
...this.state.savedValues,
|
|
|
|
businessDetailsTab: values,
|
|
|
|
};
|
|
|
|
this.setState( {
|
|
|
|
savedValues,
|
|
|
|
isValid,
|
|
|
|
} );
|
2022-02-17 19:15:11 +00:00
|
|
|
this.props.updateCurrentStepValues(
|
|
|
|
this.props.step.key,
|
2022-07-14 05:38:33 +00:00
|
|
|
savedValues
|
2022-02-17 19:15:11 +00:00
|
|
|
);
|
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 }
|
2022-10-03 08:32:23 +00:00
|
|
|
aria-disabled={ ! isValidForm }
|
2021-02-19 14:20:16 +00:00
|
|
|
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() {
|
2022-07-21 04:57:46 +00:00
|
|
|
const { isInstallingActivating } = this.props;
|
2022-07-14 05:38:33 +00:00
|
|
|
const {
|
|
|
|
savedValues: { freeFeaturesTab },
|
|
|
|
} = this.state;
|
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 }
|
2022-07-21 04:57:46 +00:00
|
|
|
installableExtensions={ this.props.installableExtensions }
|
2022-07-14 05:38:33 +00:00
|
|
|
installExtensionOptions={
|
|
|
|
freeFeaturesTab.installExtensionOptions
|
|
|
|
}
|
|
|
|
setInstallExtensionOptions={ (
|
|
|
|
installExtensionOptions
|
|
|
|
) => {
|
|
|
|
const savedValues = {
|
|
|
|
...this.state.savedValues,
|
|
|
|
freeFeaturesTab: {
|
|
|
|
...freeFeaturesTab,
|
|
|
|
installExtensionOptions,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
this.setState( {
|
|
|
|
savedValues,
|
|
|
|
} );
|
2022-07-21 04:57:46 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
// Only update current step values when current state's installExtensionOptions is not undefined.
|
|
|
|
this.state.savedValues.freeFeaturesTab
|
|
|
|
.installExtensionOptions
|
|
|
|
) {
|
|
|
|
this.props.updateCurrentStepValues(
|
|
|
|
this.props.step.key,
|
|
|
|
savedValues
|
|
|
|
);
|
|
|
|
}
|
2022-07-14 05:38:33 +00:00
|
|
|
} }
|
2021-01-06 22:08:57 +00:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2022-07-21 04:57:46 +00:00
|
|
|
const tabs = [];
|
|
|
|
if ( ! this.props.hasFinishedGetFreeExtensionsResolution ) {
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-admin__business-details__spinner">
|
|
|
|
<Spinner />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
tabs.push( {
|
|
|
|
name:
|
|
|
|
this.state.currentTab === BUSINESS_DETAILS_TAB_NAME
|
|
|
|
? 'current-tab'
|
|
|
|
: BUSINESS_DETAILS_TAB_NAME,
|
|
|
|
id: BUSINESS_DETAILS_TAB_NAME,
|
|
|
|
title: __( 'Business details', 'woocommerce' ),
|
|
|
|
} );
|
|
|
|
|
|
|
|
if ( this.props.hasInstallableExtensions ) {
|
|
|
|
tabs.push( {
|
|
|
|
name:
|
|
|
|
this.state.currentTab === BUSINESS_FEATURES_TAB_NAME
|
|
|
|
? 'current-tab'
|
|
|
|
: BUSINESS_FEATURES_TAB_NAME,
|
|
|
|
id: BUSINESS_FEATURES_TAB_NAME,
|
|
|
|
title: __( 'Free features', 'woocommerce' ),
|
|
|
|
className: this.state.isValid ? '' : 'is-disabled',
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2022-07-14 05:38:33 +00:00
|
|
|
// There is a hack here to help us manage the selected tab programmatically.
|
2021-01-06 22:08:57 +00:00
|
|
|
// 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:
|
2022-07-14 05:38:33 +00:00
|
|
|
this.state.savedValues ||
|
|
|
|
this.props.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
|
|
|
}
|
|
|
|
} }
|
2022-07-21 04:57:46 +00:00
|
|
|
tabs={ tabs }
|
2021-01-06 22:08:57 +00:00
|
|
|
>
|
|
|
|
{ ( 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 );
|
2022-07-21 04:57:46 +00:00
|
|
|
const {
|
|
|
|
getProfileItems,
|
|
|
|
getOnboardingError,
|
|
|
|
getFreeExtensions,
|
|
|
|
hasFinishedResolution,
|
|
|
|
} = select( ONBOARDING_STORE_NAME );
|
2022-06-21 08:37:34 +00:00
|
|
|
const { getPluginsError, isPluginsRequesting } =
|
|
|
|
select( PLUGINS_STORE_NAME );
|
2021-01-06 22:08:57 +00:00
|
|
|
const { general: settings = {} } = getSettings( 'general' );
|
|
|
|
|
2022-07-21 04:57:46 +00:00
|
|
|
const freeExtensions = getFreeExtensions();
|
|
|
|
const profileItems = getProfileItems();
|
|
|
|
const country = settings.woocommerce_default_country
|
|
|
|
? settings.woocommerce_default_country
|
|
|
|
: null;
|
|
|
|
|
|
|
|
const installableExtensions = freeExtensions
|
|
|
|
? getInstallableExtensions( {
|
|
|
|
freeExtensionBundleByCategory: freeExtensions,
|
|
|
|
country,
|
2022-10-14 18:43:36 +00:00
|
|
|
productTypes: profileItems.product_types || [],
|
2022-07-21 04:57:46 +00:00
|
|
|
} )
|
|
|
|
: [];
|
|
|
|
const hasInstallableExtensions = installableExtensions.some(
|
|
|
|
( { plugins } ) => plugins.length > 0
|
|
|
|
);
|
|
|
|
|
2021-01-06 22:08:57 +00:00
|
|
|
return {
|
|
|
|
hasInstallActivateError:
|
|
|
|
getPluginsError( 'installPlugins' ) ||
|
|
|
|
getPluginsError( 'activatePlugins' ),
|
2022-07-21 04:57:46 +00:00
|
|
|
hasInstallableExtensions,
|
|
|
|
hasFinishedGetFreeExtensionsResolution:
|
|
|
|
hasFinishedResolution( 'getFreeExtensions' ),
|
|
|
|
installableExtensions,
|
2021-01-06 22:08:57 +00:00
|
|
|
isError: Boolean( getOnboardingError( 'updateProfileItems' ) ),
|
|
|
|
isSettingsError: Boolean( getSettingsError( 'general' ) ),
|
|
|
|
isInstallingActivating:
|
|
|
|
isPluginsRequesting( 'installPlugins' ) ||
|
|
|
|
isPluginsRequesting( 'activatePlugins' ) ||
|
|
|
|
isPluginsRequesting( 'getJetpackConnectUrl' ),
|
2022-07-21 04:57:46 +00:00
|
|
|
profileItems,
|
|
|
|
settings,
|
2021-01-06 22:08:57 +00:00
|
|
|
};
|
|
|
|
} ),
|
|
|
|
withDispatch( ( dispatch ) => {
|
2022-07-21 04:57:46 +00:00
|
|
|
const { updateProfileItems, invalidateResolutionForStoreSelector } =
|
|
|
|
dispatch( ONBOARDING_STORE_NAME );
|
2021-01-06 22:08:57 +00:00
|
|
|
const { installAndActivatePlugins } = dispatch( PLUGINS_STORE_NAME );
|
|
|
|
const { createNotice } = dispatch( 'core/notices' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
updateProfileItems,
|
2022-07-21 04:57:46 +00:00
|
|
|
invalidateResolutionForStoreSelector,
|
2021-01-06 22:08:57 +00:00
|
|
|
};
|
|
|
|
} )
|
|
|
|
)( BusinessDetails );
|