Merge pull request #1112 from sharetribe/prevent-provider-commission-error

Prevent provider commission error
This commit is contained in:
Jenni Laakso 2019-06-10 14:07:04 +03:00 committed by GitHub
commit c46e9f2ca0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View file

@ -14,6 +14,10 @@ way to update this template, but currently, we follow a pattern:
## Upcoming version 2019-XX-XX
- [fix] In `LineItemProviderCommissionMaybe.js` file check that `providerCommissionLineItem` exists.
In default transaction process the `providerCommissionLineItem` can be expected to be there but if
the process is using only customer commission there will be error.
[#1112](https://github.com/sharetribe/flex-template-web/pull/1112)
- [fix] Fix a bug in showing review links. Because of the bug the second review link was not visible
in `ActivityFeed`. [#1106](https://github.com/sharetribe/flex-template-web/pull/1106)
- [fix] Emptying the priceFilter component in the searchPage caused a page breaking error.

View file

@ -12,7 +12,11 @@ const { Money } = sdkTypes;
// Validate the assumption that the commission exists and the amount
// is zero or positive.
const isValidCommission = commissionLineItem => {
return commissionLineItem.lineTotal instanceof Money && commissionLineItem.lineTotal.amount >= 0;
return (
commissionLineItem &&
commissionLineItem.lineTotal instanceof Money &&
commissionLineItem.lineTotal.amount >= 0
);
};
const LineItemCustomerCommissionMaybe = props => {

View file

@ -12,11 +12,7 @@ const { Money } = sdkTypes;
// Validate the assumption that the commission exists and the amount
// is zero or negative.
const isValidCommission = commissionLineItem => {
return (
commissionLineItem &&
commissionLineItem.lineTotal instanceof Money &&
commissionLineItem.lineTotal.amount <= 0
);
return commissionLineItem.lineTotal instanceof Money && commissionLineItem.lineTotal.amount <= 0;
};
const LineItemProviderCommissionMaybe = props => {
@ -29,7 +25,10 @@ const LineItemProviderCommissionMaybe = props => {
// If commission is passed it will be shown as a fee already reduces from the total price
let commissionItem = null;
if (isProvider) {
// Flex Template for Web is using the default transaction process (https://www.sharetribe.com/docs/background/transaction-process/#sharetribe-flex-default-transaction-process)
// which containt provider commissions so by default the providerCommissionLineItem should exist.
// If you are not using provider commisison you might want to remove this whole component from BookingBreakdown.js file.
if (isProvider && providerCommissionLineItem) {
if (!isValidCommission(providerCommissionLineItem)) {
// eslint-disable-next-line no-console
console.error('invalid commission line item:', providerCommissionLineItem);