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

[Manual Requests] Create thread for Manual Request when opening IOUPreview #18760

Merged
merged 26 commits into from
May 15, 2023

Conversation

bondydaa
Copy link
Contributor

@bondydaa bondydaa commented May 11, 2023

Details

This will create a thread for a Manual Request if one does not exist yet when a user click to open a Manual Request.

Fixed Issues

$ https://github.com/Expensify/Expensify/issues/278887
$ https://github.com/Expensify/Expensify/issues/270591

Tests

  • Verify that no errors appear in the JS console
  1. As userA create a chat with userB
  2. Request money from userB - $10 for lunch
  3. Click on the IOUPreview
  4. Make sure you have been navigated to a new chat report
  5. Verify you got a new report in LHN with title: $10 request for lunch
  6. Send a message in this report
  7. As userB verify you got this report in your LHN
  8. Got to the DM with UserA as userB
  9. Verify the IOUPreview has replies UI underneath like so
image
  1. Click on the IOUPreview for the $10 request
  2. Verify you are navigated to the same thread created after UserA sent a message in step 6

Offline tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
web.mp4
Mobile Web - Chrome

Cant sign in on mWeb android locally for some reason, dont want to hold on this though tried to figure out but its happening on main too

Mobile Web - Safari
iosweb.mov
Desktop
web.mp4
iOS
ios.mp4
Android
android.mp4

@bondydaa bondydaa requested a review from luacmartins May 11, 2023 00:48
@bondydaa bondydaa self-assigned this May 11, 2023
src/libs/ReportUtils.js Outdated Show resolved Hide resolved
@bondydaa
Copy link
Contributor Author

Okay getting closer. I've got the optimistic report stuff done, via the logs I (accidentally) committed you can see the object has the proper data
image

But I need to look closer at what's happening when that gets to the API and Auth b/c right now when I look up the report in the db for this it's not right:

sqlite> select * from reports where reportid=5450562980361980;
   created = 2023-05-12 05:07:27
 submitted =
  approved =
  reportID = 5450562980361980
 accountID = 0
 managerID =
reportName = Chat Report
     state = 0
     total = 0
  currency = USD
cachedData =
    status = 0

that good news 🎉 is that the rNVP is being created properly :success:

sqlite> select * from reportNameValuePairs where value=3983353111135864060;
reportID = 5450562980361980
    name = parentReportActionID
   value = 3983353111135864060

Copy link
Contributor

@luacmartins luacmartins 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. Just a few minor comments.

