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
|
|
|
|
|
|
|
/**
|
2018-10-30 18:57:48 +00:00
|
|
|
* WooCommerce dependencies
|
2018-06-07 16:05:22 +00:00
|
|
|
*/
|
2018-08-20 21:18:13 +00:00
|
|
|
import {
|
|
|
|
EllipsisMenu,
|
|
|
|
Gravatar,
|
|
|
|
Flag,
|
|
|
|
MenuTitle,
|
|
|
|
MenuItem,
|
|
|
|
OrderStatus,
|
2018-09-21 15:19:05 +00:00
|
|
|
Section,
|
2018-08-20 21:18:13 +00:00
|
|
|
} from '@woocommerce/components';
|
2018-10-30 18:57:48 +00:00
|
|
|
import { formatCurrency, getCurrencyFormatDecimal } from '@woocommerce/currency';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { ActivityCard } from '../activity-card';
|
|
|
|
import ActivityHeader from '../activity-header';
|
|
|
|
import ActivityOutboundLink from '../activity-outbound-link';
|
2018-06-07 16:05:22 +00:00
|
|
|
import { getOrderRefundTotal } from 'lib/order-values';
|
|
|
|
|
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;
|