2019-10-11 12:55:35 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
|
2020-08-03 19:24:57 +00:00
|
|
|
import { __, sprintf } from '@wordpress/i18n';
|
2019-10-21 03:11:21 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2020-07-16 15:17:10 +00:00
|
|
|
import {
|
|
|
|
getHistory,
|
|
|
|
getNewPath,
|
|
|
|
updateQueryString,
|
|
|
|
} from '@woocommerce/navigation';
|
2020-07-14 01:40:56 +00:00
|
|
|
import { Fragment } from '@wordpress/element';
|
2020-08-20 04:59:52 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2019-10-11 12:55:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Appearance from './tasks/appearance';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { getCategorizedOnboardingProducts } from '../dashboard/utils';
|
2019-10-11 12:55:35 +00:00
|
|
|
import Products from './tasks/products';
|
|
|
|
import Shipping from './tasks/shipping';
|
|
|
|
import Tax from './tasks/tax';
|
|
|
|
import Payments from './tasks/payments';
|
2020-07-14 01:40:56 +00:00
|
|
|
import { installActivateAndConnectWcpay } from './tasks/payments/methods';
|
2020-12-11 02:29:45 +00:00
|
|
|
import { groupListOfObjectsBy } from '../lib/lists';
|
2020-07-14 01:40:56 +00:00
|
|
|
|
|
|
|
export function recordTaskViewEvent(
|
|
|
|
taskName,
|
|
|
|
isJetpackConnected,
|
|
|
|
activePlugins,
|
|
|
|
installedPlugins
|
|
|
|
) {
|
|
|
|
recordEvent( 'task_view', {
|
|
|
|
task_name: taskName,
|
|
|
|
wcs_installed: installedPlugins.includes( 'woocommerce-services' ),
|
|
|
|
wcs_active: activePlugins.includes( 'woocommerce-services' ),
|
|
|
|
jetpack_installed: installedPlugins.includes( 'jetpack' ),
|
|
|
|
jetpack_active: activePlugins.includes( 'jetpack' ),
|
|
|
|
jetpack_connected: isJetpackConnected,
|
|
|
|
} );
|
|
|
|
}
|
2019-10-11 12:55:35 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
export function getAllTasks( {
|
2020-08-24 13:20:57 +00:00
|
|
|
activePlugins,
|
2020-08-03 08:22:25 +00:00
|
|
|
countryCode,
|
2020-08-24 13:20:57 +00:00
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins,
|
|
|
|
installedPlugins,
|
|
|
|
isJetpackConnected,
|
|
|
|
onboardingStatus,
|
2020-02-14 02:23:21 +00:00
|
|
|
profileItems,
|
|
|
|
query,
|
|
|
|
toggleCartModal,
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect,
|
2020-02-14 02:23:21 +00:00
|
|
|
} ) {
|
2019-10-11 12:55:35 +00:00
|
|
|
const {
|
2020-08-11 12:20:48 +00:00
|
|
|
hasPaymentGateway,
|
2019-10-11 12:55:35 +00:00
|
|
|
hasPhysicalProducts,
|
|
|
|
hasProducts,
|
2020-01-09 02:05:03 +00:00
|
|
|
isAppearanceComplete,
|
2019-10-11 12:55:35 +00:00
|
|
|
isTaxComplete,
|
|
|
|
shippingZonesCount,
|
2020-08-11 12:20:48 +00:00
|
|
|
wcPayIsConnected,
|
2020-08-24 13:20:57 +00:00
|
|
|
} = {
|
2020-08-11 12:20:48 +00:00
|
|
|
hasPaymentGateway: false,
|
2019-10-11 12:55:35 +00:00
|
|
|
hasPhysicalProducts: false,
|
|
|
|
hasProducts: false,
|
2020-01-09 02:05:03 +00:00
|
|
|
isAppearanceComplete: false,
|
2019-10-11 12:55:35 +00:00
|
|
|
isTaxComplete: false,
|
|
|
|
shippingZonesCount: 0,
|
2020-08-11 12:20:48 +00:00
|
|
|
wcPayIsConnected: false,
|
2020-08-24 13:20:57 +00:00
|
|
|
...onboardingStatus,
|
|
|
|
};
|
2019-10-11 12:55:35 +00:00
|
|
|
|
2020-08-03 19:24:57 +00:00
|
|
|
const groupedProducts = getCategorizedOnboardingProducts(
|
2020-05-25 00:26:08 +00:00
|
|
|
profileItems,
|
|
|
|
installedPlugins
|
|
|
|
);
|
2020-08-03 19:24:57 +00:00
|
|
|
const { products, remainingProducts, uniqueItemsList } = groupedProducts;
|
|
|
|
|
2020-07-14 01:40:56 +00:00
|
|
|
const woocommercePaymentsInstalled =
|
|
|
|
installedPlugins.indexOf( 'woocommerce-payments' ) !== -1;
|
2020-07-16 15:17:10 +00:00
|
|
|
const {
|
|
|
|
completed: profilerCompleted,
|
|
|
|
product_types: productTypes,
|
|
|
|
} = profileItems;
|
2020-07-14 01:40:56 +00:00
|
|
|
|
2020-12-01 11:55:27 +00:00
|
|
|
let purchaseAndInstallText = __( 'Add paid extensions to my store' );
|
2020-08-03 19:24:57 +00:00
|
|
|
|
|
|
|
if ( uniqueItemsList.length === 1 ) {
|
2020-12-01 11:55:27 +00:00
|
|
|
const { name: itemName } = uniqueItemsList[ 0 ];
|
|
|
|
const purchaseAndInstallFormat = __(
|
|
|
|
'Add %s to my store',
|
|
|
|
'woocommerce-admin'
|
|
|
|
);
|
2020-08-03 19:24:57 +00:00
|
|
|
purchaseAndInstallText = sprintf( purchaseAndInstallFormat, itemName );
|
|
|
|
}
|
|
|
|
|
2019-10-21 03:11:21 +00:00
|
|
|
const tasks = [
|
2020-05-27 16:08:39 +00:00
|
|
|
{
|
|
|
|
key: 'store_details',
|
2020-09-24 11:53:13 +00:00
|
|
|
title: __( 'Store details', 'woocommerce-admin' ),
|
2020-05-27 16:08:39 +00:00
|
|
|
container: null,
|
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'store_details' );
|
2020-08-27 12:10:23 +00:00
|
|
|
getHistory().push( getNewPath( {}, '/setup-wizard', {} ) );
|
2020-05-27 16:08:39 +00:00
|
|
|
},
|
2020-07-16 15:17:10 +00:00
|
|
|
completed: profilerCompleted,
|
2020-05-27 16:08:39 +00:00
|
|
|
visible: true,
|
|
|
|
time: __( '4 minutes', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2020-05-27 16:08:39 +00:00
|
|
|
},
|
2019-12-31 08:50:45 +00:00
|
|
|
{
|
|
|
|
key: 'purchase',
|
2020-08-03 19:24:57 +00:00
|
|
|
title: purchaseAndInstallText,
|
2019-12-31 08:50:45 +00:00
|
|
|
container: null,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'purchase' );
|
2020-08-03 19:24:57 +00:00
|
|
|
return remainingProducts.length ? toggleCartModal() : null;
|
2020-07-16 16:54:31 +00:00
|
|
|
},
|
2020-08-03 19:24:57 +00:00
|
|
|
visible: products.length,
|
|
|
|
completed: products.length && ! remainingProducts.length,
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
2020-07-14 10:46:25 +00:00
|
|
|
isDismissable: true,
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2019-12-31 08:50:45 +00:00
|
|
|
},
|
2019-10-11 12:55:35 +00:00
|
|
|
{
|
|
|
|
key: 'products',
|
2020-05-27 16:08:39 +00:00
|
|
|
title: __( 'Add my products', 'woocommerce-admin' ),
|
2019-10-11 12:55:35 +00:00
|
|
|
container: <Products />,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'products' );
|
2020-07-16 16:54:31 +00:00
|
|
|
updateQueryString( { task: 'products' } );
|
|
|
|
},
|
2019-10-11 12:55:35 +00:00
|
|
|
completed: hasProducts,
|
|
|
|
visible: true,
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '1 minute per product', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2019-10-11 12:55:35 +00:00
|
|
|
},
|
2020-07-14 01:40:56 +00:00
|
|
|
{
|
|
|
|
key: 'woocommerce-payments',
|
|
|
|
title: __( 'Set up WooCommerce Payments', 'woocommerce-admin' ),
|
|
|
|
container: <Fragment />,
|
2020-08-11 12:20:48 +00:00
|
|
|
completed: wcPayIsConnected,
|
2020-09-03 02:28:31 +00:00
|
|
|
onClick: async ( e ) => {
|
|
|
|
if ( e.target.nodeName === 'A' ) {
|
|
|
|
// This is a nested link, so don't activate the task.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-14 01:40:56 +00:00
|
|
|
await new Promise( ( resolve, reject ) => {
|
|
|
|
// This task doesn't have a view, so the recordEvent call
|
|
|
|
// in TaskDashboard.recordTaskView() is never called. So
|
|
|
|
// record it here.
|
|
|
|
recordTaskViewEvent(
|
|
|
|
'wcpay',
|
|
|
|
isJetpackConnected,
|
|
|
|
activePlugins,
|
|
|
|
installedPlugins
|
|
|
|
);
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'woocommerce-payments' );
|
2020-07-14 01:40:56 +00:00
|
|
|
return installActivateAndConnectWcpay(
|
|
|
|
resolve,
|
|
|
|
reject,
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
visible:
|
2020-08-03 08:22:25 +00:00
|
|
|
window.wcAdminFeatures.wcpay &&
|
|
|
|
woocommercePaymentsInstalled &&
|
|
|
|
countryCode === 'US',
|
2020-09-03 02:28:31 +00:00
|
|
|
additionalInfo: __(
|
|
|
|
'By setting up, you are agreeing to the <a href="https://wordpress.com/tos/" target="_blank">Terms of Service</a>',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
2020-07-14 01:40:56 +00:00
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2020-07-14 01:40:56 +00:00
|
|
|
},
|
2019-10-11 12:55:35 +00:00
|
|
|
{
|
2020-07-16 18:09:36 +00:00
|
|
|
key: 'payments',
|
|
|
|
title: __( 'Set up payments', 'woocommerce-admin' ),
|
|
|
|
container: <Payments />,
|
2020-08-11 12:20:48 +00:00
|
|
|
completed: hasPaymentGateway,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'payments' );
|
2020-07-16 18:09:36 +00:00
|
|
|
updateQueryString( { task: 'payments' } );
|
2020-07-16 16:54:31 +00:00
|
|
|
},
|
2020-09-23 12:55:19 +00:00
|
|
|
visible: ! woocommercePaymentsInstalled || countryCode !== 'US',
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2019-10-11 12:55:35 +00:00
|
|
|
},
|
2020-07-16 18:09:36 +00:00
|
|
|
{
|
|
|
|
key: 'tax',
|
|
|
|
title: __( 'Set up tax', 'woocommerce-admin' ),
|
|
|
|
container: <Tax />,
|
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'tax' );
|
2020-07-16 18:09:36 +00:00
|
|
|
updateQueryString( { task: 'tax' } );
|
|
|
|
},
|
|
|
|
completed: isTaxComplete,
|
|
|
|
visible: true,
|
|
|
|
time: __( '1 minute', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2020-07-16 18:09:36 +00:00
|
|
|
},
|
2019-10-11 12:55:35 +00:00
|
|
|
{
|
|
|
|
key: 'shipping',
|
|
|
|
title: __( 'Set up shipping', 'woocommerce-admin' ),
|
|
|
|
container: <Shipping />,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'shipping' );
|
2020-07-16 16:54:31 +00:00
|
|
|
updateQueryString( { task: 'shipping' } );
|
|
|
|
},
|
2020-10-09 20:28:41 +00:00
|
|
|
completed: shippingZonesCount > 0,
|
2019-10-17 14:39:59 +00:00
|
|
|
visible:
|
2020-07-16 15:17:10 +00:00
|
|
|
( productTypes && productTypes.includes( 'physical' ) ) ||
|
2019-10-17 14:39:59 +00:00
|
|
|
hasPhysicalProducts,
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '1 minute', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2019-10-11 12:55:35 +00:00
|
|
|
},
|
|
|
|
{
|
2020-07-16 18:09:36 +00:00
|
|
|
key: 'appearance',
|
|
|
|
title: __( 'Personalize my store', 'woocommerce-admin' ),
|
|
|
|
container: <Appearance />,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
onTaskSelect( 'appearance' );
|
2020-07-16 18:09:36 +00:00
|
|
|
updateQueryString( { task: 'appearance' } );
|
2020-07-16 16:54:31 +00:00
|
|
|
},
|
2020-07-16 18:09:36 +00:00
|
|
|
completed: isAppearanceComplete,
|
2019-10-11 12:55:35 +00:00
|
|
|
visible: true,
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
2020-12-03 21:16:04 +00:00
|
|
|
type: 'setup',
|
2019-10-11 12:55:35 +00:00
|
|
|
},
|
|
|
|
];
|
2020-12-11 02:29:45 +00:00
|
|
|
return groupListOfObjectsBy(
|
|
|
|
applyFilters( 'woocommerce_admin_onboarding_task_list', tasks, query ),
|
|
|
|
'type',
|
|
|
|
'extension'
|
2020-02-14 02:23:21 +00:00
|
|
|
);
|
2019-10-11 12:55:35 +00:00
|
|
|
}
|