/** @format */ /** * External dependencies */ import { __, _n, sprintf } from '@wordpress/i18n'; import { Button, ToggleControl, withAPIData } from '@wordpress/components'; import { Component, compose } from '@wordpress/element'; /** * Internal dependencies */ import Card from 'components/card'; import { EllipsisMenu, MenuItem, MenuTitle } from 'components/ellipsis-menu'; class WidgetNumbers extends Component { constructor() { super( ...arguments ); this.state = { showCustomers: true, showProducts: true, showOrders: true, }; this.toggle = this.toggle.bind( this ); } toggle( type ) { return () => { this.setState( state => ( { [ type ]: ! state[ type ] } ) ); }; } renderMenu() { return ( { __( 'Display Stats:', 'woo-dash' ) } ); } render() { const { orders, products } = this.props; const totalOrders = ( orders.data && orders.data.length ) || 0; const totalProducts = ( products.data && products.data.length ) || 0; const { showCustomers, showProducts, showOrders } = this.state; return (
{ showCustomers && (
{ sprintf( _n( '%d New Customer', '%d New Customers', 4, 'woo-dash' ), 4 ) }
) } { showOrders && (
{ sprintf( _n( '%d New Order', '%d New Orders', totalOrders, 'woo-dash' ), totalOrders ) }
) } { showProducts && (
{ sprintf( _n( '%d Product', '%d Products', totalProducts, 'woo-dash' ), totalProducts ) }
) }
); } } export default compose( [ withAPIData( () => ( { orders: '/wc/v2/orders?status=processing', products: '/wc/v2/products', } ) ), ] )( WidgetNumbers );