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

Offline and errors pattern in Quickbooks Online integration #46511

Merged

Conversation

zfurtak
Copy link
Contributor

@zfurtak zfurtak commented Jul 30, 2024

Details

Fixed Issues

$#45406 - partially fixed
PROPOSAL:

Tests

Test errors:

  1. Set Simulate failing network in Troubleshooting (you can set MAX_REQUEST_RETRIES to 0 to get errors faster).
  2. Go to Settings -> Workspaces -> your QuickbooksOnline workspace -> Accounting.
  3. Go through every page and try changing values.
  4. See that there are RBRs and error messages when request fails.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go to Settings -> Workspaces -> your QuickbooksOnline workspace -> Accounting.
  2. Go through every page and try changing values.
  3. See that changed values are on opacity 50%.

QA Steps

Test errors:

  1. Set Simulate failing network in Troubleshooting (you can set MAX_REQUEST_RETRIES to 0 to get errors faster).
  2. Go to Settings -> Workspaces -> your QuickbooksOnline workspace -> Accounting.
  3. Go through every page and try changing values.
  4. See that there are RBRs and error messages when request fails.
  • 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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • 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 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(theme.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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • 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.

Screenshots/Videos

Android: Native #### Offline https://github.com/user-attachments/assets/8bf46e3d-8f15-4a88-a2cf-592bd7ac8df2

Errors

android-error-1.mov
Android: mWeb Chrome

Offline

mweb-android-offline-1.mov

Errors

mweb-android-errors-1.mov
iOS: Native

Offline

ios-offline-1.mov

Errors

ios-error-1.mov
iOS: mWeb Safari

Offline

mweb-ios-offline-1.mov

Errors

mweb-ios-error-1.mov
MacOS: Chrome / Safari

Offline

web-offline-1.mov

Errors

web-error-1.mov
MacOS: Desktop #### Offline https://github.com/user-attachments/assets/beeb1c13-53bc-4be2-8208-28f6dda6febb

Errors

desktop-error-1.mov

Copy link
Contributor

@war-in war-in left a comment

Choose a reason for hiding this comment

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

You've performed a titanic work here 🤯 Please address the comments and then we're ready for C+ review 🔥

@zfurtak zfurtak requested a review from war-in August 7, 2024 13:06
@zfurtak
Copy link
Contributor Author

zfurtak commented Aug 8, 2024

hi @kirillzyusko, since the new React Compiler check was introduced, the flow is failing for me with components that my PR hasn't touched at all.
Could you take a look? 😊
EDIT:
I found errors related to changed files:

  • Reason: Invalid nesting in program blocks or scopes
  • Reason: Unexpected terminal kind optional for ternary test block
  • Reason: React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved...

@kirillzyusko
Copy link
Contributor

Hey @zfurtak

Which errors QuickbooksOutOfPocketExpenseConfigurationPage.tsx file throws? If it's only React Compiler has skipped optimizing this component because the existing manual memoization could not be preserved then it could because of the fact that you've changed useMemo code - maybe it happens because we duplicate dependency and re-use the same expression inside useMemo (maybe worth to create a separate variable and re-use it).

I believe if you run npm run react-compiler-healthcheck then it should print all files with all problematic code and line numbers. Can you go through all these errors and figure out which code causes problems and try to re-work it so that compiler doesn't complain anymore?

@zfurtak
Copy link
Contributor Author

zfurtak commented Aug 8, 2024

I believe if you run npm run react-compiler-healthcheck then it should print all files with all problematic code and line numbers. Can you go through all these errors and figure out which code causes problems and try to re-work it so that compiler doesn't complain anymore?

This is exactly what I did, here is the output I got:

  • ...QuickbooksAdvancedPage.tsx Reason: Invalid nesting in program blocks or scopes
  • ...QuickbooksExportConfigurationPage.tsx:97:111. Reason: Unexpected terminal kind optional for ternary test block
  • ...QuickbooksExportDateSelectPage.tsx:36:8. Reason: React Compiler has skipped optimizing this component because the existing manual ...
  • ...QuickbooksOutOfPocketExpenseConfigurationPage.tsx Reason: Invalid nesting in program blocks or scopes

EDIT:
@kirillzyusko
I managed to solve 2 of these issues, I am left with two files with the same error: Reason: Invalid nesting in program blocks or scopes
Here are links to React Compiler Playground which shows the errors (however they are different)
QuickbooksAdvancedPage.tsx
QuickbooksOutOfPocketExpenseConfigurationPage.tsx

At this point I don't know how to solve them 🧐

@zfurtak zfurtak marked this pull request as ready for review August 8, 2024 12:49
@zfurtak zfurtak requested a review from a team as a code owner August 8, 2024 12:49
@zfurtak
Copy link
Contributor Author

zfurtak commented Aug 14, 2024

hi 👋
I'm still not sure what should I do with the error on the empty page from the first point 🤔
About the second point (offline):
So far I've changed the grey empty list component, but it was with opacity 50% because when we change the value of Export as, we also change the value of the account, sometimes it changes to an empty list and then we see the component. However now it has lower opacity when options exist and 100% on empty list. 😊

About the error messages, we were changing the flow of showing them, however we didn't update the messages and sticked with previous ones (same as on staging).

However I discovered a problem related to this part (video below). 🐛

The title should be Not configured but the value of reimbursableExpensesAccount.name (from QBO config) remains from the previous option, as we pass undefined to onyx. I tried to change it in the code to clear the value with null but the backend doesn't allow it. Could you consider this as a possible issue?

Screen.Recording.2024-08-14.at.14.42.36.mov

cc @ikevin127 @dubielzyk-expensify @shawnborton @trjExpensify

Copy link
Contributor

@ikevin127 ikevin127 left a comment

Choose a reason for hiding this comment

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

2. "Accounting > Export > Export company card expenses as" empty Bank account page is grayed-out after changing Export as while offline | 🟢 FIXED

I'm still not sure what should I do with the error on the empty page from the first point 🤔

Which leaves the issue number 1 with the error placed at the bottom of the empty page:

Screenshot 2024-08-14 at 13 29 57

I think given that the design team doesn't feel strongly about it (ref1, ref2) I think we can leave it like that.

The title should be Not configured but the value of reimbursableExpensesAccount.name (from QBO config) remains from the previous option, as we pass undefined to onyx. I tried to change it in the code to clear the value with null but the backend doesn't allow it. Could you consider this as a possible issue?

Not sure regarding this issue, sounds like we might want to handle it here but it might require BE changes so I'll defer this to assigned CME to decide whether to handle this here or in a new issue.

cc @deetergp on the sentence ^ above!

Otherwise, PR tests well, LGTM 🚀

@melvin-bot melvin-bot bot requested a review from deetergp August 14, 2024 20:48
@deetergp
Copy link
Contributor

Can we elaborate on HOW the backend is preventing us from clearing this out? Which API command is returning the undefined — is it UpdateQuickbooksOnlineReimbursableExpensesAccount?

@war-in
Copy link
Contributor

war-in commented Aug 19, 2024

@deetergp We use the UpdateManyPolicyConnectionConfigurations command here and we want to set nonReimbursableExpensesAccount field to null (or some other value that tells us it's empty).

Now it's done this way

[CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT]: row.accounts[0],

but if the row.accounts is empty we get undefined and send nothing to the backend.

We tried to pass null when the row.accounts[0] is undefined but the backend returned an error:
image

That's why we think this issue is BE related but maybe there is a way of clearing the value. Any help would be appreciated 🙏

@zfurtak
Copy link
Contributor Author

zfurtak commented Aug 26, 2024

hi @deetergp, could you take a look at this issue? 😊

@zfurtak
Copy link
Contributor Author

zfurtak commented Aug 27, 2024

@deetergp
Can we get on with this issue? because it's been in progress for quite a long time so far 😊

@deetergp
Copy link
Contributor

My apologies @zfurtak, I will investigate those BE changes today.

@zfurtak
Copy link
Contributor Author

zfurtak commented Aug 29, 2024

Hello @deetergp, how is it going? 😃

@deetergp
Copy link
Contributor

@zfurtak @war-in Can you give me the policyID for the workspace you are testing with? I found the block where we are throwing it (link, for future me's benefit) but I want to see what's currently stored in the DB for that property. Thanks!

@zfurtak
Copy link
Contributor Author

zfurtak commented Sep 1, 2024

@deetergp sure thing!
Here's the ID of my policy that is connected to QBO: A99CBAAB0B1E1AB3

@zfurtak
Copy link
Contributor Author

zfurtak commented Sep 4, 2024

Hi @deetergp, at the moment the code that connects back and front is being changed, maybe this refactor will fix the problem at the same time. 🤔.
However this bug had existed before this refactor, so I think it could be good to leave it as it is for now and merge this PR as it's been waiting enough already.
What do you think? 😊
cc: @war-in

};
API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, onyxData);
}

