2020-11-06 01:21:05 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { SETTINGS_STORE_NAME, ITEMS_STORE_NAME } from '@woocommerce/data';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { DEFAULT_ACTIONABLE_STATUSES } from '../../../analytics/settings/config';
|
|
|
|
|
2020-11-06 16:50:24 +00:00
|
|
|
export function getUnreadOrders( select, orderStatuses ) {
|
2020-11-06 01:21:05 +00:00
|
|
|
const { getItemsTotalCount, getItemsError, isResolving } = select(
|
|
|
|
ITEMS_STORE_NAME
|
|
|
|
);
|
|
|
|
|
|
|
|
if ( ! orderStatuses.length ) {
|
2020-11-11 20:28:44 +00:00
|
|
|
return 0;
|
2020-11-06 01:21:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ordersQuery = {
|
|
|
|
page: 1,
|
|
|
|
per_page: 1, // Core endpoint requires per_page > 0.
|
|
|
|
status: orderStatuses,
|
|
|
|
_fields: [ 'id' ],
|
|
|
|
};
|
|
|
|
|
|
|
|
// Disable eslint rule requiring `latestNote` to be defined below because the next two statements
|
|
|
|
// depend on `getItemsTotalCount` to have been called.
|
|
|
|
// eslint-disable-next-line @wordpress/no-unused-vars-before-return
|
|
|
|
const totalOrders = getItemsTotalCount( 'orders', ordersQuery );
|
|
|
|
const isError = Boolean( getItemsError( 'orders', ordersQuery ) );
|
|
|
|
const isRequesting = isResolving( 'getItemsTotalCount', [
|
|
|
|
'orders',
|
|
|
|
ordersQuery,
|
|
|
|
] );
|
|
|
|
|
|
|
|
if ( isError || isRequesting ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return totalOrders;
|
|
|
|
}
|
2020-11-06 16:50:24 +00:00
|
|
|
|
|
|
|
export function getOrderStatuses( select ) {
|
|
|
|
const { getSetting: getMutableSetting } = select( SETTINGS_STORE_NAME );
|
|
|
|
const {
|
|
|
|
woocommerce_actionable_order_statuses: orderStatuses = DEFAULT_ACTIONABLE_STATUSES,
|
|
|
|
} = getMutableSetting( 'wc_admin', 'wcAdminSettings', {} );
|
|
|
|
return orderStatuses;
|
|
|
|
}
|