Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Created IOU preview component within chat #2112

Merged
merged 35 commits into from
Apr 26, 2021
Merged

[No QA] Created IOU preview component within chat #2112

merged 35 commits into from
Apr 26, 2021

Conversation

tugbadogan
Copy link
Contributor

@tugbadogan tugbadogan commented Mar 26, 2021

@iwiznia @Julesssss

Details

  • Added IOU Preview component
  • Fetched required iou data from Onyx
  • Implemented the Quote section
  • Implemented IOU Preview UI

Fixed Issues

Fixes #2027

Tests

  • Logged in to account Tugba Oge and requested money from user Fadime Dogan.
  • Verified quote and preview box working as expected.
  • Paid money via API call.
  • Once IOU is settled, verified that there is a separate quoted message about settlement and there is no preview box.

QA Steps

For now, this is only testable internally. The cancel/decline cases will be tested as part of the IOU Details PR, which will introduce that functionality. For now, I have been testing this with API calls.

  • Login to user X
  • Create IOU transaction with user Y via UI or API call as mentioned in issue description [Chat] [IOU] Create Preview Component #2027
  • Open 1:1 chat with the person from transaction
  • Observe that there is a quoted message about the request and preview box with amount and Y owes X message.
  • Login to user Y
  • Open 1:1 chat with user X
  • Observe that there is a quoted message about the request and preview box with amount, Y owes X message and Pay button.
  • Pay the IOU transaction with API call
  • For both users, observe that there is a quoted message about the settlement. Make sure there is no preview box.
  • Create a new transaction
  • Cancel the transaction
  • For both users, the Preview component should not display

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Owner / Manager Views

Group Chat View
Screenshot 2021-03-30 at 16 16 21

Mobile Web

Owner / Manager Views

Desktop

Owner / Manager Views

iOS

Owner / Manager Views

Android

Owner / Manager Views

