2019-10-11 12:55:35 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-10-21 03:11:21 +00:00
|
|
|
import { applyFilters } from '@wordpress/hooks';
|
2019-10-11 12:55:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2019-11-22 17:07:26 +00:00
|
|
|
import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
|
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';
|
2019-10-11 12:55:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Appearance from './tasks/appearance';
|
2019-12-31 08:50:45 +00:00
|
|
|
import { getProductIdsForCart } 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';
|
|
|
|
import { recordEvent } from 'lib/tracks';
|
|
|
|
|
|
|
|
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( {
|
|
|
|
profileItems,
|
2020-06-10 23:49:27 +00:00
|
|
|
taskListPayments,
|
2020-02-14 02:23:21 +00:00
|
|
|
query,
|
|
|
|
toggleCartModal,
|
2020-07-14 01:40:56 +00:00
|
|
|
activePlugins,
|
2020-05-25 00:26:08 +00:00
|
|
|
installedPlugins,
|
2020-07-14 01:40:56 +00:00
|
|
|
installAndActivatePlugins,
|
|
|
|
createNotice,
|
|
|
|
isJetpackConnected,
|
2020-02-14 02:23:21 +00:00
|
|
|
} ) {
|
2019-10-11 12:55:35 +00:00
|
|
|
const {
|
|
|
|
hasPhysicalProducts,
|
|
|
|
hasProducts,
|
2020-01-09 02:05:03 +00:00
|
|
|
isAppearanceComplete,
|
2019-10-11 12:55:35 +00:00
|
|
|
isTaxComplete,
|
|
|
|
shippingZonesCount,
|
|
|
|
} = getSetting( 'onboarding', {
|
|
|
|
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-05-25 00:26:08 +00:00
|
|
|
const productIds = getProductIdsForCart(
|
|
|
|
profileItems,
|
|
|
|
true,
|
|
|
|
installedPlugins
|
|
|
|
);
|
|
|
|
const remainingProductIds = getProductIdsForCart(
|
|
|
|
profileItems,
|
|
|
|
false,
|
|
|
|
installedPlugins
|
|
|
|
);
|
2019-12-31 08:50:45 +00:00
|
|
|
|
2020-06-10 23:49:27 +00:00
|
|
|
const paymentsCompleted = Boolean(
|
|
|
|
taskListPayments && taskListPayments.completed
|
2019-10-11 12:55:35 +00:00
|
|
|
);
|
2020-06-10 23:49:27 +00:00
|
|
|
const paymentsSkipped = Boolean(
|
|
|
|
taskListPayments && taskListPayments.skipped
|
2020-05-04 11:33:11 +00:00
|
|
|
);
|
2019-10-11 12:55:35 +00:00
|
|
|
|
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
|
|
|
|
2019-10-21 03:11:21 +00:00
|
|
|
const tasks = [
|
2020-05-27 16:08:39 +00:00
|
|
|
{
|
|
|
|
key: 'store_details',
|
|
|
|
title: __( 'Store details', 'woocommerce-admin' ),
|
|
|
|
container: null,
|
|
|
|
onClick: () => {
|
2020-07-16 16:54:31 +00:00
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: 'store_details',
|
|
|
|
} );
|
2020-07-16 15:17:10 +00:00
|
|
|
getHistory().push( getNewPath( {}, `/profiler`, {} ) );
|
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' ),
|
|
|
|
},
|
2019-12-31 08:50:45 +00:00
|
|
|
{
|
|
|
|
key: 'purchase',
|
|
|
|
title: __( 'Purchase & install extensions', 'woocommerce-admin' ),
|
|
|
|
container: null,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: 'purchase',
|
|
|
|
} );
|
|
|
|
return remainingProductIds.length ? toggleCartModal() : null;
|
|
|
|
},
|
2019-12-31 08:50:45 +00:00
|
|
|
visible: productIds.length,
|
2020-06-15 22:38:36 +00:00
|
|
|
completed: productIds.length && ! remainingProductIds.length,
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
2020-07-14 10:46:25 +00:00
|
|
|
isDismissable: true,
|
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: () => {
|
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: 'products',
|
|
|
|
} );
|
|
|
|
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' ),
|
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 />,
|
|
|
|
completed: paymentsCompleted || paymentsSkipped,
|
|
|
|
onClick: async () => {
|
|
|
|
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-07-16 16:54:31 +00:00
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: 'woocommerce-payments',
|
|
|
|
} );
|
2020-07-14 01:40:56 +00:00
|
|
|
return installActivateAndConnectWcpay(
|
|
|
|
resolve,
|
|
|
|
reject,
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
},
|
|
|
|
visible:
|
|
|
|
window.wcAdminFeatures.wcpay && woocommercePaymentsInstalled,
|
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
|
|
|
},
|
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 />,
|
|
|
|
completed: paymentsCompleted || paymentsSkipped,
|
2020-07-16 16:54:31 +00:00
|
|
|
onClick: () => {
|
|
|
|
recordEvent( 'tasklist_click', {
|
2020-07-16 18:09:36 +00:00
|
|
|
task_name: 'payments',
|
2020-07-16 16:54:31 +00:00
|
|
|
} );
|
2020-07-16 18:09:36 +00:00
|
|
|
if ( paymentsCompleted || paymentsSkipped ) {
|
|
|
|
window.location = getAdminLink(
|
|
|
|
'admin.php?page=wc-settings&tab=checkout'
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
updateQueryString( { task: 'payments' } );
|
2020-07-16 16:54:31 +00:00
|
|
|
},
|
2020-07-16 18:09:36 +00:00
|
|
|
visible: ! woocommercePaymentsInstalled,
|
2020-05-27 16:08:39 +00:00
|
|
|
time: __( '2 minutes', 'woocommerce-admin' ),
|
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: () => {
|
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: 'tax',
|
|
|
|
} );
|
|
|
|
updateQueryString( { task: 'tax' } );
|
|
|
|
},
|
|
|
|
completed: isTaxComplete,
|
|
|
|
visible: true,
|
|
|
|
time: __( '1 minute', 'woocommerce-admin' ),
|
|
|
|
},
|
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: () => {
|
|
|
|
recordEvent( 'tasklist_click', {
|
|
|
|
task_name: 'shipping',
|
|
|
|
} );
|
|
|
|
updateQueryString( { task: 'shipping' } );
|
|
|
|
},
|
2019-10-11 12:55:35 +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' ),
|
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: () => {
|
|
|
|
recordEvent( 'tasklist_click', {
|
2020-07-16 18:09:36 +00:00
|
|
|
task_name: 'appearance',
|
2020-07-16 16:54:31 +00:00
|
|
|
} );
|
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' ),
|
2019-10-11 12:55:35 +00:00
|
|
|
},
|
|
|
|
];
|
2019-10-21 03:11:21 +00:00
|
|
|
|
2020-02-14 02:23:21 +00:00
|
|
|
return applyFilters(
|
|
|
|
'woocommerce_admin_onboarding_task_list',
|
|
|
|
tasks,
|
|
|
|
query
|
|
|
|
);
|
2019-10-11 12:55:35 +00:00
|
|
|
}
|