julkascript / cardflow

The open-source Trading Card Game market
MIT License
10 stars 4 forks source link

Implement feedbacks on the frontend #89

Closed RyotaMitaraiWeb closed 2 months ago

RyotaMitaraiWeb commented 2 months ago

This PR makes the feedback part of the orders modal functional.

For now, the frontend retrieves the feedback for each of the displayed orders in the table, which is mostly so that they can be loaded instantly when the modal is opened. Buyers can leave a review at any point of the order (which is at least what happens on the backend, since you can leave a review even in an ordered state). Whether the save button is disabled has also been updated to account for the possibility of leaving a review.

Tests have been updated and some new ones have been added to reflect the new features.

Let me know if there are any issues

julkascript commented 2 months ago

Looks and feels good, however, I found the following bug:

  1. I have 1 review already in the table
  2. Review order
  3. Write the order and the stars
  4. Save
  5. Open the modal -> the review is there
  6. Refresh the page, open the modal -> the review is gone
  7. Cannot write and save a new one

Also, I've been thinking - the "Review Order" button would look nicer if it's of variant outlined, and color primary.

julkascript commented 2 months ago

Also, let's make it, so reviews can only be left after the order is completed or rejected. I'll fix it in the backend.

RyotaMitaraiWeb commented 2 months ago

I was unable to reproduce the bug, unfortunately. If it's an issue on the front-end, my guess would be incorrect retrieval of the feedback for the given order, but I'd need to investigate further before I can conclude

The other comments have been implemented, I also updated tests again to reflect this

RyotaMitaraiWeb commented 2 months ago

To be more specific about the bug, I tried creating multitudes of orders and reviews from three different accounts and everything works correctly on my side, even after refreshing on all ends

RyotaMitaraiWeb commented 2 months ago

Update: I managed to reproduce the bug on my end, so I can confirm it exists, I will investigate more

RyotaMitaraiWeb commented 2 months ago

so upon further investigation, I am 90% sure this is a bug on the backend, not on the frontend, since I managed to reproduce it even with the Swagger client + I think I know where the issue is coming from

How to actually reproduce the bug To reproduce the bug, do the following (assuming a clean database with no prior orders and feedbacks):

  1. Check out two separate orders. From now on, the first order will be referred to as order one and the second one as order two. Do NOT leave any reviews until you can see both orders in the "My orders" page.
  2. Get both orders to completed or rejected state
  3. Leave a review for order two (do NOT leave any review for order one)
  4. Refresh
  5. Notice that the review is missing from order two. However, if you open the modal for order one, you will notice that the review you left is there instead.

The issue seems to come from how the backend retrieves the feedbacks, more specifically on line 85 in order/views.py. From what I read, zip will pair the nth element of each collection together until the smallest one gets exhausted. Because our review, intended for order two, is the first one to be retrieved (as it's the only one in the database) and order one is the first order to be retrieved (because it was created first), they end up paired together, thus the backend tells me that this review's order ID is 1 (the correct ID would be 2).

Another way to confirm the existence of an issue with the retrieval is to compare what the backend tells you with what the DB tells you (via PGAdmin4). The database correctly maps our review to order two, but the backend will tell you that the review is intended for order one

julkascript commented 2 months ago

@milensski @dinocom33 can you guys check this bug out?

milensski commented 2 months ago

Hi,

I was able to reproduce the bug even with 18 orders, when I made a review to order 14 it went in order 1, I will examine it and will fix.

@RyotaMitaraiWeb Thanks for looking into it , I will check your advise first.