2020-03-06 12:27:54 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-05-31 03:49:36 +00:00
|
|
|
import clsx from 'clsx';
|
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';
|
2023-11-20 12:53:41 +00:00
|
|
|
import type { CartFeeItem, Currency } 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 }` }
|
2024-05-31 03:49:36 +00:00
|
|
|
className={ clsx(
|
2021-01-20 20:35:53 +00:00
|
|
|
'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 }
|
2023-12-12 23:05:20 +00:00
|
|
|
label={ name || __( 'Fee', 'woocommerce' ) }
|
2021-01-13 16:57:42 +00:00
|
|
|
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;
|