2018-06-07 16:05:22 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
2018-07-09 15:46:31 +00:00
|
|
|
import { compose, Fragment } from '@wordpress/element';
|
2018-06-07 16:05:22 +00:00
|
|
|
import { Dashicon, withAPIData } from '@wordpress/components';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-07-09 15:46:31 +00:00
|
|
|
import { noop } from 'lodash';
|
2018-06-07 16:05:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-06-28 13:52:45 +00:00
|
|
|
import ActivityCard from './activity-card';
|
2018-07-09 15:46:31 +00:00
|
|
|
import ActivityHeader from './activity-header';
|
|
|
|
import { EllipsisMenu, MenuTitle, MenuItem } from 'components/ellipsis-menu';
|
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-07-11 17:06:26 +00:00
|
|
|
import Gravatar from 'components/gravatar';
|
2018-06-20 15:10:06 +00:00
|
|
|
import { Section } from 'layout/section';
|
2018-06-07 16:05:22 +00:00
|
|
|
|
2018-07-09 15:46:31 +00:00
|
|
|
function OrdersPanel( { orders } ) {
|
2018-06-07 16:05:22 +00:00
|
|
|
const { data = [], isLoading } = orders;
|
|
|
|
|
2018-07-09 15:46:31 +00:00
|
|
|
const menu = (
|
|
|
|
<EllipsisMenu label="Demo Menu">
|
|
|
|
<MenuTitle>Test</MenuTitle>
|
|
|
|
<MenuItem onInvoke={ noop }>Test</MenuItem>
|
|
|
|
</EllipsisMenu>
|
|
|
|
);
|
|
|
|
|
2018-06-07 16:05:22 +00:00
|
|
|
return (
|
2018-07-09 15:46:31 +00:00
|
|
|
<Fragment>
|
2018-07-10 12:48:06 +00:00
|
|
|
<ActivityHeader title={ __( 'Orders', 'wc-admin' ) } menu={ menu } />
|
2018-07-09 15:46:31 +00:00
|
|
|
<Section>
|
|
|
|
{ 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
|
|
|
|
);
|
2018-06-07 16:05:22 +00:00
|
|
|
|
2018-07-09 15:46:31 +00:00
|
|
|
const total = order.total;
|
|
|
|
const refundValue = getOrderRefundTotal( order );
|
|
|
|
const remainingTotal = getCurrencyFormatDecimal( order.total ) + refundValue;
|
2018-06-07 16:05:22 +00:00
|
|
|
|
2018-07-09 15:46:31 +00:00
|
|
|
return (
|
|
|
|
<ActivityCard
|
|
|
|
key={ i }
|
2018-07-10 12:48:06 +00:00
|
|
|
label={ __( 'Order', 'wc-admin' ) }
|
2018-07-09 15:46:31 +00:00
|
|
|
icon={ <Dashicon icon="format-aside" /> }
|
|
|
|
date={ order.date_created }
|
|
|
|
>
|
2018-07-11 17:06:26 +00:00
|
|
|
<Gravatar user={ address.email } />
|
2018-07-10 12:48:06 +00:00
|
|
|
<div>{ sprintf( __( '%s placed order #%d', 'wc-admin' ), name, order.id ) }</div>
|
2018-07-09 15:46:31 +00:00
|
|
|
<div>
|
2018-06-07 16:05:22 +00:00
|
|
|
<span>
|
2018-07-09 15:46:31 +00:00
|
|
|
{ sprintf(
|
2018-07-10 12:48:06 +00:00
|
|
|
_n( '%d product', '%d products', productsCount, 'wc-admin' ),
|
2018-07-09 15:46:31 +00:00
|
|
|
productsCount
|
|
|
|
) }
|
|
|
|
</span>{' '}
|
|
|
|
{ refundValue ? (
|
|
|
|
<span>
|
|
|
|
<s>{ formatCurrency( total, order.currency ) }</s>{' '}
|
|
|
|
{ formatCurrency( remainingTotal, order.currency ) }
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span>{ formatCurrency( total, order.currency ) }</span>
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
</ActivityCard>
|
|
|
|
);
|
|
|
|
} )
|
|
|
|
) }
|
|
|
|
</Section>
|
|
|
|
</Fragment>
|
2018-06-07 16:05:22 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-07-09 15:46:31 +00:00
|
|
|
OrdersPanel.propTypes = {
|
2018-06-07 16:05:22 +00:00
|
|
|
orders: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default compose( [
|
|
|
|
withAPIData( () => ( {
|
|
|
|
orders: '/wc/v3/orders',
|
|
|
|
} ) ),
|
2018-07-09 15:46:31 +00:00
|
|
|
] )( OrdersPanel );
|