2021-09-21 19:33:44 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-06-24 09:06:43 +00:00
|
|
|
import React, { useEffect } from 'react';
|
2021-09-21 19:33:44 +00:00
|
|
|
import { registerPlugin } from '@wordpress/plugins';
|
2022-06-24 09:06:43 +00:00
|
|
|
import {
|
|
|
|
WooOnboardingTaskListItem,
|
|
|
|
WooOnboardingTask,
|
|
|
|
} from '@woocommerce/onboarding';
|
2021-09-21 19:33:44 +00:00
|
|
|
import { PLUGINS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
import { useDispatch } from '@wordpress/data';
|
2022-06-24 09:06:43 +00:00
|
|
|
import { Spinner } from '@woocommerce/components';
|
2021-09-21 19:33:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { installActivateAndConnectWcpay } from './PaymentGatewaySuggestions/components/WCPay';
|
|
|
|
|
|
|
|
const WoocommercePaymentsTaskItem = () => {
|
|
|
|
const { installAndActivatePlugins } = useDispatch( PLUGINS_STORE_NAME );
|
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<WooOnboardingTaskListItem id="woocommerce-payments">
|
|
|
|
{ ( { defaultTaskItem: DefaultTaskItem } ) => (
|
|
|
|
<DefaultTaskItem
|
2022-06-24 09:06:43 +00:00
|
|
|
// intercept the click on the task list item so that we don't have to see a intermediate page before installing woocommerce payments
|
2021-09-21 19:33:44 +00:00
|
|
|
onClick={ () => {
|
|
|
|
return new Promise( ( resolve, reject ) => {
|
|
|
|
return installActivateAndConnectWcpay(
|
|
|
|
reject,
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
</WooOnboardingTaskListItem>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
registerPlugin( 'woocommerce-admin-task-wcpay', {
|
|
|
|
scope: 'woocommerce-tasks',
|
|
|
|
render: WoocommercePaymentsTaskItem,
|
|
|
|
} );
|
2022-06-24 09:06:43 +00:00
|
|
|
|
|
|
|
const ReadyWcPay = () => {
|
|
|
|
const { installAndActivatePlugins } = useDispatch( PLUGINS_STORE_NAME );
|
|
|
|
const { createNotice } = useDispatch( 'core/notices' );
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
new Promise( ( resolve, reject ) => {
|
|
|
|
return installActivateAndConnectWcpay(
|
|
|
|
reject,
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
}, [ createNotice, installAndActivatePlugins ] );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
style={ {
|
|
|
|
height: '70vh',
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
<Spinner />
|
|
|
|
<div style={ { marginTop: '1rem' } }>
|
|
|
|
Preparing payment settings...
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
// shows up at http://host/wp-admin/admin.php?page=wc-admin&task=woocommerce-payments which is the default url for woocommerce-payments task
|
|
|
|
const WoocommercePaymentsTaskPage = () => (
|
|
|
|
<WooOnboardingTask id="woocommerce-payments">
|
|
|
|
<ReadyWcPay />
|
|
|
|
</WooOnboardingTask>
|
|
|
|
);
|
|
|
|
|
|
|
|
registerPlugin( 'woocommerce-admin-task-wcpay-page', {
|
|
|
|
scope: 'woocommerce-tasks',
|
|
|
|
render: WoocommercePaymentsTaskPage,
|
|
|
|
} );
|