2019-05-20 20:50:25 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-06-11 12:47:53 +00:00
|
|
|
import { isNil } from 'lodash';
|
2019-05-20 20:50:25 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
|
2019-06-11 12:47:53 +00:00
|
|
|
export const formatParams = ( dateFormat, period, skipChecked ) => {
|
2019-05-20 20:50:25 +00:00
|
|
|
const params = {};
|
|
|
|
if ( skipChecked ) {
|
|
|
|
params.skip_existing = true;
|
|
|
|
}
|
|
|
|
if ( period.label !== 'all' ) {
|
|
|
|
if ( period.label === 'custom' ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
const daysDifference = moment().diff(
|
|
|
|
moment( period.date, dateFormat ),
|
|
|
|
'days',
|
|
|
|
true
|
|
|
|
);
|
2019-06-11 12:47:53 +00:00
|
|
|
params.days = Math.floor( daysDifference );
|
2019-05-20 20:50:25 +00:00
|
|
|
} else {
|
|
|
|
params.days = parseInt( period.label, 10 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return params;
|
|
|
|
};
|
2019-06-11 12:47:53 +00:00
|
|
|
|
|
|
|
export const getStatus = ( {
|
|
|
|
customersProgress,
|
|
|
|
customersTotal,
|
|
|
|
inProgress,
|
|
|
|
ordersProgress,
|
|
|
|
ordersTotal,
|
|
|
|
} ) => {
|
|
|
|
if ( inProgress ) {
|
|
|
|
if (
|
|
|
|
isNil( customersProgress ) ||
|
|
|
|
isNil( ordersProgress ) ||
|
|
|
|
isNil( customersTotal ) ||
|
|
|
|
isNil( ordersTotal )
|
|
|
|
) {
|
|
|
|
return 'initializing';
|
|
|
|
}
|
|
|
|
if ( customersProgress < customersTotal ) {
|
|
|
|
return 'customers';
|
|
|
|
}
|
|
|
|
if ( ordersProgress < ordersTotal ) {
|
|
|
|
return 'orders';
|
|
|
|
}
|
|
|
|
return 'finalizing';
|
|
|
|
}
|
|
|
|
if ( customersTotal > 0 || ordersTotal > 0 ) {
|
2020-02-14 02:23:21 +00:00
|
|
|
if (
|
|
|
|
customersProgress === customersTotal &&
|
|
|
|
ordersProgress === ordersTotal
|
|
|
|
) {
|
2019-06-11 12:47:53 +00:00
|
|
|
return 'finished';
|
|
|
|
}
|
|
|
|
return 'ready';
|
|
|
|
}
|
|
|
|
return 'nothing';
|
|
|
|
};
|