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( {
|
2019-06-11 12:47:53 +00:00
|
|
|
importDate,
|
2019-05-09 09:11:58 +00:00
|
|
|
onDeletePreviousData,
|
2019-06-11 12:47:53 +00:00
|
|
|
onReimportData,
|
2019-05-09 09:11:58 +00:00
|
|
|
onStartImport,
|
|
|
|
onStopImport,
|
2019-06-11 12:47:53 +00:00
|
|
|
status,
|
2019-05-07 07:18:48 +00:00
|
|
|
} ) {
|
|
|
|
const getActions = () => {
|
2019-06-11 12:47:53 +00:00
|
|
|
const importDisabled = status !== 'ready';
|
|
|
|
|
2019-05-07 07:18:48 +00:00
|
|
|
// An import is currently in progress
|
2019-06-11 12:47:53 +00:00
|
|
|
if ( [ 'initializing', 'customers', 'orders', 'finalizing' ].includes( status ) ) {
|
2019-05-07 07:18:48 +00:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-11 12:47:53 +00:00
|
|
|
if ( [ 'ready', 'nothing' ].includes( status ) ) {
|
|
|
|
if ( importDate ) {
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Button isPrimary onClick={ onStartImport } disabled={ importDisabled }>
|
|
|
|
{ __( 'Start', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
<Button isDefault onClick={ onDeletePreviousData }>
|
|
|
|
{ __( 'Delete Previously Imported Data', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-05-07 07:18:48 +00:00
|
|
|
return (
|
2019-05-10 09:34:03 +00:00
|
|
|
<Fragment>
|
2019-06-11 12:47:53 +00:00
|
|
|
<Button isPrimary onClick={ onStartImport } disabled={ importDisabled }>
|
2019-05-10 09:34:03 +00:00
|
|
|
{ __( 'Start', 'woocommerce-admin' ) }
|
|
|
|
</Button>
|
|
|
|
</Fragment>
|
2019-05-07 07:18:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Has imported all possible data
|
|
|
|
return (
|
|
|
|
<Fragment>
|
2019-06-11 12:47:53 +00:00
|
|
|
<Button isDefault onClick={ onReimportData }>
|
|
|
|
{ __( 'Re-import Data', 'woocommerce-admin' ) }
|
2019-05-07 07:18:48 +00:00
|
|
|
</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;
|