2018-07-05 03:14:40 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { dispatch } from '@wordpress/data';
|
2018-08-21 19:02:49 +00:00
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
2018-07-05 03:14:40 +00:00
|
|
|
|
2018-11-05 21:02:04 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { stringifyQuery } from '@woocommerce/navigation';
|
|
|
|
|
2018-10-16 08:50:07 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { NAMESPACE } from 'store/constants';
|
|
|
|
|
2018-07-05 03:14:40 +00:00
|
|
|
export default {
|
2018-11-05 23:30:32 +00:00
|
|
|
// TODO: Use controls data plugin or fresh-data instead of async
|
|
|
|
async getOrders( ...args ) {
|
|
|
|
// This is interim code to work with either 2.x or 3.x version of @wordpress/data
|
|
|
|
// TODO: Change to just `getNotes( query )` after Gutenberg plugin uses @wordpress/data 3+
|
|
|
|
const query = args.length === 1 ? args[ 0 ] : args[ 1 ];
|
|
|
|
|
2018-07-05 03:14:40 +00:00
|
|
|
try {
|
2018-10-16 08:50:07 +00:00
|
|
|
const orders = await apiFetch( { path: NAMESPACE + 'orders' + stringifyQuery( query ) } );
|
|
|
|
dispatch( 'wc-admin' ).setOrders( orders, query );
|
2018-07-05 03:14:40 +00:00
|
|
|
} catch ( error ) {
|
2018-10-16 08:50:07 +00:00
|
|
|
dispatch( 'wc-admin' ).setOrdersError( query );
|
2018-07-05 03:14:40 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|