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-07-16 13:53:38 +00:00
|
|
|
import { Button, withAPIData } from '@wordpress/components';
|
2018-06-07 16:05:22 +00:00
|
|
|
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-07-16 16:28:26 +00:00
|
|
|
import Flag from 'components/flag';
|
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-07-16 16:28:26 +00:00
|
|
|
const gravatarWithFlag = ( order, address ) => {
|
|
|
|
return (
|
|
|
|
<div className="woocommerce-layout__activity-panel-avatar-flag-overlay">
|
|
|
|
<Flag order={ order } />
|
|
|
|
<Gravatar user={ address.email } />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
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-16 13:53:38 +00:00
|
|
|
className="woocommerce-order-activity-card"
|
|
|
|
title={ sprintf( __( '%s placed order #%d', 'wc-admin' ), name, order.id ) }
|
2018-07-16 16:28:26 +00:00
|
|
|
icon={ gravatarWithFlag( order, address ) }
|
2018-07-09 15:46:31 +00:00
|
|
|
date={ order.date_created }
|
2018-07-16 13:53:38 +00:00
|
|
|
subtitle={
|
|
|
|
<div>
|
2018-07-09 15:46:31 +00:00
|
|
|
<span>
|
2018-07-16 13:53:38 +00:00
|
|
|
{ sprintf(
|
|
|
|
_n( '%d product', '%d products', productsCount, 'wc-admin' ),
|
|
|
|
productsCount
|
|
|
|
) }
|
2018-07-09 15:46:31 +00:00
|
|
|
</span>
|
2018-07-16 13:53:38 +00:00
|
|
|
{ refundValue ? (
|
|
|
|
<span>
|
|
|
|
<s>{ formatCurrency( total, order.currency ) }</s>{' '}
|
|
|
|
{ formatCurrency( remainingTotal, order.currency ) }
|
|
|
|
</span>
|
|
|
|
) : (
|
|
|
|
<span>{ formatCurrency( total, order.currency ) }</span>
|
|
|
|
) }
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
actions={
|
|
|
|
<Button isDefault onClick={ noop }>
|
|
|
|
Begin fulfillment
|
|
|
|
</Button>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
Pending
|
2018-07-09 15:46:31 +00:00
|
|
|
</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 );
|