Merge pull request #1106 from sharetribe/fix-bug-in-reviewlink

Fix bug in showing the review link after other party has already reviewed it
This commit is contained in:
Jenni Laakso 2019-06-10 11:23:38 +03:00 committed by GitHub
commit a740d03ca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 17 deletions

View file

@ -2,4 +2,6 @@ exports.exceptions = [
// Add exceptions to audit script:
// // Severity: low, lodash (< 4.17.5), used heavily in our CRA fork
// "https://npmjs.com/advisories/577",
// Temporarily skip warning about axios until SDK is updated
"https://npmjs.com/advisories/880",
];

View file

@ -14,6 +14,8 @@ way to update this template, but currently, we follow a pattern:
## Upcoming version 2019-XX-XX
- [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.
[#1101](https://github.com/sharetribe/flex-template-web/pull/1101)

View file

@ -25,6 +25,7 @@ import {
isCustomerReview,
isProviderReview,
txRoleIsProvider,
txRoleIsCustomer,
getUserTxRole,
isRelevantPastTransition,
} from '../../util/transaction';
@ -94,10 +95,10 @@ Review.propTypes = {
};
const hasUserLeftAReviewFirst = (userRole, transaction) => {
const isProvider = txRoleIsProvider(userRole);
return isProvider
? txIsInFirstReviewBy(transaction, isProvider)
: txIsInFirstReviewBy(transaction, !isProvider);
// Because function txIsInFirstReviewBy uses isCustomer to check in which state the reviews are
// we should also use isCustomer insted of isProvider
const isCustomer = txRoleIsCustomer(userRole);
return txIsInFirstReviewBy(transaction, isCustomer);
};
const resolveTransitionMessage = (
@ -145,20 +146,21 @@ const resolveTransitionMessage = (
case TRANSITION_CANCEL:
return <FormattedMessage id="ActivityFeed.transitionCancel" />;
case TRANSITION_COMPLETE:
// Show the leave a review link if the state is delivered or
// if current user is not the first to leave a review
// Show the leave a review link if the state is delivered and if the current user is the first to leave a review
const reviewPeriodJustStarted = txIsDelivered(transaction);
const reviewPeriodIsOver = txIsReviewed(transaction);
const userHasLeftAReview = hasUserLeftAReviewFirst(ownRole, transaction);
const reviewLink =
reviewPeriodJustStarted || !(reviewPeriodIsOver || userHasLeftAReview) ? (
<InlineTextButton onClick={onOpenReviewModal}>
<FormattedMessage id="ActivityFeed.leaveAReview" values={{ displayName }} />
</InlineTextButton>
) : null;
const reviewAsFirstLink = reviewPeriodJustStarted ? (
<InlineTextButton onClick={onOpenReviewModal}>
<FormattedMessage id="ActivityFeed.leaveAReview" values={{ displayName }} />
</InlineTextButton>
) : null;
return <FormattedMessage id="ActivityFeed.transitionComplete" values={{ reviewLink }} />;
return (
<FormattedMessage
id="ActivityFeed.transitionComplete"
values={{ reviewLink: reviewAsFirstLink }}
/>
);
case TRANSITION_REVIEW_1_BY_PROVIDER:
case TRANSITION_REVIEW_1_BY_CUSTOMER:
@ -169,7 +171,7 @@ const resolveTransitionMessage = (
// one to leave a review
const reviewPeriodIsOver = txIsReviewed(transaction);
const userHasLeftAReview = hasUserLeftAReviewFirst(ownRole, transaction);
const reviewLink = !(reviewPeriodIsOver || userHasLeftAReview) ? (
const reviewAsSecondLink = !(reviewPeriodIsOver || userHasLeftAReview) ? (
<InlineTextButton onClick={onOpenReviewModal}>
<FormattedMessage id="ActivityFeed.leaveAReviewSecond" values={{ displayName }} />
</InlineTextButton>
@ -177,7 +179,7 @@ const resolveTransitionMessage = (
return (
<FormattedMessage
id="ActivityFeed.transitionReview"
values={{ displayName, reviewLink }}
values={{ displayName, reviewLink: reviewAsSecondLink }}
/>
);
}