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">
|
2023-03-24 04:26:13 +00:00
|
|
|
{ ( {
|
|
|
|
defaultTaskItem: DefaultTaskItem,
|
|
|
|
}: {
|
|
|
|
defaultTaskItem: ( props: {
|
|
|
|
onClick: () => void;
|
|
|
|
} ) => JSX.Element;
|
|
|
|
} ) => (
|
2021-09-21 19:33:44 +00:00
|
|
|
<DefaultTaskItem
|
2024-07-02 15:45:27 +00:00
|
|
|
// Intercept the click on the task list item so that we don't have to see an intermediate page before installing WooPayments.
|
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', {
|
2023-03-24 04:26:13 +00:00
|
|
|
// @ts-expect-error scope is not defined in the type definition but it is a valid property
|
2021-09-21 19:33:44 +00:00
|
|
|
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', {
|
2023-03-24 04:26:13 +00:00
|
|
|
// @ts-expect-error scope is not defined in the type definition but it is a valid property
|
2022-06-24 09:06:43 +00:00
|
|
|
scope: 'woocommerce-tasks',
|
|
|
|
render: WoocommercePaymentsTaskPage,
|
|
|
|
} );
|