App icon indicating copy to clipboard operation
App copied to clipboard

[Chat] [IOU] Create IOUConfirm step

Open Jag96 opened this issue 5 years ago β€’ 21 comments

If you haven’t already, check out our contributing guidelines for onboarding!


Upwork Posting: https://www.upwork.com/jobs/~01744b3390e36e5f36

This issue builds on top of the existing IOU Modal, which was implemented in this PR. The IOU Confirm step page has already been created and is a controlled component (IOUModal manages its state).

The Confirm step allows users to confirm the 'request money' (1:1) or 'bill split'(multiple participants) amount and the participants they are requesting payment from. To open the Modal, you can navigate to localhost:8080/iou/request AND localhost:8080/iou/split.

You can also launch the IOUModal by temporarily modifying the routes in CreateMenu. Launch the request money flow with Navigation.navigate(ROUTES.IOU_REQUEST) and the bill split flow with Navigation.navigate(ROUTES.IOU_BILL)

Mobile & mobile web Confirm Confirm Split

Web & Desktop FAB Open

Deliverables:

  1. The title should match the title from the Participants step (step 2). This will be 'Split' or 'Request', followed by the amount. (for example: 'Split $42.00' || Request $42.00)
  2. If the IOU flow is for a bill split, then we should display the current user under the 'WHO PAID?' title (this is not shown for the request money flow)
  3. We then need to display all participants other than the current user. With the amount that they will need to pay (total amount, split equally between amount of participants)
    1. If 'Bill split' flow, then we should reuse the list from the IOUParticipantsSplit page
    2. If 'Request money' flow, then we simply display a single user under the 'To' heading
  4. An input field should allow the user to input an optional comment for the IOU request
  5. The button label should read 'Request $[currency][amount]' or 'Split bill' if there are multiple participants
  6. A new API function should be created within API.js: createIOUTransaction, which will be called from IOUModal to create the IOU (details for this request can be found below).
  7. When the user hits this button, we should pass the comment input string up to IOUModal via the existing onStepComplete callback (or something similar), and we should then call the new createIOUTransaction API function from within a new IOUAction function.
    1. We should show a loading indicator in the button (using ButtonWithLoader), by setting the Onyx IOU key to IOU: {loading:true}. We should display a loading indicator in the Button while this is true.
    2. Within this new IOUAction function we should await a successful response to createIOUTransaction, and then pass the returned reportID value to GetIOUReport, to retrieve the full IOUReport details
    3. Then, we should persist the simplified version of these details to Onyx, just like we are doing here
  8. Finally, back in IOUModal we should subscribe to the reportIOU_ Onyx key. Once we notice that the new IOU data has been persisted to Onyx (when we persist the data in step 7, we should receive this in our Onyx subscription). Once this value is not null, we know that the report has successfully been created and persisted to Onyx, so we can close the IOU Modal.

CreateIOUTransaction API Example of the API which is used to create the IOU request / split.

curl --request POST \
  --url 'https://expensify-jules.ngrok.io/api?command=CreateIOUTransaction' \
  --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
  --cookie 'email=jules%252B3%2540expensify.com; accountID=12; authToken=66ADF90...22AE918' \
  --form [email protected] \
  --form currency=USD \
  --form 'comment=Pizza πŸ•' \
  --form amount=550

Expensify/Expensify Issue URL: https://github.com/Expensify/Expensify/issues/157782

Jag96 avatar Mar 22 '21 18:03 Jag96

Hey @Jag96, I notice you have self-assigned this issue. Is it still pending a proposal? In that case, I would like to contribute to this issue. The issue's a continuity to an earlier issue I contributed in: #1694

My proposal:

  • Modify getTitleForStep in IOUModal to match the title from IOUParticipants step for the IOUConfirmation page

  • We have two ways to render a page:

      I. If it's Bill Split: 
    
      - In the IOUConfirmation step, add a Text component with the "WHO PAID" label at the beginning of the page. Under the text, we display the current user with a tick mark next to them using `OptionRow`
      - Then, in the second section of the page, we display "WHO WAS THERE" text similarly
      - We reuse the `OptionsSelector` list that is used on the `IOUParticipantsSplit` page
    
      II. If it's Request: 
    
      - Add a text component with "TO" label at the beginning of the page.
      - Use `OptionRow` to display the participant without a tick mark.
    
  • An input field should be added within both flows to ask the user for an optional comment for the request. I will reuse the TextInputWithFocusStyles for this purpose.

  • Finally, the button label should have conditional logic to display either 'Request $[currency][amount]' | 'Split bill' based on the flow

  • I will create a new API.js function called: createIOUTransaction to create the IOU

  • I will use the existing onStepComplete callback to call createIOUTransaction API function within a new async createNewTransaction function in IOUAction

  • Within the function, we will set loading true for the Onyx IOU key by setting it as Onyx.merge(ONYXKEYS.IOU, {loading: true}) before calling createIOUTransaction. I will pass this loading to the button loader's isLoading prop.

  • We then await a successful response to createIOUTransaction and pass the returned reportID to get IOUReport using GetIOUReport

  • We then set loading false for the Onyx IOUKey as well by setting it as: Onyx.merge(ONYXKEYS.IOU, {loading: false});

  • Moreover, we persist the simplified version of the report we get from getSimplifiedIOUReport(iouReport) in Onyx.

  • Also, I will subscribe IOUModal to the reportIOU_ Onyx key, so that when we persist a report in the above step, the IOUModal receives the event. When it does, we will know that the report has been successfully created, so we can close the IOUModal

