Merge pull request woocommerce/woocommerce-admin#1271 from woocommerce/update/customer-report-real-endpoint
Hook up customers report table to real data.
This commit is contained in:
commit
571ee1fee0
|
@ -18,7 +18,7 @@ export const filters = [
|
|||
param: 'filter',
|
||||
showFilters: () => true,
|
||||
filters: [
|
||||
{ label: __( 'All Registered Customers', 'wc-admin' ), value: 'all' },
|
||||
{ label: __( 'All Customers', 'wc-admin' ), value: 'all' },
|
||||
{ label: __( 'Advanced Filters', 'wc-admin' ), value: 'advanced' },
|
||||
],
|
||||
},
|
||||
|
|
|
@ -19,6 +19,11 @@ import CustomersReportTable from './table';
|
|||
export default class CustomersReport extends Component {
|
||||
render() {
|
||||
const { query, path } = this.props;
|
||||
const tableQuery = {
|
||||
orderby: 'date_registered',
|
||||
order: 'desc',
|
||||
...query,
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
|
@ -29,7 +34,7 @@ export default class CustomersReport extends Component {
|
|||
showDatePicker={ false }
|
||||
advancedFilters={ advancedFilters }
|
||||
/>
|
||||
<CustomersReportTable query={ query } />
|
||||
<CustomersReportTable query={ tableQuery } />
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ export default class CustomersReportTable extends Component {
|
|||
},
|
||||
{
|
||||
label: __( 'Sign Up', 'wc-admin' ),
|
||||
key: 'date_sign_up',
|
||||
key: 'date_registered',
|
||||
defaultSort: true,
|
||||
isSortable: true,
|
||||
},
|
||||
|
@ -95,26 +95,31 @@ export default class CustomersReportTable extends Component {
|
|||
return customers.map( customer => {
|
||||
const {
|
||||
avg_order_value,
|
||||
billing,
|
||||
date_last_active,
|
||||
date_sign_up,
|
||||
date_registered,
|
||||
email,
|
||||
first_name,
|
||||
id,
|
||||
last_name,
|
||||
name,
|
||||
user_id,
|
||||
orders_count,
|
||||
username,
|
||||
total_spend,
|
||||
postcode,
|
||||
city,
|
||||
country,
|
||||
} = customer;
|
||||
const { postcode, city, country } = billing || {};
|
||||
const name = `${ first_name } ${ last_name }`;
|
||||
|
||||
const customerNameLink = (
|
||||
<Link href={ 'user-edit.php?user_id=' + id } type="wp-admin">
|
||||
const customerNameLink = user_id ? (
|
||||
<Link href={ 'user-edit.php?user_id=' + user_id } type="wp-admin">
|
||||
{ name }
|
||||
</Link>
|
||||
) : (
|
||||
name
|
||||
);
|
||||
|
||||
const dateRegistered = date_registered
|
||||
? formatDate( defaultTableDateFormat, date_registered )
|
||||
: '—';
|
||||
|
||||
return [
|
||||
{
|
||||
display: customerNameLink,
|
||||
|
@ -125,8 +130,8 @@ export default class CustomersReportTable extends Component {
|
|||
value: username,
|
||||
},
|
||||
{
|
||||
display: formatDate( defaultTableDateFormat, date_sign_up ),
|
||||
value: date_sign_up,
|
||||
display: dateRegistered,
|
||||
value: date_registered,
|
||||
},
|
||||
{
|
||||
display: <a href={ 'mailto:' + email }>{ email }</a>,
|
||||
|
@ -182,7 +187,7 @@ export default class CustomersReportTable extends Component {
|
|||
labels={ { placeholder: __( 'Search by customer name', 'wc-admin' ) } }
|
||||
searchBy="customers"
|
||||
searchParam="name_includes"
|
||||
title={ __( 'Registered Customers', 'wc-admin' ) }
|
||||
title={ __( 'Customers', 'wc-admin' ) }
|
||||
columnPrefsKey="customers_report_columns"
|
||||
/>
|
||||
);
|
||||
|
|
|
@ -14,10 +14,6 @@ import { stringifyQuery } from '@woocommerce/navigation';
|
|||
*/
|
||||
import { getResourceIdentifier, getResourcePrefix } from '../../utils';
|
||||
import { NAMESPACE } from '../../constants';
|
||||
import { SWAGGERNAMESPACE } from 'store/constants';
|
||||
|
||||
// TODO: Remove once swagger endpoints are phased out.
|
||||
const swaggerEndpoints = [ 'customers' ];
|
||||
|
||||
const typeEndpointMap = {
|
||||
'report-items-query-orders': 'orders',
|
||||
|
@ -42,17 +38,11 @@ function read( resourceNames, fetch = apiFetch ) {
|
|||
const prefix = getResourcePrefix( resourceName );
|
||||
const endpoint = typeEndpointMap[ prefix ];
|
||||
const query = getResourceIdentifier( resourceName );
|
||||
|
||||
const fetchArgs = {
|
||||
parse: false,
|
||||
path: NAMESPACE + '/reports/' + endpoint + stringifyQuery( query ),
|
||||
};
|
||||
|
||||
if ( swaggerEndpoints.indexOf( endpoint ) >= 0 ) {
|
||||
fetchArgs.url = SWAGGERNAMESPACE + 'reports/' + endpoint + stringifyQuery( query );
|
||||
} else {
|
||||
fetchArgs.path = NAMESPACE + '/reports/' + endpoint + stringifyQuery( query );
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch( fetchArgs );
|
||||
const report = await response.json();
|
||||
|
|
Loading…
Reference in New Issue