2020-03-06 12:27:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-01-20 20:35:53 +00:00
|
|
|
import classnames from 'classnames';
|
2020-03-06 12:27:54 +00:00
|
|
|
import { __ } from '@wordpress/i18n';
|
2020-04-24 13:44:44 +00:00
|
|
|
import {
|
|
|
|
TAXES_ENABLED,
|
|
|
|
DISPLAY_ITEMIZED_TAXES,
|
|
|
|
} from '@woocommerce/block-settings';
|
2021-03-05 14:03:48 +00:00
|
|
|
import type { Currency } from '@woocommerce/price-format';
|
|
|
|
import type { CartTotalsTaxLineItem } from '@woocommerce/type-defs/cart';
|
|
|
|
import { ReactElement } from 'react';
|
2020-03-06 12:27:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-01-20 20:35:53 +00:00
|
|
|
import TotalsItem from '../item';
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2021-03-05 14:03:48 +00:00
|
|
|
interface Values {
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
tax_lines: CartTotalsTaxLineItem[];
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
total_tax: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface TotalsTaxesProps {
|
|
|
|
className?: string;
|
|
|
|
currency: Currency;
|
|
|
|
values: Values | Record< string, never >;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TotalsTaxes = ( {
|
|
|
|
currency,
|
|
|
|
values,
|
|
|
|
className,
|
|
|
|
}: TotalsTaxesProps ): ReactElement | null => {
|
2020-04-24 13:44:44 +00:00
|
|
|
const { total_tax: totalTax, tax_lines: taxLines } = values;
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2020-04-22 13:16:17 +00:00
|
|
|
if ( ! TAXES_ENABLED ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:44:44 +00:00
|
|
|
if ( ! DISPLAY_ITEMIZED_TAXES ) {
|
|
|
|
return (
|
|
|
|
<TotalsItem
|
2021-01-20 20:35:53 +00:00
|
|
|
className={ classnames(
|
|
|
|
'wc-block-components-totals-taxes',
|
|
|
|
className
|
|
|
|
) }
|
2020-04-24 13:44:44 +00:00
|
|
|
currency={ currency }
|
|
|
|
label={ __( 'Taxes', 'woo-gutenberg-products-block' ) }
|
|
|
|
value={ parseInt( totalTax, 10 ) }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-06 12:27:54 +00:00
|
|
|
return (
|
2020-04-24 13:44:44 +00:00
|
|
|
<>
|
|
|
|
{ taxLines.map( ( { name, price }, i ) => (
|
|
|
|
<TotalsItem
|
|
|
|
key={ `tax-line-${ i }` }
|
2020-06-17 09:53:42 +00:00
|
|
|
className="wc-block-components-totals-taxes"
|
2020-04-24 13:44:44 +00:00
|
|
|
currency={ currency }
|
|
|
|
label={ name }
|
|
|
|
value={ parseInt( price, 10 ) }
|
|
|
|
/>
|
|
|
|
) ) }{ ' ' }
|
|
|
|
</>
|
2020-03-06 12:27:54 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-09 07:29:34 +00:00
|
|
|
export default TotalsTaxes;
|