Use WC regular endpoint instead of reports endpoint to load customers autocompleter suggestions
This commit is contained in:
parent
d9fe77de24
commit
ce080f4fe0
|
@ -13,7 +13,6 @@ import { stringifyQuery } from '@woocommerce/navigation';
|
||||||
* Internal dependencies
|
* Internal dependencies
|
||||||
*/
|
*/
|
||||||
import { computeSuggestionMatch } from './utils';
|
import { computeSuggestionMatch } from './utils';
|
||||||
import { SWAGGERNAMESPACE } from 'store/constants';
|
|
||||||
|
|
||||||
const getName = customer => customer.first_name + ' ' + customer.last_name;
|
const getName = customer => customer.first_name + ' ' + customer.last_name;
|
||||||
|
|
||||||
|
@ -26,7 +25,7 @@ const getName = customer => customer.first_name + ' ' + customer.last_name;
|
||||||
export default {
|
export default {
|
||||||
name: 'customers',
|
name: 'customers',
|
||||||
className: 'woocommerce-search__customers-result',
|
className: 'woocommerce-search__customers-result',
|
||||||
async options( name ) {
|
options( name ) {
|
||||||
let payload = '';
|
let payload = '';
|
||||||
if ( name ) {
|
if ( name ) {
|
||||||
const query = {
|
const query = {
|
||||||
|
@ -35,17 +34,7 @@ export default {
|
||||||
};
|
};
|
||||||
payload = stringifyQuery( query );
|
payload = stringifyQuery( query );
|
||||||
}
|
}
|
||||||
// TODO: Use wc endpoint when it's ready
|
return apiFetch( { path: `/wc/v3/customers${ payload }` } );
|
||||||
const response = await fetch( SWAGGERNAMESPACE + 'reports/customers' + payload );
|
|
||||||
// const customers = await apiFetch( { path: `/wc/v3/reports/customers${ payload }` } );
|
|
||||||
const customers = await response.json();
|
|
||||||
const ids = customers.map( customer => customer.id );
|
|
||||||
// @TODO load customers names from WC endpoint
|
|
||||||
return ids.map( id => ( {
|
|
||||||
id,
|
|
||||||
first_name: 'Customer ' + id,
|
|
||||||
last_name: '',
|
|
||||||
} ) );
|
|
||||||
},
|
},
|
||||||
isDebounced: true,
|
isDebounced: true,
|
||||||
getOptionKeywords( customer ) {
|
getOptionKeywords( customer ) {
|
||||||
|
|
Loading…
Reference in New Issue