diff --git a/src/components/BookingBreakdown/BookingBreakdown.js b/src/components/BookingBreakdown/BookingBreakdown.js
index 041cbd8a..ddb39deb 100644
--- a/src/components/BookingBreakdown/BookingBreakdown.js
+++ b/src/components/BookingBreakdown/BookingBreakdown.js
@@ -12,7 +12,7 @@ import {
LINE_ITEM_PROVIDER_COMMISSION,
} from '../../util/types';
-import LineItemUnitPrice from './LineItemUnitPrice';
+import LineItemUnitPriceMaybe from './LineItemUnitPriceMaybe';
import LineItemBookingPeriod from './LineItemBookingPeriod';
import LineItemUnitsMaybe from './LineItemUnitsMaybe';
import LineItemSubTotalMaybe from './LineItemSubTotalMaybe';
@@ -40,7 +40,7 @@ export const BookingBreakdownComponent = props => {
return (
-
+
diff --git a/src/components/BookingBreakdown/LineItemBookingPeriod.js b/src/components/BookingBreakdown/LineItemBookingPeriod.js
index 03d49e83..bd018c54 100644
--- a/src/components/BookingBreakdown/LineItemBookingPeriod.js
+++ b/src/components/BookingBreakdown/LineItemBookingPeriod.js
@@ -59,12 +59,8 @@ const LineItemBookingPeriod = props => {
item => item.code === unitType && !item.reversal
);
- if (!unitPurchase) {
- throw new Error(`LineItemBookingPeriod: lineItem (${unitType}) missing`);
- }
-
const useQuantityForDayCount = isNightly || isDaily;
- const count = useQuantityForDayCount ? unitPurchase.quantity.toFixed() : dayCount;
+ const count = useQuantityForDayCount && unitPurchase ? unitPurchase.quantity.toFixed() : dayCount;
const unitCountMessage = (
{
item => item.code === unitType && !item.reversal
);
- if (!unitPurchase) {
- throw new Error(`LineItemSubTotalMaybe: lineItem (${unitType}) missing`);
- }
+ const formattedSubTotal = unitPurchase ? formatMoney(intl, unitPurchase.lineTotal) : null;
- const formattedSubTotal = formatMoney(intl, unitPurchase.lineTotal);
-
- return showSubTotal ? (
+ return formattedSubTotal && showSubTotal ? (
diff --git a/src/components/BookingBreakdown/LineItemUnitPrice.js b/src/components/BookingBreakdown/LineItemUnitPriceMaybe.js
similarity index 78%
rename from src/components/BookingBreakdown/LineItemUnitPrice.js
rename to src/components/BookingBreakdown/LineItemUnitPriceMaybe.js
index 980fd43a..29549016 100644
--- a/src/components/BookingBreakdown/LineItemUnitPrice.js
+++ b/src/components/BookingBreakdown/LineItemUnitPriceMaybe.js
@@ -5,7 +5,7 @@ import { LINE_ITEM_NIGHT, LINE_ITEM_DAY, propTypes } from '../../util/types';
import css from './BookingBreakdown.css';
-const LineItemUnitPrice = props => {
+const LineItemUnitPriceMaybe = props => {
const { transaction, unitType, intl } = props;
const isNightly = unitType === LINE_ITEM_NIGHT;
const isDaily = unitType === LINE_ITEM_DAY;
@@ -19,26 +19,22 @@ const LineItemUnitPrice = props => {
item => item.code === unitType && !item.reversal
);
- if (!unitPurchase) {
- throw new Error(`LineItemUnitPrice: lineItem (${unitType}) missing`);
- }
+ const formattedUnitPrice = unitPurchase ? formatMoney(intl, unitPurchase.unitPrice) : null;
- const formattedUnitPrice = formatMoney(intl, unitPurchase.unitPrice);
-
- return (
+ return formattedUnitPrice ? (
{formattedUnitPrice}
- );
+ ) : null;
};
-LineItemUnitPrice.propTypes = {
+LineItemUnitPriceMaybe.propTypes = {
transaction: propTypes.transaction.isRequired,
unitType: propTypes.bookingUnitType.isRequired,
intl: intlShape.isRequired,
};
-export default LineItemUnitPrice;
+export default LineItemUnitPriceMaybe;
diff --git a/src/util/types.js b/src/util/types.js
index 1e2c2a6b..67f968ae 100644
--- a/src/util/types.js
+++ b/src/util/types.js
@@ -307,6 +307,17 @@ const LINE_ITEMS = [
propTypes.bookingUnitType = oneOf([LINE_ITEM_NIGHT, LINE_ITEM_DAY, LINE_ITEM_UNITS]);
+const requiredLineItemPropType = (props, propName, componentName) => {
+ const prop = props[propName];
+
+ if (!prop || prop === '') {
+ return new Error(`Missing line item code prop from ${componentName}.`);
+ }
+ if (!/^line-item\/.+/.test(prop)) {
+ return new Error(`Invalid line item code value ${prop} passed to ${componentName}.`);
+ }
+};
+
// Denormalised transaction object
propTypes.transaction = shape({
id: propTypes.uuid.isRequired,
@@ -323,7 +334,7 @@ propTypes.transaction = shape({
lineItems: arrayOf(
shape({
- code: oneOf(LINE_ITEMS).isRequired,
+ code: requiredLineItemPropType,
includeFor: arrayOf(oneOf(['customer', 'provider'])).isRequired,
quantity: instanceOf(Decimal),
unitPrice: propTypes.money.isRequired,