/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { Button, Spinner } from '@wordpress/components';
import { updateQueryString } from '@woocommerce/navigation';
import { recordEvent } from '@woocommerce/tracks';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import { getPluginTrackKey } from '~/utils';
export const Action = ( {
hasSetup = false,
needsSetup = true,
id,
isEnabled = false,
isLoading = false,
isInstalled = false,
isRecommended = false,
hasPlugins,
manageUrl = null,
markConfigured,
onSetUp = () => {},
onSetupCallback,
setupButtonText = __( 'Get started', 'woocommerce' ),
externalLink = null,
} ) => {
const [ isBusy, setIsBusy ] = useState( false );
const classes = 'woocommerce-task-payment__action';
if ( isLoading ) {
return ;
}
const handleClick = async () => {
onSetUp( id );
recordEvent( 'tasklist_payment_setup', {
selected: getPluginTrackKey( id ),
} );
if ( ! hasPlugins && externalLink ) {
window.location.href = externalLink;
return;
}
if ( onSetupCallback ) {
setIsBusy( true );
await new Promise( onSetupCallback )
.then( () => {
setIsBusy( false );
} )
.catch( () => {
setIsBusy( false );
} );
return;
}
updateQueryString( {
id,
} );
};
const ManageButton = () => (
);
const SetupButton = () => (
);
const EnableButton = () => (
);
if ( ! hasSetup ) {
if ( ! isEnabled ) {
return ;
}
return ;
}
// This isolates core gateways that include setup
if ( ! hasPlugins ) {
if ( isEnabled ) {
return ;
}
return ;
}
if ( ! needsSetup ) {
if ( ! isEnabled ) {
return ;
}
return ;
}
if ( isInstalled && hasPlugins ) {
return (
);
}
return ;
};