barun1997 avatar Mar 22 '21 23:03 barun1997

Hi, I would like to work on this issue. Here is my proposal:

  1. The title should match the title from the Participants step (step 2). This will be 'Split' or 'Request', followed by the amount. (for example: 'Split $42.00' || Request $42.00)

I will modify first if condition here to have same title with Participants step: https://github.com/Expensify/Expensify.cash/blob/fa6185b2c51fdc0f28ab9cbc48b8a306f64a537d/src/pages/iou/IOUModal.js#L65-L73

  1. If the IOU flow is for a bill split, then we should display the current user under the 'WHO PAID?' title (this is not shown for the request money flow)

I will pass hasMultipleParticipants prop to IOUConfirmPage component to distinguish bill split and request money. If it is a bill split, I will show 'WHO PAID?' title.

  1. We then need to display all participants other than the current user. With the amount that they will need to pay (total amount, split equally between amount of participants)

    1. If 'Bill split' flow, then we should reuse the list from the IOUParticipantsSplit page

I will pass participants array from IOUModal's state to IOUConfirmPage component as a prop. With iouAmount and participants list, I will calculate the amount they will need to pay within IOUConfirmPage component.

https://github.com/Expensify/Expensify.cash/blob/fa6185b2c51fdc0f28ab9cbc48b8a306f64a537d/src/pages/iou/IOUModal.js#L48

  1. If 'Request money' flow, then we simply display a single user under the 'To' heading

Again, using hasMultipleParticipants prop, I will show 'To' heading with single participant.

  1. An input field should allow the user to input an optional comment for the IOU request

I will add TextInputFocusable element for optional comment.

  1. The button label should read 'Request $[currency][amount]' or 'Split bill' if there are multiple participants

Again, using hasMultipleParticipants prop, I will have custom button label.

  1. A new API function should be created within API.js: createIOUTransaction, which will be called from IOUModal to create the IOU (details for this request can be found below).

