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';
|
2022-12-23 11:59:02 +00:00
|
|
|
import type { CartFeeItem } from '@woocommerce/types';
|
2021-03-05 14:03:48 +00:00
|
|
|
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 {
|
2022-02-25 08:58:09 +00:00
|
|
|
/**
|
|
|
|
* Currency
|
|
|
|
*/
|
2021-03-05 14:03:48 +00:00
|
|
|
currency: Currency;
|
2022-02-25 08:58:09 +00:00
|
|
|
/**
|
|
|
|
* Cart fees
|
|
|
|
*/
|
2021-03-05 14:03:48 +00:00
|
|
|
cartFees: CartFeeItem[];
|
2022-02-25 08:58:09 +00:00
|
|
|
/**
|
|
|
|
* Component wrapper classname
|
|
|
|
*
|
|
|
|
* @default 'wc-block-components-totals-fees'
|
|
|
|
*/
|
2021-03-05 14:03:48 +00:00
|
|
|
className?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TotalsFees = ( {
|
|
|
|
currency,
|
|
|
|
cartFees,
|
|
|
|
className,
|
|
|
|
}: TotalsFeesProps ): ReactElement | null => {
|
2021-01-13 16:57:42 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-09-29 06:34:55 +00:00
|
|
|
{ cartFees.map( ( { id, key, 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',
|
2023-09-29 06:34:55 +00:00
|
|
|
'wc-block-components-totals-fees__' + key,
|
2021-01-20 20:35:53 +00:00
|
|
|
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;
|