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-12-21 17:08:57 +00:00
|
|
|
export interface TotalsFeesProps {
|
2021-03-05 14:03:48 +00:00
|
|
|
currency: Currency;
|
|
|
|
cartFees: CartFeeItem[];
|
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TotalsFees = ( {
|
|
|
|
currency,
|
|
|
|
cartFees,
|
|
|
|
className,
|
|
|
|
}: TotalsFeesProps ): ReactElement | null => {
|
2021-01-13 16:57:42 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-06-17 07:49:45 +00:00
|
|
|
{ cartFees.map( ( { id, name, totals }, index ) => {
|
2021-01-13 16:57:42 +00:00
|
|
|
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
|
2021-06-17 07:49:45 +00:00
|
|
|
key={ id || `${ index }-${ name }` }
|
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;
|