Skip to content

Commit

Permalink
Merge pull request #1283 from sharetribe/handle-deleted-reviews
Browse files Browse the repository at this point in the history
Handle deleted reviews in ActivityFeed
  • Loading branch information
OtterleyW authored Apr 9, 2020
2 parents 92e21f2 + e02a1b6 commit 5f3d4fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ way to update this template, but currently, we follow a pattern:

## Upcoming version 2020-XX-XX

- [fix] Handle deleted reviews in ActivityFeed [#1283](https://github.com/sharetribe/ftw-daily/pull/1283)

## [v4.4.1] 2020-03-30

- [change] Improve the search page sorting and filters UI for different screen sizes [#1280](https://github.com/sharetribe/ftw-daily/pull/1280)
Expand Down
25 changes: 17 additions & 8 deletions src/components/ActivityFeed/ActivityFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ const Review = props => {
return (
<div>
<p className={css.reviewContent}>{content}</p>
<ReviewRating
reviewStarClassName={css.reviewStar}
className={css.reviewStars}
rating={rating}
/>
{rating ? (
<ReviewRating
reviewStarClassName={css.reviewStar}
className={css.reviewStars}
rating={rating}
/>
) : null}
</div>
);
};
Expand Down Expand Up @@ -203,7 +205,9 @@ const resolveTransitionMessage = (
};

const reviewByAuthorId = (transaction, userId) => {
return transaction.reviews.filter(r => r.author.id.uuid === userId.uuid)[0];
return transaction.reviews.filter(
r => !r.attributes.deleted && r.author.id.uuid === userId.uuid
)[0];
};

const Transition = props => {
Expand Down Expand Up @@ -240,18 +244,23 @@ const Transition = props => {
);
const currentTransition = transition.transition;

const deletedReviewContent = intl.formatMessage({ id: 'ActivityFeed.deletedReviewContent' });
let reviewComponent = null;

if (transitionIsReviewed(lastTransition)) {
if (isCustomerReview(currentTransition)) {
const review = reviewByAuthorId(currentTransaction, customer.id);
reviewComponent = (
reviewComponent = review ? (
<Review content={review.attributes.content} rating={review.attributes.rating} />
) : (
<Review content={deletedReviewContent} />
);
} else if (isProviderReview(currentTransition)) {
const review = reviewByAuthorId(currentTransaction, provider.id);
reviewComponent = (
reviewComponent = review ? (
<Review content={review.attributes.content} rating={review.attributes.rating} />
) : (
<Review content={deletedReviewContent} />
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ActivityFeed.deletedListing": "deleted listing",
"ActivityFeed.deletedReviewContent": "This review is deleted.",
"ActivityFeed.leaveAReview": "Leave a review for { displayName }.",
"ActivityFeed.leaveAReviewSecond": "Leave a review for { displayName } to see their review.",
"ActivityFeed.ownTransitionAccept": "You accepted the booking request.",
Expand Down

0 comments on commit 5f3d4fc

Please sign in to comment.