/** @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 './activity-card'; import { formatCurrency, getCurrencyFormatDecimal } from 'lib/currency'; import { getOrderRefundTotal } from 'lib/order-values'; import { Section } from 'layout/section'; function OrdersList( { orders } ) { const { data = [], isLoading } = orders; return (
{ isLoading ? (

Loading

) : ( 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 ( } date={ order.date_created } >
{ sprintf( __( '%s placed order #%d', 'woo-dash' ), name, order.id ) }
{ sprintf( _n( '%d product', '%d products', productsCount, 'woo-dash' ), productsCount ) } {' '} { refundValue ? ( { formatCurrency( total, order.currency ) }{' '} { formatCurrency( remainingTotal, order.currency ) } ) : ( { formatCurrency( total, order.currency ) } ) }
); } ) ) }
); } OrdersList.propTypes = { orders: PropTypes.object.isRequired, }; export default compose( [ withAPIData( () => ( { orders: '/wc/v3/orders', } ) ), ] )( OrdersList );