2018-06-07 16:05:22 +00:00
|
|
|
/** @format */
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __, _n, sprintf } from '@wordpress/i18n';
|
2018-08-01 19:07:17 +00:00
|
|
|
import { Button } from '@wordpress/components';
|
2018-07-23 20:14:40 +00:00
|
|
|
import { Fragment } from '@wordpress/element';
|
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-07-20 18:41:39 +00:00
|
|
|
import { ActivityCard } from '../activity-card';
|
2018-07-16 18:37:25 +00:00
|
|
|
import ActivityHeader from '../activity-header';
|
2018-07-17 18:51:56 +00:00
|
|
|
import ActivityOutboundLink from '../activity-outbound-link';
|
2018-07-09 15:46:31 +00:00
|
|
|
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-07-17 13:11:13 +00:00
|
|
|
import OrderStatus from 'components/order-status';
|
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>
|
|
|
|
) : (
|
2018-07-17 18:51:56 +00:00
|
|
|
<Fragment>
|
|
|
|
{ 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-17 18:51:56 +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-23 20:14:40 +00:00
|
|
|
return (
|
|
|
|
<ActivityCard
|
|
|
|
key={ i }
|
|
|
|
className="woocommerce-order-activity-card"
|
|
|
|
title={ sprintf( __( '%s placed order #%d', 'wc-admin' ), name, order.id ) }
|
|
|
|
icon={ gravatarWithFlag( order, address ) }
|
|
|
|
date={ order.date_created }
|
|
|
|
subtitle={
|
|
|
|
<div>
|
2018-07-16 13:53:38 +00:00
|
|
|
<span>
|
2018-07-23 20:14:40 +00:00
|
|
|
{ sprintf(
|
|
|
|
_n( '%d product', '%d products', productsCount, 'wc-admin' ),
|
|
|
|
productsCount
|
|
|
|
) }
|
2018-07-16 13:53:38 +00:00
|
|
|
</span>
|
2018-07-23 20:14:40 +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>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<OrderStatus order={ order } />
|
|
|
|
</ActivityCard>
|
2018-07-17 18:51:56 +00:00
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
<ActivityOutboundLink href={ 'edit.php?post_type=shop_order' }>
|
|
|
|
{ __( 'Manage all orders' ) }
|
|
|
|
</ActivityOutboundLink>
|
|
|
|
</Fragment>
|
2018-07-09 15:46:31 +00:00
|
|
|
) }
|
|
|
|
</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,
|
|
|
|
};
|
|
|
|
|
2018-08-07 20:11:30 +00:00
|
|
|
OrdersPanel.defaultProps = {
|
|
|
|
orders: {
|
|
|
|
data: [],
|
|
|
|
isLoading: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-08-01 19:07:17 +00:00
|
|
|
export default OrdersPanel;
|