2018-12-06 22:21:46 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { Component } from '@wordpress/element';
|
|
|
|
import { format as formatDate } from '@wordpress/date';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2019-01-09 00:24:49 +00:00
|
|
|
import { defaultTableDateFormat } from '@woocommerce/date';
|
2018-12-06 22:21:46 +00:00
|
|
|
import { formatCurrency, getCurrencyFormatDecimal } from '@woocommerce/currency';
|
|
|
|
import { Link } from '@woocommerce/components';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ReportTable from 'analytics/components/report-table';
|
|
|
|
import { numberFormat } from 'lib/number';
|
|
|
|
|
|
|
|
export default class CustomersReportTable extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.getHeadersContent = this.getHeadersContent.bind( this );
|
|
|
|
this.getRowsContent = this.getRowsContent.bind( this );
|
|
|
|
}
|
|
|
|
|
|
|
|
getHeadersContent() {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
label: __( 'Name', 'wc-admin' ),
|
|
|
|
key: 'name',
|
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Username', 'wc-admin' ),
|
|
|
|
key: 'username',
|
|
|
|
hiddenByDefault: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Sign Up', 'wc-admin' ),
|
|
|
|
key: 'date_sign_up',
|
|
|
|
defaultSort: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Email', 'wc-admin' ),
|
|
|
|
key: 'email',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Orders', 'wc-admin' ),
|
|
|
|
key: 'orders_count',
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Lifetime Spend', 'wc-admin' ),
|
|
|
|
key: 'total_spend',
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2018-12-10 15:23:02 +00:00
|
|
|
label: __( 'AOV', 'wc-admin' ),
|
|
|
|
screenReaderLabel: __( 'Average Order Value', 'wc-admin' ),
|
2018-12-12 14:46:40 +00:00
|
|
|
key: 'avg_order_value',
|
2018-12-06 22:21:46 +00:00
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Last Active', 'wc-admin' ),
|
|
|
|
key: 'date_last_active',
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Country', 'wc-admin' ),
|
|
|
|
key: 'country',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'City', 'wc-admin' ),
|
|
|
|
key: 'city',
|
|
|
|
hiddenByDefault: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: __( 'Postal Code', 'wc-admin' ),
|
|
|
|
key: 'postal_code',
|
|
|
|
hiddenByDefault: true,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
getRowsContent( customers ) {
|
|
|
|
return customers.map( customer => {
|
|
|
|
const {
|
2018-12-12 14:46:40 +00:00
|
|
|
avg_order_value,
|
2018-12-12 12:55:10 +00:00
|
|
|
billing,
|
2018-12-06 22:21:46 +00:00
|
|
|
date_last_active,
|
|
|
|
date_sign_up,
|
|
|
|
email,
|
2018-12-12 12:55:10 +00:00
|
|
|
first_name,
|
|
|
|
id,
|
|
|
|
last_name,
|
2018-12-06 22:21:46 +00:00
|
|
|
orders_count,
|
|
|
|
username,
|
|
|
|
total_spend,
|
|
|
|
} = customer;
|
2018-12-12 12:55:10 +00:00
|
|
|
const { postcode, city, country } = billing || {};
|
|
|
|
const name = `${ first_name } ${ last_name }`;
|
2018-12-06 22:21:46 +00:00
|
|
|
|
|
|
|
const customerNameLink = (
|
|
|
|
<Link href={ 'user-edit.php?user_id=' + id } type="wp-admin">
|
|
|
|
{ name }
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: customerNameLink,
|
|
|
|
value: name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: username,
|
|
|
|
value: username,
|
|
|
|
},
|
|
|
|
{
|
2019-01-09 00:24:49 +00:00
|
|
|
display: formatDate( defaultTableDateFormat, date_sign_up ),
|
2018-12-06 22:21:46 +00:00
|
|
|
value: date_sign_up,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: <a href={ 'mailto:' + email }>{ email }</a>,
|
|
|
|
value: email,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: numberFormat( orders_count ),
|
|
|
|
value: orders_count,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: formatCurrency( total_spend ),
|
|
|
|
value: getCurrencyFormatDecimal( total_spend ),
|
|
|
|
},
|
|
|
|
{
|
2018-12-12 14:46:40 +00:00
|
|
|
display: formatCurrency( avg_order_value ),
|
|
|
|
value: getCurrencyFormatDecimal( avg_order_value ),
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
{
|
2019-01-09 00:24:49 +00:00
|
|
|
display: formatDate( defaultTableDateFormat, date_last_active ),
|
2018-12-06 22:21:46 +00:00
|
|
|
value: date_last_active,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: country,
|
|
|
|
value: country,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: city,
|
|
|
|
value: city,
|
|
|
|
},
|
|
|
|
{
|
2018-12-12 12:55:10 +00:00
|
|
|
display: postcode,
|
|
|
|
value: postcode,
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { query } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ReportTable
|
|
|
|
endpoint="customers"
|
2018-12-12 12:55:10 +00:00
|
|
|
extendItemsMethodNames={ {
|
|
|
|
load: 'getCustomers',
|
2018-12-15 12:15:13 +00:00
|
|
|
getError: 'getCustomersError',
|
2018-12-12 12:55:10 +00:00
|
|
|
isRequesting: 'isGetCustomersRequesting',
|
|
|
|
} }
|
2018-12-06 22:21:46 +00:00
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
getRowsContent={ this.getRowsContent }
|
|
|
|
itemIdField="id"
|
|
|
|
query={ query }
|
2018-12-18 12:35:58 +00:00
|
|
|
labels={ { placeholder: __( 'Search by customer name', 'wc-admin' ) } }
|
2018-12-14 12:29:17 +00:00
|
|
|
searchBy="customers"
|
|
|
|
searchParam="name_includes"
|
2018-12-06 22:21:46 +00:00
|
|
|
title={ __( 'Registered Customers', 'wc-admin' ) }
|
2018-12-13 20:34:23 +00:00
|
|
|
columnPrefsKey="customers_report_columns"
|
2018-12-06 22:21:46 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|