I will create an API function that makes a POST request with CreateIOUTransaction command with required fields similar to this one: https://github.com/Expensify/Expensify.cash/blob/4bc32214cd2158a02053da8bf6c3619ad3505d63/src/libs/API.js#L486-L491

  1. When the user hits this button, we should pass the comment input string up to IOUModal via the existing onStepComplete callback (or something similar), and we should then call the new createIOUTransaction API function from within a new [IOUAction] (https://github.com/Expensify/Expensify.cash/blob/fa6185b2c51fdc0f28ab9cbc48b8a306f64a537d/src/libs/actions/IOU.js) function.

I will add a function in IOUModal that calls createIOUTransaction API function and I will pass this function to IOUConfirmPage as onStepComplete prop.

  1. We should show a loading indicator in the button (using ButtonWithLoader), by setting the Onyx IOU key to IOU: {loading:true}. We should display a loading indicator in the Button while this is true.

In this new function, I will update Onyx IOU key to IOU: {loading:true} .

  1. Within this new IOUAction function we should await a successful response to createIOUTransaction, and then pass the returned reportID value to GetIOUReport, to retrieve the full IOUReport details

I'm going to use promise and then to await API call to pass returned reportID value to GetIOUReport.

  1. Then, we should persist the simplified version of these details to Onyx, just like we are doing here

Then I will update Onyx with new data.

  1. Finally, back in IOUModal we should subscribe to the reportIOU_ Onyx key. Once we notice that the new IOU data has been persisted to Onyx (when we persist the data in step 7, we should receive this in our Onyx subscription). Once this value is not null, we know that the report has successfully been created and persisted to Onyx, so we can close the IOU Modal.

I will add withOnyx to IOUModal in order to subscribe to the reportIOU_ Onyx key.

https://github.com/Expensify/Expensify.cash/blob/10a21d6778da60aa913f820e2c93888efb585a9e/src/pages/iou/steps/IOUConfirmPage.js#L45-L47

tugbadogan avatar Mar 22 '21 23:03 tugbadogan

Thanks for both of your submissions. We'll go with @barun1997 as his submission was first.

We have more IOU issues on the way!

Julesssss avatar Mar 23 '21 14:03 Julesssss

@Julesssss Thanks for the assignment! I will start working on it right away.

@Jag96 I've applied for the job posting in Upwork. Please kindly take a look.

barun1997 avatar Mar 23 '21 15:03 barun1997

Hi @Julesssss, I am working to complete this issue, but I just wanted to gain some clarity on createIOUTransaction. After a successful transaction creation, it returns a reportID. In the issue note:

2\. Within this new IOUAction function we should await a successful response to `createIOUTransaction`, and then pass the returned `reportID` value to `GetIOUReport`, to retrieve the full IOUReport details

it is mentioned that this reportID should be passed to GetIOUReport but GetIOUReport expects debtorEmail.

https://github.com/Expensify/Expensify.cash/blob/2b0674b94819926f38e71b4c5c8edf25bebe1ecb/src/libs/API.js#L628-L632

So, my thought process is to instead implement it the way it's implemented in actions/Report.js since we already have a reportID:

https://github.com/Expensify/Expensify.cash/blob/2b0674b94819926f38e71b4c5c8edf25bebe1ecb/src/libs/actions/Report.js#L228-L241

Please let me know if I'm missing something!

barun1997 avatar Mar 25 '21 11:03 barun1997

it is mentioned that this reportID should be passed to GetIOUReport but GetIOUReport expects debtorEmail.

Ah yes, this changed recently. I should have let you know. You've got it though, that would be the ideal solution πŸ‘

Let us know if you have any other questions!

Julesssss avatar Mar 25 '21 11:03 Julesssss

Ahh, gotcha! Thank you.

barun1997 avatar Mar 25 '21 11:03 barun1997

@Julesssss, just a final question regarding API call for CreateIOUTransaction for Split Bills.

The example is:


curl --request POST \
  --url 'https://expensify.com/api?command=CreateIOUTransaction' \
  --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
  --cookie 'email=jules%252B3%2540expensify.com; accountID=12; authToken=66ADF90...22AE918' \
  --form [email protected] \
  --form currency=USD \
  --form 'comment=Pizza πŸ•' \
  --form amount=550 

It works perfectly when I send a single debtorEmail, but for Split, we'd have multiple emails. Could you give me an example for CreateIOUTransaction in the case of a Split Bill? Thank you for your help!

barun1997 avatar Mar 26 '21 14:03 barun1997

Ah yes, this is a totally different API. I probably should have shared all of them, rather than those I thought would be necessary πŸ™ƒ

/CreateIOUSplit

curl --request POST \
  --url 'https://expensify.com/api?command=CreateIOUSplit' \
  --header 'Content-Type: application/x-www-form-urlencoded' \
  --cookie 'email=REDACTED; accountID=REDACTED; authToken=REDACTED' \
  --data reportID=786 \
  --data amount=100 \
  --data currency=USD \
  --data 'splits=[{"amount":50,"email":"[email protected]"},{"amount":50,"email":"[email protected]"}]'

Julesssss avatar Mar 26 '21 15:03 Julesssss

Haha! Makes sense now. Thank you! @Julesssss

barun1997 avatar Mar 26 '21 15:03 barun1997

Can you please link to your draft PR once you have one @barun1997?

iwiznia avatar Mar 26 '21 18:03 iwiznia

Reopening this, it seems that there is still a regression related to the original fix. cc @barun1997

Jag96 avatar Apr 19 '21 17:04 Jag96

I will take a look, thank you!

barun1997 avatar Apr 20 '21 02:04 barun1997

Hi, I looked at this issue today, but still can't seem to wrap my head around it to find a proper solution. The problem is that I fixed the original solution by restricting it to flexGrow0 so it doesn't take the remaining space. But if I do let it default to flex1, this allows it to scroll, but it takes all the available space. Screenshot 2021-04-21 at 17 11 41

I will make another try tomorrow, but I'm open to your suggestions!

barun1997 avatar Apr 21 '21 11:04 barun1997

I don't have any specific suggestions, but it might be worth sharing the problem in the expensify-open-source channel to get more eyes on the problem.

Julesssss avatar Apr 21 '21 16:04 Julesssss

@Julesssss Thank you! I have shared it in the Slack Group.

barun1997 avatar Apr 22 '21 03:04 barun1997

@barun1997 have you done any further investigation on how to fix this?

Jag96 avatar Apr 23 '21 18:04 Jag96

Hi, just to be clear on the specification required:

Is this something we're looking for? https://www.loom.com/share/68ef6b07a742462b955680c094189834

I think I've figured out a solution for this! If this is the desired solution :)

barun1997 avatar Apr 27 '21 12:04 barun1997

Having the input at the bottom with only a few participants is not ideal.

I'm tagging @shawnborton, who may have some ideas on how to solve the scrolling problem.

Julesssss avatar Apr 27 '21 17:04 Julesssss

@Julesssss That's no longer a problem now, fortunately! Just wondering if the scroll action (with comment fixed as in the video) is the desired UX?

barun1997 avatar Apr 27 '21 17:04 barun1997