2020-03-06 12:27:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
|
|
|
import { DISPLAY_CART_PRICES_INCLUDING_TAX } from '@woocommerce/block-settings';
|
2021-03-05 14:03:48 +00:00
|
|
|
import type { Currency } from '@woocommerce/price-format';
|
|
|
|
import type { ReactElement } from 'react';
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2021-01-20 20:35:53 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import TotalsItem from '../item';
|
|
|
|
|
2021-03-05 14:03:48 +00:00
|
|
|
interface Values {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
total_items: string;
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
total_items_tax: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface SubtotalProps {
|
|
|
|
className?: string;
|
|
|
|
currency: Currency;
|
|
|
|
values: Values | Record< string, never >;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Subtotal = ( {
|
|
|
|
currency,
|
|
|
|
values,
|
|
|
|
className,
|
|
|
|
}: SubtotalProps ): ReactElement => {
|
2020-03-06 12:27:54 +00:00
|
|
|
const { total_items: totalItems, total_items_tax: totalItemsTax } = values;
|
|
|
|
const itemsValue = parseInt( totalItems, 10 );
|
|
|
|
const itemsTaxValue = parseInt( totalItemsTax, 10 );
|
|
|
|
|
|
|
|
return (
|
|
|
|
<TotalsItem
|
2021-01-20 20:35:53 +00:00
|
|
|
className={ className }
|
2020-03-06 12:27:54 +00:00
|
|
|
currency={ currency }
|
|
|
|
label={ __( 'Subtotal', 'woo-gutenberg-products-block' ) }
|
|
|
|
value={
|
|
|
|
DISPLAY_CART_PRICES_INCLUDING_TAX
|
|
|
|
? itemsValue + itemsTaxValue
|
|
|
|
: itemsValue
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-09 07:29:34 +00:00
|
|
|
export default Subtotal;
|