2018-06-07 16:05:22 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
|
|
|
import { compose } from '@wordpress/element';
|
|
|
|
import { Dashicon, withAPIData } from '@wordpress/components';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ActivityCard from 'components/activity-card';
|
2018-06-20 17:44:13 +00:00
|
|
|
import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency';
|
2018-06-07 16:05:22 +00:00
|
|
|
import { getOrderRefundTotal } from 'lib/order-values';
|
2018-06-20 15:10:06 +00:00
|
|
|
import { Section } from 'layout/section';
|
2018-06-07 16:05:22 +00:00
|
|
|
|
|
|
|
function OrdersList( { orders } ) {
|
|
|
|
const { data = [], isLoading } = orders;
|
|
|
|
|
|
|
|
return (
|
2018-06-20 15:10:06 +00:00
|
|
|
<Section>
|
2018-06-07 16:05:22 +00:00
|
|
|
{ isLoading ? (
|
|
|
|
<p>Loading</p>
|
|
|
|
) : (
|
|
|
|
data.map( ( order, i ) => {
|
|
|
|
// We want the billing address, but shipping can be used as a fallback.
|
|
|
|
const address = { ...order.shipping, ...order.billing };
|
|
|
|
const name = `${ address.first_name } ${ address.last_name }`;
|
|
|
|
const productsCount = order.line_items.reduce(
|
|
|
|
( total, line ) => total + line.quantity,
|
|
|
|
0
|
|
|
|
);
|
|
|
|
|
|
|
|
const total = order.total;
|
|
|
|
const refundValue = getOrderRefundTotal( order );
|
|
|
|
const remainingTotal = getCurrencyFormatDecimal( order.total ) + refundValue;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ActivityCard
|
|
|
|
key={ i }
|
|
|
|
label={ __( 'Order', 'woo-dash' ) }
|
|
|
|
icon={ <Dashicon icon="format-aside" /> }
|
|
|
|
date={ order.date_created }
|
|
|
|
>
|
|
|
|
<div>{ sprintf( __( '%s placed order #%d', 'woo-dash' ), name, order.id ) }</div>
|
|
|
|
<div>
|
|
|
|
<span>
|
|
|
|
{ sprintf(
|
|
|
|
_n( '%d product', '%d products', productsCount, 'woo-dash' ),
|
|
|
|
productsCount
|
|
|
|
) }
|
|
|
|
</span>{' '}
|
|
|
|
{ refundValue ? (
|
|
|
|
<span>
|
2018-06-20 17:44:13 +00:00
|
|
|
<s>{ formatCurrency( total, order.currency ) }</s>{' '}
|
|
|
|
{ formatCurrency( remainingTotal, order.currency ) }
|
2018-06-07 16:05:22 +00:00
|
|
|
</span>
|
|
|
|
) : (
|
2018-06-20 17:44:13 +00:00
|
|
|
<span>{ formatCurrency( total, order.currency ) }</span>
|
2018-06-07 16:05:22 +00:00
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</ActivityCard>
|
|
|
|
);
|
|
|
|
} )
|
|
|
|
) }
|
2018-06-20 15:10:06 +00:00
|
|
|
</Section>
|
2018-06-07 16:05:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
OrdersList.propTypes = {
|
|
|
|
orders: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default compose( [
|
|
|
|
withAPIData( () => ( {
|
|
|
|
orders: '/wc/v3/orders',
|
|
|
|
} ) ),
|
|
|
|
] )( OrdersList );
|