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';
|
2021-04-22 11:37:27 +00:00
|
|
|
import { getSetting } from '@woocommerce/settings';
|
2021-03-05 14:03:48 +00:00
|
|
|
import type { Currency } from '@woocommerce/price-format';
|
|
|
|
import type { CartFeeItem } from '@woocommerce/type-defs/cart';
|
|
|
|
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 TotalsFeesProps {
|
|
|
|
currency: Currency;
|
|
|
|
cartFees: CartFeeItem[];
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TotalsFees = ( {
|
|
|
|
currency,
|
|
|
|
cartFees,
|
|
|
|
className,
|
|
|
|
}: TotalsFeesProps ): ReactElement | null => {
|
2021-01-13 16:57:42 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{ cartFees.map( ( { id, name, totals } ) => {
|
|
|
|
const feesValue = parseInt( totals.total, 10 );
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2021-01-13 16:57:42 +00:00
|
|
|
if ( ! feesValue ) {
|
|
|
|
return null;
|
|
|
|
}
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2021-01-13 16:57:42 +00:00
|
|
|
const feesTaxValue = parseInt( totals.total_tax, 10 );
|
2020-03-06 12:27:54 +00:00
|
|
|
|
2021-01-13 16:57:42 +00:00
|
|
|
return (
|
|
|
|
<TotalsItem
|
|
|
|
key={ id }
|
2021-01-20 20:35:53 +00:00
|
|
|
className={ classnames(
|
|
|
|
'wc-block-components-totals-fees',
|
|
|
|
className
|
|
|
|
) }
|
2021-01-13 16:57:42 +00:00
|
|
|
currency={ currency }
|
|
|
|
label={
|
|
|
|
name || __( 'Fee', 'woo-gutenberg-products-block' )
|
|
|
|
}
|
|
|
|
value={
|
2021-04-22 11:37:27 +00:00
|
|
|
getSetting( 'displayCartPricesIncludingTax', false )
|
2021-01-13 16:57:42 +00:00
|
|
|
? feesValue + feesTaxValue
|
|
|
|
: feesValue
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</>
|
2020-03-06 12:27:54 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-12-09 07:29:34 +00:00
|
|
|
export default TotalsFees;
|