@tugbadogan tugbadogan requested a review from a team as a code owner March 26, 2021 18:23
@botify botify requested review from NikkiWines and removed request for a team March 26, 2021 18:24
Comment on lines 38 to 41
report: PropTypes.shape({

// IOU report ID associated with current report
iouReportID: PropTypes.number,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason not to just pass the reportID at this stage, and subscribe to the full report Onyx further down the Component chain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I can pass just iouReportID here. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this was addressed and I think @Julesssss was suggesting that we pass the iouReportID directly instead of subscribing to the entire report object.

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far.

Just to let you know, until now group chat IOU actions have been of type ADDCOMMENT, but we've changed this to be an IOU action, which should make it easier to render the Quote component in group chats.

[This change is currently on staging.expensify.com]

@tugbadogan
Copy link
Contributor Author

Just to let you know, until now group chat IOU actions have been of type ADDCOMMENT, but we've changed this to be an IOU action, which should make it easier to render the Quote component in group chats.

Do we use the same API method for creating transactions in group chat? Should I worry about different transaction types, request money and split bill?

@Julesssss
Copy link
Contributor

Do we use the same API method for creating transactions in group chat? Should I worry about different transaction types, request money and split bill?

Good question, sorry I didn't share this to begin with:

  • Creating a group split is done with this API request (you will first need to create a report for these users via this API and pass that reportID)
  • This simply creates creates a 1:1 IOU for each individual participant and the bill creator (so in the example above, 2 IOU reports are created: jules | jules+4, jules | jules+6)
  • No need to worry about different types, once the above request is made, you will still interact with IOUActions in a 1:1 report in the usual way
  • The exception is that within a group chat the IOUAction contains participant names -- which you can use to display all participants in the quote message. The Preview Component within group chats should look like the following (no View Details link, all participants listed):

Chat (9)
FAB Open (2)

@tugbadogan
Copy link
Contributor Author

Hey @Julesssss

When I called PayIOU API method, iouReportId key is removed from report, hasOutstandingIOU key is set to true and reportIOUs_ object is deleted from Onyx. So, I cannot fetch state, status and I cannot display the paid amount on the preview box as I don't have access to the transactions anymore.

Is there anywhere else that I can find settled IOUs, so I can display the paid amount?

@Julesssss
Copy link
Contributor

Julesssss commented Mar 30, 2021

Is there anywhere else that I can find settled IOUs, so I can display the paid amount?

Hey @tugbadogan, we won't show the lower preview section (component B) if the balance is 0. Sorry, I forgot to mention this in the original description. This should resolve the problem of displaying the Paid amount.

However, I realise now that this same issue will apply to the view details link -- let me investigate and get back to you.

@Julesssss
Copy link
Contributor

Actually ignore that last part, the view details link isn't part of this PR 🙃

@tugbadogan tugbadogan changed the title [Draft] Created IOU preview component within chat Created IOU preview component within chat Mar 30, 2021
@tugbadogan
Copy link
Contributor Author

I updated the PR. It's ready for review.

@Julesssss
Copy link
Contributor

Nice work! Here are some things I've noticed:

  1. Once an IOU is settled we don't need to render the component
    I think we need to check isMostRecentIOUReport AND report.hasOutstandingIOU

Screenshot 2021-03-31 at 14 43 37

  1. If you don't have a reason, we should remove the 'for': (Requested $9 from Jules for)

Screenshot 2021-03-31 at 15 07 17

  1. When a transaction is cancelled, we don't seem to be immediately updating other IOUs.
    • the middle component should be hidden, (this happens after a refresh)
    • device-2021-03-31-151535
    • the preview component should say $5, not $10 -- I can see the cachedTotal is correctly showing $5
    • Screenshot 2021-03-31 at 15 21 50

Also, we should just show a users first name for the requested quote message (but this is a separate backend issue)

Comment on lines 185 to 187
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already have reportID, isn't this unnecessary -- now that we simply pass reportID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is chatReportID but we need iouReportID and we need to fetch chatReport first to use report.iouReportID in child component's withOnyx. I'm now passing report to use report.hasOutstandingIOU anyway.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pass the iouReportID or anything else we need directly?

@tugbadogan
Copy link
Contributor Author

  1. Once an IOU is settled we don't need to render the component
    I think we need to check isMostRecentIOUReport AND report.hasOutstandingIOU

👍

  1. If you don't have a reason, we should remove the 'for': (Requested $9 from Jules for)

These action messages are generated on server side. Should I modify the message on the client side?

  1. When a transaction is cancelled, we don't seem to be immediately updating other IOUs.
    • the middle component should be hidden, (this happens after a refresh)
    • the preview component should say $5, not $10 -- I can see the cachedTotal is correctly showing $5

I fixed these issues 👍

Also, we should just show a users first name for the requested quote message (but this is a separate backend issue)

Agreed, this is similar to 'for' issue. It is better to fix this on backend.

@iwiznia
Copy link
Contributor

iwiznia commented Mar 31, 2021

These action messages are generated on server side. Should I modify the message on the client side?

No, but after the for there should be the comment of the request, I think that we are not removing the for when there's no comment. I will make a PR to handle that

Also, we should just show a users first name for the requested quote message (but this is a separate backend issue)

Will handle this too.

@Julesssss
Copy link
Contributor

I ran through the full flow on web, Android, and iOS. I can see the last issues I mentioned have been fixed, but noticed one remaining issue:

When I pay/decline/create an IOU transaction I see the storage being updated locally. But, we're not updating the current page. I think this is because we're updating the wrong data store. I see the IOUReport being persisted as a regular report under reports_123, instead of reportIOUs_123.

@Julesssss
Copy link
Contributor

Julesssss commented Apr 1, 2021

Just wanted to leave the test flow that I ran though here, in case anyone else tests this over the UK easter bank holiday:

1 . Open report with 0 IOUs
2. No preview components should be visible
3. Create an IOU transaction 
4. Preview component should be visible
5. Create a second IOU transaction 
6. A quote message should appear for each, but the preview should only show on the most recent IOU transaction
7. Create a 3rd transaction
8. Cancel a transaction (as the user who created them)
9. Quote should read 'Cancelled'  
10. Decline a transaction (as the user who received them)
11. Quote should read 'Declined'   
12. Pay the IOU
13. Preview should not display

IOU API requests

CreateIOUReport
Requesting money from another person

curl --request POST \
  --url 'https://expensify.cash/api?command=CreateIOUTransaction' \
  --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
  --cookie 'email=admin%2540verified.com; accountID=262; authToken=B2C581...DAE9A' \
  --form debtorEmail=jules+2@expensify.com \
  --form currency=USD \
  --form 'comment=Ice cream' \
  --form amount=299

CreateIOUSplit
Splitting bill of $15.00 between myself and two others -- must first create a chat with CreateChatReport if one doesn't already exist

curl --request POST \
  --url 'https://expensify.cash/api?command=CreateIOUSplit' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --cookie 'email=jules%2540expensify.com; accountID=2; authToken=4FC46..817617' \
  --data reportID=712 \
  --data amount=1500 \
  --data currency=USD \
  --data 'splits=[{"amount":500,"email":"jules@expensify.com"},{"amount":500,"email":"jules+6@expensify.com"},{"amount":500,"email":"jules+5@expensify.com"}]'

CreateChatReport
Must occur prior to CreateIOUSplit if you don't already have the reportID

curl --request POST \
  --url 'https://expensify.cash/api?command=CreateChatReport' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --cookie 'email=jules%2540expensify.com; accountID=2; authToken=4FC46...817617' \
  --data 'emailList=["jules+4@expensify.com","jules+6@expensify.com","jules+6@expensify.com","jules+5@expensify.com"]'

Pay IOU
Pay outstanding amount to close IOU

curl --request POST \
  --url 'https://expensify.cash/api?command=PayIOU' \
  --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
  --cookie 'email=admin%2540verified.com; accountID=262; authToken=B2C581...DAE9A' \
  --form reportID=778 \
  --form paymentMethodType=Venmo

Decline IOU
Cancel or decline a single IOU transaction/request

curl --request POST \
  --url 'https://expensify.cash/api?command=RejectTransaction' \
  --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
  --cookie 'email=admin%2540verified.com; accountID=262; authToken=B2C581...DAE9A' \
  --form reportID=776 \
  --form transactionID=4294967349 \
  --form 'comment='\''I dispute this!'\'''

Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately there seems to have been a slight regression with the latest changes. As the user who creates a group chat, sends a message, and then an IOU split for that group, we should see the following Onyx data created for each individual 1:1

report_940
reportActions_940
reportIOUs_941       --> This is being created as reportIOUs_940

Screenshot 2021-04-21 at 16 49 40

So we're creating the chat reports, but not creating or linking to the IOUReport. Other than this and the issue where IOUReports are not retrievable via the push data, everything else is testing well.

@Julesssss
Copy link
Contributor

To round up the feedback:

Once that's done I'll ping the remaining reviewers and run the test flows once more.

@tugbadogan
Copy link
Contributor Author

Unfortunately there seems to have been a slight regression with the latest changes. As the user who creates a group chat, sends a message, and then an IOU split for that group, we should see the following Onyx data created for each individual 1:1

So we're creating the chat reports, but not creating or linking to the IOUReport. Other than this and the issue where IOUReports are not retrievable via the push data, everything else is testing well.

I tested split bill flow for a group chat. The problem is caused by push notification being sent with iouReportID for each report in the group instead of chatReportID. You solved this issue with 1:1 IOU report creation.

report_940
reportActions_940
reportIOUs_941       --> This is being created as reportIOUs_940

Screenshot 2021-04-21 at 16 49 40

In this example 940 is iouReportID so reportIOUs_940 is created as expected. report_940 and reportActions_940 shouldn't be created with this id. If you can fix the push notifications being sent with chatReportIDs, this problem shouldn't occur.

@tugbadogan
Copy link
Contributor Author

@Julesssss
This is request for IOU split action. I think it returns created IOU report IDs in reportIDList.

Screenshot 2021-04-22 at 00 45 51

And we are getting push notifications for these IOU report IDs.

Screenshot 2021-04-22 at 00 51 37

When we call Get API method for reportStuff we get details about IOU report as expected.

Screenshot 2021-04-22 at 00 47 24

@Julesssss
Copy link
Contributor

I tested split bill flow for a group chat. The problem is caused by push notification being sent with iouReportID for each report in the group instead of chatReportID. You solved this issue with 1:1 IOU report creation.

Great spot! Thanks for pointing this out... I've just fixed this and will report back once this change has gone live on prod.

Julesssss
Julesssss previously approved these changes Apr 23, 2021
Copy link
Contributor

@Julesssss Julesssss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Not sure what happened with the last commit, but thanks for reverting.

I've tested the flows against this internal Web-E PR which fixes the push notification problem we introduced. It also requires pulling the latest Auth changes and rebuilding.

I'll update the test steps to let QA know what is testable at this stage. I think for now this should be tested internally.

@Julesssss
Copy link
Contributor

@NikkiWines @marcaaron @AndrewGable -- not much has changed since your previous reviews, but I'll leave the PR open for a couple of hours in case you have any last thoughts.

@Julesssss Julesssss changed the title Created IOU preview component within chat [No QA] Created IOU preview component within chat Apr 23, 2021
@iwiznia
Copy link
Contributor

iwiznia commented Apr 23, 2021

Seems you've got conflicts @tugbadogan, can you resolve them please?

@tugbadogan
Copy link
Contributor Author

Resolved the conflicts.

@Julesssss Julesssss merged commit ac3ca58 into Expensify:main Apr 26, 2021
@OSBotify
Copy link
Contributor

OSBotify commented May 8, 2021

🚀 Deployed to production in version: 1.0.39-5🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Chat] [IOU] Create Preview Component
10 participants