mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 05:00:43 +10:00
Remove requirement for a known line item
Remove the requirement that a certain kind of line item is found from a transaction.
This commit is contained in:
parent
8247e54988
commit
d8c614c911
5 changed files with 23 additions and 24 deletions
|
|
@ -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 (
|
||||
<div className={classes}>
|
||||
<LineItemUnitPrice transaction={transaction} unitType={unitType} intl={intl} />
|
||||
<LineItemUnitPriceMaybe transaction={transaction} unitType={unitType} intl={intl} />
|
||||
<LineItemBookingPeriod transaction={transaction} booking={booking} unitType={unitType} />
|
||||
<LineItemUnitsMaybe transaction={transaction} unitType={unitType} />
|
||||
|
||||
|
|
|
|||
|
|
@ -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 = (
|
||||
<FormattedHTMLMessage
|
||||
|
|
|
|||
|
|
@ -44,13 +44,9 @@ const LineItemSubTotalMaybe = props => {
|
|||
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 ? (
|
||||
<div className={css.lineItem}>
|
||||
<span className={css.itemLabel}>
|
||||
<FormattedMessage id="BookingBreakdown.subTotal" />
|
||||
|
|
|
|||
|
|
@ -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 ? (
|
||||
<div className={css.lineItem}>
|
||||
<span className={css.itemLabel}>
|
||||
<FormattedMessage id={translationKey} />
|
||||
</span>
|
||||
<span className={css.itemValue}>{formattedUnitPrice}</span>
|
||||
</div>
|
||||
);
|
||||
) : null;
|
||||
};
|
||||
|
||||
LineItemUnitPrice.propTypes = {
|
||||
LineItemUnitPriceMaybe.propTypes = {
|
||||
transaction: propTypes.transaction.isRequired,
|
||||
unitType: propTypes.bookingUnitType.isRequired,
|
||||
intl: intlShape.isRequired,
|
||||
};
|
||||
|
||||
export default LineItemUnitPrice;
|
||||
export default LineItemUnitPriceMaybe;
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue