2019-05-07 07:18:48 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Button } from '@wordpress/components';
|
|
|
|
import { Fragment } from '@wordpress/element';
|
|
|
|
|
|
|
|
function HistoricalDataActions( {
|
|
|
|
customersProgress,
|
|
|
|
customersTotal,
|
|
|
|
hasImportedData,
|
|
|
|
inProgress,
|
2019-05-09 09:11:58 +00:00
|
|
|
onDeletePreviousData,
|
|
|
|
onStartImport,
|
|
|
|
onStopImport,
|
2019-05-07 07:18:48 +00:00
|
|
|
ordersProgress,
|
|
|
|
ordersTotal,
|
|
|
|
} ) {
|
|
|
|
const getActions = () => {
|
|
|
|
// An import is currently in progress
|
|
|
|
if ( inProgress ) {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Button
|
|
|
|
className="woocommerce-settings-historical-data__action-button"
|
|
|
|
isPrimary
|
2019-05-09 09:11:58 +00:00
|
|
|
onClick={ onStopImport }
|
2019-05-07 07:18:48 +00:00
|
|
|
>
|
|
|
|
{ __( 'Stop Import', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
<div className="woocommerce-setting__help woocommerce-settings-historical-data__action-help">
|
|
|
|
{ __(
|
|
|
|
'Imported data will not be lost if the import is stopped.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
<br />
|
|
|
|
{ __(
|
|
|
|
'Navigating away from this page will not affect the import.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has no imported data
|
|
|
|
if ( ! hasImportedData ) {
|
|
|
|
return (
|
2019-05-09 09:11:58 +00:00
|
|
|
<Button isPrimary onClick={ onStartImport }>
|
2019-05-07 07:18:48 +00:00
|
|
|
{ __( 'Start', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has imported all possible data
|
|
|
|
if ( customersProgress === customersTotal && ordersProgress === ordersTotal ) {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Button isDefault onClick={ () => null }>
|
|
|
|
{ __( 'Re-import Data', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
2019-05-09 09:11:58 +00:00
|
|
|
<Button isDefault onClick={ onDeletePreviousData }>
|
2019-05-07 07:18:48 +00:00
|
|
|
{ __( 'Delete Previously Imported Data', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// It's not in progress and has some imported data
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-05-09 09:11:58 +00:00
|
|
|
<Button isPrimary onClick={ onStartImport }>
|
2019-05-07 07:18:48 +00:00
|
|
|
{ __( 'Start', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
2019-05-09 09:11:58 +00:00
|
|
|
<Button isDefault onClick={ onDeletePreviousData }>
|
2019-05-07 07:18:48 +00:00
|
|
|
{ __( 'Delete Previously Imported Data', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-settings__actions woocommerce-settings-historical-data__actions">
|
|
|
|
{ getActions() }
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HistoricalDataActions;
|