src/components/ReportActionItem/MoneyRequestAction.js Outdated Show resolved Hide resolved
src/components/ReportActionItem/MoneyRequestAction.js Outdated Show resolved Hide resolved
src/components/ReportActionItem/MoneyRequestAction.js Outdated Show resolved Hide resolved
console.log({optimisticThreadReport});
Report.openReport(
optimisticThreadReport.reportID,
[_.reject(optimisticThreadReport.participants, (login) => login === lodashGet(props.session, 'email', ''))],
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be the same as props.chatReport.participants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't 100% sure since the API param for participants says it shouldn't include the user making the request: https://github.com/Expensify/Web-Expensify/blob/335001f0f64bf449fc884456ef1911cd1e6f17d5/lib/ReportAPI.php#L4404-L4405

Copy link
Contributor Author

Choose a reason for hiding this comment

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

okay asked about this here https://expensify.slack.com/archives/C02HWMSMZEC/p1683912289696679?thread_ts=1683911072.385549&cid=C02HWMSMZEC

And looks like it doesn't really matter if we include the user making the request here because in Auth here we make sure to include them and since set doesn't allow duplicates we are fine https://github.com/Expensify/Auth/blob/dbd779f7c423a82d4871d6dc076ecb37406fb43c/auth/command/OpenReport.cpp#L77

src/languages/en.js Outdated Show resolved Hide resolved
src/libs/ReportUtils.js Show resolved Hide resolved
@bondydaa
Copy link
Contributor Author

Okay I addressed all the comments but for some reason I'm still unsure why the optimistic report object that is being passed to OpenReport isn't leading to the data in the DB being set properly.

sqlite> select * from reports where reportid=2326627911912510;
   created = 2023-05-12 18:52:46
 submitted =
  approved =
  reportID = 2326627911912510
 accountID = 0
 managerID =
reportName = Chat Report
     state = 0
     total = 0
  currency = USD
cachedData =
    status = 0

The thread does get created though which is our main goal here

sqlite> select * from reportNameValuePairs where value=3983353111135864060;
reportID = 2326627911912510
    name = parentReportActionID
   value = 3983353111135864060

when testing this I've had to manually delete the data from the DB and also out of the localDB by searching report_[reportID] and clicking delete otherwise the front end still thinks a thread already exists.

I have to sign off for now so if someone can take this over that would be great. I don't expect to be online Monday but if I am able to then I'll let people know.

);
console.log({optimisticThreadReport});
Report.openReport(optimisticThreadReport.reportID, optimisticThreadReport.participants, optimisticThreadReport);
}
if (hasMultipleParticipants) {
Navigation.navigate(ROUTES.getReportParticipantsRoute(props.chatReportID));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that I think in order to get the newly created thread to show up we'll need to have something like GetChats triggered OR navigate to the report here in this section.

@Julesssss and @luacmartins had mentioned that this might be in the works else where as well but I'm not sure of a GH or anything for it.

If nothing changes here with these routes then the modal will continue to open instead of going to the thread.

@mountiny mountiny self-assigned this May 13, 2023
@fedirjh

This comment was marked as resolved.

Copy link
Contributor

@luacmartins luacmartins 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! We'll also need to update the thread report to display the MoneyRequestHeader component

Comment on lines +99 to +116
const participants = _.uniq([props.session.email, props.action.actorEmail]);
const formattedUserLogins = _.map(participants, (login) => OptionsListUtils.addSMSDomainIfPhoneNumber(login).toLowerCase());
const thread = ReportUtils.buildOptimisticChatReport(
formattedUserLogins,
props.translate('iou.threadReportName', {
formattedAmount: CurrencyUtils.convertToDisplayString(lodashGet(props.action, 'originalMessage.amount', 0), lodashGet(props.action, 'originalMessage.currency', '')),
comment: props.action.originalMessage.comment,
}),
'',
CONST.POLICY.OWNER_EMAIL_FAKE,
CONST.POLICY.OWNER_EMAIL_FAKE,
false,
'',
undefined,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
props.action.reportActionID,
props.chatReportID, // Needs to be changed to iouReportID
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, we should create an utils method. Seems ok to leave it for now given that this is blocking other issues

// If the childReportID is not present, we need to create a new thread
const childReportID = lodashGet(props.action, 'childReportID', '0');
if (childReportID === '0') {
const participants = _.uniq([props.session.email, props.action.actorEmail]);
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 just filter those out?

@mountiny
Copy link
Contributor

@fedirjh can you try on a fresh account? with all these fast changes there might be something stale :/

@fedirjh
Copy link
Contributor

fedirjh commented May 15, 2023

@mountiny hmm on staging this is working well. Seems like using the staging server locally fix it. Updating the PR checklist shorlty

@mountiny
Copy link
Contributor

Lovely, thanks!

@trjExpensify
Copy link
Contributor

Wahoo, thanks a lot @fedirjh! ❤️ We're hoping to get this one merged today to unblock a couple of other PRs for EC3. 🙏

@fedirjh
Copy link
Contributor

fedirjh commented May 15, 2023

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
Desktop.mov
Mobile Web - Chrome
Screen.Recording.2023-05-15.at.6.25.12.PM.mov

Offline

Screen.Recording.2023-05-15.at.6.58.45.PM.mov
Mobile Web - Safari Screenshot 2023-05-15 at 6 23 00 PM Screenshot 2023-05-15 at 6 23 08 PM Screenshot 2023-05-15 at 6 23 27 PM

Simulator Screenshot - iPhone 14 - 2023-05-15 at 18 22 26

Desktop
Screen.Recording.2023-05-15.at.6.18.46.PM.mov
iOS
IOS.mov
Screenshot 2023-05-15 at 6 36 47 PM
Android
Screen.Recording.2023-05-15.at.6.49.55.PM.mov
Screenshot 2023-05-15 at 6 50 53 PM Screenshot 2023-05-15 at 6 51 05 PM

Copy link
Contributor

@fedirjh fedirjh left a comment

Choose a reason for hiding this comment

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

LGTM and tests well.

@melvin-bot
Copy link

melvin-bot bot commented May 15, 2023

🎯 @fedirjh, thanks for reviewing and testing this PR! 🎉

An E/App issue has been created to issue payment here: #18964.

@mountiny mountiny requested a review from luacmartins May 15, 2023 18:19
@mountiny
Copy link
Contributor

@fedirjh thank you!

@luacmartins lets merge this and handle the rest in follow up PRs.

Copy link
Contributor

@luacmartins luacmartins left a comment

Choose a reason for hiding this comment

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

LGTM! As discussed, we need a followup to use the right report header for transaction threads

@luacmartins luacmartins merged commit b744bd3 into main May 15, 2023
@luacmartins luacmartins deleted the bondy-thread-manual-requests branch May 15, 2023 18:27
OSBotify pushed a commit that referenced this pull request May 15, 2023
[Manual Requests] Create thread for Manual Request when opening IOUPreview

(cherry picked from commit b744bd3)
OSBotify added a commit that referenced this pull request May 15, 2023
@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by https://github.com/luacmartins in version: 1.3.14-6 🚀

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

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/yuwenmemon in version: 1.3.14-14 🚀

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

@OSBotify
Copy link
Contributor

🚀 Cherry-picked to staging by https://github.com/AndrewGable in version: 1.3.28-2 🚀

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

@Expensify/applauseleads please QA this PR and check it off on the deploy checklist if it passes.

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.3.28-5 🚀

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

comment: props.action.originalMessage.comment,
}),
'',
CONST.POLICY.OWNER_EMAIL_FAKE,
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from IOU - Workspace avatar shows 'U' avatar before reverting to actual avatar in IOU view:
We could use real policyID from iouReport to avoid flickering in offline mode.

lodashGet(props.iouReport, 'policyID', CONST.POLICY.OWNER_EMAIL_FAKE)

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.

9 participants