function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: IntegrationEntityMap) {
const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS, settingValue);
function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: IntegrationEntityMap, oldValue?: IntegrationEntityMap) {
Copy link
Contributor

@ZhenjaHorbach ZhenjaHorbach Sep 4, 2024

Choose a reason for hiding this comment

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

I have a small proposal
Maybe you will like it 😅

I also started making a similar PR today by mistake
And how do you like this format of typing?

https://github.com/Expensify/App/pull/48525/files#diff-7b811795926d7001296df148e05cadd46ac9cf78bdb6418d2787d1172b8e237bR210-R214

We can be sure that the parameters passed will have correct types
Plus we can reuse TSettingValue for settingValue and oldValue

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 like it! Should I do it right away here or do you prefer to merge your PR? 😊

Copy link
Contributor

Choose a reason for hiding this comment

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

I think yours is better
Since my PR is in draft and requires filling out checklists 😅
Plus it's better to close it since there is your PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 🤓

@deetergp deetergp merged commit fd16fdd into Expensify:main Sep 5, 2024
16 checks passed
@OSBotify
Copy link
Contributor

OSBotify commented Sep 5, 2024

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented Sep 5, 2024

🚀 Deployed to staging by https://github.com/deetergp in version: 9.0.30-0 🚀

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

@@ -92,6 +90,7 @@ function buildOnyxDataForQuickbooksConfiguration<TSettingName extends keyof Conn
policyID: string,
settingName: TSettingName,
settingValue: Partial<Connections['quickbooksOnline']['config'][TSettingName]>,
oldSettingValue?: Partial<Connections['quickbooksOnline']['config'][TSettingName]>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we make this value optional with ?? I think it is not optional and it looks like we are passing it in every call

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's because we pass values from QuickbooksOnline config that can be undefined
e.g. here

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh, I see, thanks!

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.