2018-10-11 23:33:18 +00:00
|
|
|
/** @format */
|
2018-10-12 19:20:48 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { dispatch } from '@wordpress/data';
|
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
|
2018-11-05 21:02:04 +00:00
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
|
|
|
import { stringifyQuery } from '@woocommerce/navigation';
|
|
|
|
|
2018-10-16 19:46:00 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { NAMESPACE } from 'store/constants';
|
|
|
|
|
2018-10-12 19:20:48 +00:00
|
|
|
export default {
|
2018-11-05 23:30:32 +00:00
|
|
|
// TODO: Use controls data plugin or fresh-data instead of async
|
|
|
|
async getNotes( ...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-10-12 19:20:48 +00:00
|
|
|
try {
|
2018-10-16 19:46:00 +00:00
|
|
|
const notes = await apiFetch( { path: NAMESPACE + 'admin/notes' + stringifyQuery( query ) } );
|
|
|
|
dispatch( 'wc-admin' ).setNotes( notes, query );
|
2018-10-12 19:20:48 +00:00
|
|
|
} catch ( error ) {
|
2018-10-16 19:46:00 +00:00
|
|
|
dispatch( 'wc-admin' ).setNotesError( query );
|
2018-10-12 19:20:48 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|