2018-12-06 22:21:46 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2019-02-05 12:00:37 +00:00
|
|
|
import { __, _n } from '@wordpress/i18n';
|
2019-01-18 03:13:07 +00:00
|
|
|
import { Component, Fragment } from '@wordpress/element';
|
|
|
|
import { Tooltip } from '@wordpress/components';
|
2018-12-06 22:21:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* WooCommerce dependencies
|
|
|
|
*/
|
2019-11-26 19:39:40 +00:00
|
|
|
import { defaultTableDateFormat } from 'lib/date';
|
2019-11-21 21:51:52 +00:00
|
|
|
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency-format';
|
2019-01-14 09:54:44 +00:00
|
|
|
import { Date, Link } from '@woocommerce/components';
|
2019-11-21 21:51:52 +00:00
|
|
|
import { formatValue } from 'lib/number-format';
|
2019-11-22 17:07:26 +00:00
|
|
|
import { getAdminLink, getSetting } from '@woocommerce/wc-admin-settings';
|
2019-09-30 21:43:26 +00:00
|
|
|
|
|
|
|
const { countries } = getSetting( 'dataEndpoints', { countries: {} } );
|
2018-12-06 22:21:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ReportTable from 'analytics/components/report-table';
|
|
|
|
|
|
|
|
export default class CustomersReportTable extends Component {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.getHeadersContent = this.getHeadersContent.bind( this );
|
|
|
|
this.getRowsContent = this.getRowsContent.bind( this );
|
2019-01-21 15:46:21 +00:00
|
|
|
this.getSummary = this.getSummary.bind( this );
|
2018-12-06 22:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getHeadersContent() {
|
|
|
|
return [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Name', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'name',
|
|
|
|
required: true,
|
|
|
|
isLeftAligned: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Username', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'username',
|
|
|
|
hiddenByDefault: true,
|
|
|
|
},
|
2019-01-23 17:51:12 +00:00
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Last Active', 'woocommerce-admin' ),
|
2019-01-23 17:51:12 +00:00
|
|
|
key: 'date_last_active',
|
|
|
|
defaultSort: true,
|
|
|
|
isSortable: true,
|
|
|
|
},
|
2018-12-06 22:21:46 +00:00
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Sign Up', 'woocommerce-admin' ),
|
2019-01-10 00:43:39 +00:00
|
|
|
key: 'date_registered',
|
2018-12-06 22:21:46 +00:00
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Email', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'email',
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Orders', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'orders_count',
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Total Spend', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'total_spend',
|
|
|
|
isSortable: true,
|
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'AOV', 'woocommerce-admin' ),
|
|
|
|
screenReaderLabel: __( 'Average Order Value', 'woocommerce-admin' ),
|
2018-12-12 14:46:40 +00:00
|
|
|
key: 'avg_order_value',
|
2018-12-06 22:21:46 +00:00
|
|
|
isNumeric: true,
|
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Country', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'country',
|
2019-06-19 22:15:58 +00:00
|
|
|
isSortable: true,
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'City', 'woocommerce-admin' ),
|
2018-12-06 22:21:46 +00:00
|
|
|
key: 'city',
|
|
|
|
hiddenByDefault: true,
|
2019-06-19 22:15:58 +00:00
|
|
|
isSortable: true,
|
|
|
|
},
|
|
|
|
{
|
2019-06-28 16:41:22 +00:00
|
|
|
label: __( 'Region', 'woocommerce-admin' ),
|
2019-06-19 22:15:58 +00:00
|
|
|
key: 'state',
|
|
|
|
hiddenByDefault: true,
|
|
|
|
isSortable: true,
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'Postal Code', 'woocommerce-admin' ),
|
2019-06-28 18:15:50 +00:00
|
|
|
key: 'postcode',
|
2018-12-06 22:21:46 +00:00
|
|
|
hiddenByDefault: true,
|
2019-06-19 22:15:58 +00:00
|
|
|
isSortable: true,
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-01-18 03:13:07 +00:00
|
|
|
getCountryName( code ) {
|
2019-09-23 21:47:08 +00:00
|
|
|
return typeof countries[ code ] !== 'undefined' ? countries[ code ] : null;
|
2019-01-18 03:13:07 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 22:21:46 +00:00
|
|
|
getRowsContent( customers ) {
|
|
|
|
return customers.map( customer => {
|
|
|
|
const {
|
2018-12-12 14:46:40 +00:00
|
|
|
avg_order_value,
|
2018-12-06 22:21:46 +00:00
|
|
|
date_last_active,
|
2019-01-10 00:43:39 +00:00
|
|
|
date_registered,
|
2018-12-06 22:21:46 +00:00
|
|
|
email,
|
2019-01-10 00:43:39 +00:00
|
|
|
name,
|
|
|
|
user_id,
|
2018-12-06 22:21:46 +00:00
|
|
|
orders_count,
|
|
|
|
username,
|
|
|
|
total_spend,
|
2019-01-10 00:43:39 +00:00
|
|
|
postcode,
|
|
|
|
city,
|
2019-06-19 22:15:58 +00:00
|
|
|
state,
|
2019-01-10 00:43:39 +00:00
|
|
|
country,
|
2018-12-06 22:21:46 +00:00
|
|
|
} = customer;
|
2019-01-18 03:13:07 +00:00
|
|
|
const countryName = this.getCountryName( country );
|
2018-12-06 22:21:46 +00:00
|
|
|
|
2019-01-10 00:43:39 +00:00
|
|
|
const customerNameLink = user_id ? (
|
2019-11-22 17:07:26 +00:00
|
|
|
<Link href={ getAdminLink( 'user-edit.php?user_id=' + user_id ) } type="wp-admin">
|
2018-12-06 22:21:46 +00:00
|
|
|
{ name }
|
|
|
|
</Link>
|
2019-01-10 00:43:39 +00:00
|
|
|
) : (
|
|
|
|
name
|
2018-12-06 22:21:46 +00:00
|
|
|
);
|
|
|
|
|
2019-08-07 19:12:47 +00:00
|
|
|
const dateLastActive = date_last_active ? (
|
|
|
|
<Date date={ date_last_active } visibleFormat={ defaultTableDateFormat } />
|
|
|
|
) : (
|
|
|
|
'—'
|
|
|
|
);
|
|
|
|
|
2019-01-16 21:10:23 +00:00
|
|
|
const dateRegistered = date_registered ? (
|
|
|
|
<Date date={ date_registered } visibleFormat={ defaultTableDateFormat } />
|
|
|
|
) : (
|
|
|
|
'—'
|
|
|
|
);
|
2019-01-10 00:43:39 +00:00
|
|
|
|
2019-01-18 03:13:07 +00:00
|
|
|
const countryDisplay = (
|
|
|
|
<Fragment>
|
|
|
|
<Tooltip text={ countryName }>
|
|
|
|
<span aria-hidden="true">{ country }</span>
|
|
|
|
</Tooltip>
|
|
|
|
<span className="screen-reader-text">{ countryName }</span>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
|
2018-12-06 22:21:46 +00:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
display: customerNameLink,
|
|
|
|
value: name,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: username,
|
|
|
|
value: username,
|
|
|
|
},
|
2019-01-23 17:51:12 +00:00
|
|
|
{
|
2019-08-07 19:12:47 +00:00
|
|
|
display: dateLastActive,
|
2019-01-23 17:51:12 +00:00
|
|
|
value: date_last_active,
|
|
|
|
},
|
2018-12-06 22:21:46 +00:00
|
|
|
{
|
2019-01-10 00:43:39 +00:00
|
|
|
display: dateRegistered,
|
|
|
|
value: date_registered,
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
display: <a href={ 'mailto:' + email }>{ email }</a>,
|
|
|
|
value: email,
|
|
|
|
},
|
|
|
|
{
|
2019-11-21 21:51:52 +00:00
|
|
|
display: formatValue( 'number', orders_count ),
|
2018-12-06 22:21:46 +00:00
|
|
|
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-18 03:13:07 +00:00
|
|
|
display: countryDisplay,
|
2018-12-06 22:21:46 +00:00
|
|
|
value: country,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
display: city,
|
|
|
|
value: city,
|
|
|
|
},
|
2019-06-19 22:15:58 +00:00
|
|
|
{
|
|
|
|
display: state,
|
|
|
|
value: state,
|
|
|
|
},
|
2018-12-06 22:21:46 +00:00
|
|
|
{
|
2018-12-12 12:55:10 +00:00
|
|
|
display: postcode,
|
|
|
|
value: postcode,
|
2018-12-06 22:21:46 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2019-01-21 15:46:21 +00:00
|
|
|
getSummary( totals ) {
|
2019-02-05 12:00:37 +00:00
|
|
|
const {
|
|
|
|
customers_count = 0,
|
|
|
|
avg_orders_count = 0,
|
|
|
|
avg_total_spend = 0,
|
|
|
|
avg_avg_order_value = 0,
|
|
|
|
} = totals;
|
2019-01-21 15:46:21 +00:00
|
|
|
return [
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: _n( 'customer', 'customers', customers_count, 'woocommerce-admin' ),
|
2019-11-21 21:51:52 +00:00
|
|
|
value: formatValue( 'number', customers_count ),
|
2019-01-21 15:46:21 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: _n( 'average order', 'average orders', avg_orders_count, 'woocommerce-admin' ),
|
2019-11-21 21:51:52 +00:00
|
|
|
value: formatValue( 'number', avg_orders_count ),
|
2019-01-21 15:46:21 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'average lifetime spend', 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: formatCurrency( avg_total_spend ),
|
2019-01-21 15:46:21 +00:00
|
|
|
},
|
|
|
|
{
|
2019-03-13 17:14:02 +00:00
|
|
|
label: __( 'average order value', 'woocommerce-admin' ),
|
2019-02-05 12:00:37 +00:00
|
|
|
value: formatCurrency( avg_avg_order_value ),
|
2019-01-21 15:46:21 +00:00
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-12-06 22:21:46 +00:00
|
|
|
render() {
|
2019-03-21 03:25:05 +00:00
|
|
|
const { isRequesting, query, filters, advancedFilters } = this.props;
|
2018-12-06 22:21:46 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<ReportTable
|
|
|
|
endpoint="customers"
|
|
|
|
getHeadersContent={ this.getHeadersContent }
|
|
|
|
getRowsContent={ this.getRowsContent }
|
2019-01-21 15:46:21 +00:00
|
|
|
getSummary={ this.getSummary }
|
2019-02-26 09:28:50 +00:00
|
|
|
isRequesting={ isRequesting }
|
2018-12-06 22:21:46 +00:00
|
|
|
itemIdField="id"
|
|
|
|
query={ query }
|
2019-03-13 17:14:02 +00:00
|
|
|
labels={ { placeholder: __( 'Search by customer name', 'woocommerce-admin' ) } }
|
2018-12-14 12:29:17 +00:00
|
|
|
searchBy="customers"
|
2019-03-13 17:14:02 +00:00
|
|
|
title={ __( 'Customers', 'woocommerce-admin' ) }
|
2018-12-13 20:34:23 +00:00
|
|
|
columnPrefsKey="customers_report_columns"
|
2019-03-21 03:25:05 +00:00
|
|
|
filters={ filters }
|
|
|
|
advancedFilters={ advancedFilters }
|
2018-12-06 22:21:46 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2019-01-29 16:48:46 +00:00
|
|
|
}
|