diff --git a/src/components/BookingBreakdown/LineItemBasePriceMaybe.js b/src/components/BookingBreakdown/LineItemBasePriceMaybe.js new file mode 100644 index 00000000..3c57e921 --- /dev/null +++ b/src/components/BookingBreakdown/LineItemBasePriceMaybe.js @@ -0,0 +1,42 @@ +import React from 'react'; +import { FormattedMessage, intlShape } from '../../util/reactIntl'; +import { formatMoney } from '../../util/currency'; +import { LINE_ITEM_NIGHT, LINE_ITEM_DAY, propTypes } from '../../util/types'; + +import css from './BookingBreakdown.css'; + +const LineItemBasePriceMaybe = props => { + const { transaction, unitType, intl } = props; + const isNightly = unitType === LINE_ITEM_NIGHT; + const isDaily = unitType === LINE_ITEM_DAY; + const translationKey = isNightly + ? 'BookingBreakdown.baseUnitNight' + : isDaily + ? 'BookingBreakdown.baseUnitDay' + : 'BookingBreakdown.baseUnitQuantity'; + + const unitPurchase = transaction.attributes.lineItems.find( + item => item.code === unitType && !item.reversal + ); + + const quantity = unitPurchase ? unitPurchase.quantity.toString() : null; + const unitPrice = unitPurchase ? formatMoney(intl, unitPurchase.unitPrice) : null; + const total = unitPurchase ? formatMoney(intl, unitPurchase.lineTotal) : null; + + return quantity && total ? ( +