Skip to content

Authenticate with QBO#39219

Merged
marcaaron merged 48 commits into
mainfrom
hayata-authenticate-with-qbo
Apr 17, 2024
Merged

Authenticate with QBO#39219
marcaaron merged 48 commits into
mainfrom
hayata-authenticate-with-qbo

Conversation

@hayata-suenaga

@hayata-suenaga hayata-suenaga commented Mar 28, 2024

Copy link
Copy Markdown
Contributor

cc: @aldo-expensify

Details

This PR is part of the QBO project where we supports integration with QuickBooks Online, an accounting software, on New Expensify.

This PR adds a button that the user can click to start the authentication flow with the QBO. On both web and native platforms, this button opens up a new web page where the user can authenticate with the QBO. After the authentication is complete, the user's authentication token is stored in the backend and the web page closes.

On a web browser, the web page is opened on a separate browser window. On iOS and Android, a temporary browser window is opened as a modal within the app to display the web page.

Fixed Issues

$ #39094
PROPOSAL: N/A

Tests

Important Notes for testing: When testing the QBO authentication flow:

  • Make sure you are not logged in already with another account in OldDot, otherwise it will use the incorrect authToken in some parts causing failure
  • If you are an Expensify employee, you will have to disable WARP
  1. Create a NewDot account
  2. Create a Workspace
  3. Go to the Workspace's settings page
  4. Go to the "More features" and enable "Accounting" at the bottom
    image
  5. Go to the new "Accounting" menu entry
  6. Click "Set up"
    image
  7. Sign in with a QBO account
  8. The authentication flows opens a new tab. Confirm that after finishing the authentication the tab automatically closes.
  9. Verify that you see an loading spinner while the import is happening
  10. Verify that after the import is done, some new menu entries appear:
    image
  11. Click in the vertical 3 dots and choose "Disconnect"
  12. Click "Disconnect" in the confirmation modal
  13. Verify that there is only the initial menu entry with the "Set up" button

Test on iOS or Android

  1. Create a NewDot account
  2. Create a Workspace
  3. Go to the Workspace's settings page
  4. Go to the "More features" and enable "Accounting" at the bottom
  5. Go to the new "Accounting" menu entry
  6. Click "Set up"
  7. Sign in with a QBO account
  8. The authentication flows opens in a web view inside the App. Confirm that after finishing the authentication the web view automatically closes.
  9. Verify that you see an loading spinner while the import is happening
  10. Verify that after the import is done, some new menu entries appear:
  11. Click in the vertical 3 dots and choose "Disconnect"
  12. Click "Disconnect" in the confirmation modal
  13. Verify that there is only the initial menu entry with the "Set up" button

QA Steps

No QA. The new button is not used yet. There is no way for the QA team to test this.

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.
  • I verified that similar component doesn't exist in the codebase
  • I verified that all props are defined accurately and each prop has a /** comment above it */
  • I verified that each file is named correctly
  • I verified that each component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
  • I verified that the only data being stored in component state is data necessary for rendering and nothing else
  • In component if we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
  • 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)
  • I verified that component 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)
  • I verified that all JSX used for rendering exists in the render method
  • I verified that each 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

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
Screen.Recording.2024-04-16.at.5.58.01.PM.mov
MacOS: Chrome / Safari
Screen.Recording.2024-04-10.at.6.13.30.PM.mov
MacOS: Desktop

@github-actions

This comment has been minimized.

@@ -0,0 +1,7 @@
type WorkspaceIntegrationImportStatus = {
status: 'starting' | 'finished' | 'progress';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can remove the status and just use stageInProgress

@github-actions

github-actions Bot commented Apr 2, 2024

Copy link
Copy Markdown
Contributor

@aldo-expensify aldo-expensify self-assigned this Apr 4, 2024
@aldo-expensify

Copy link
Copy Markdown
Contributor

@hayata-suenaga I see that the PolicyAccountingPage is not even implemented yet, I don't think it makes a lot of sense to work on this yet. Is there a PR implementing PolicyAccountingPage that is on the work? if not I think we should start with that.

@hayata-suenaga

Copy link
Copy Markdown
Contributor Author

@aldo-expensify, this is the PR that is implementing the PolicyAccountingPage. That PR will be merged without the code to actually trigger the authentication flow.

After we finish this PP to open the authentication flow, we will create another PR to add to trigger the authentication flow when the button is clicked.

@aldo-expensify

aldo-expensify commented Apr 8, 2024

Copy link
Copy Markdown
Contributor

@aldo-expensify, this is the PR that is implementing the PolicyAccountingPage.

@hayata-suenaga Did you forget to add the link? :P

@hayata-suenaga

Copy link
Copy Markdown
Contributor Author

oops 😓 🙇 here is the link 😄

@hayata-suenaga

Copy link
Copy Markdown
Contributor Author

@aldo-expensify, just a heads up. Some codes related to the QBO authentication flow were added in this PR that implements the WorksapceAccountingPage.

ex. getQuickBooksOnlineSetupLink and type PolicyConnectionSyncStage

@aldo-expensify
aldo-expensify marked this pull request as ready for review April 11, 2024 01:07
@marcaaron
marcaaron requested review from a team and removed request for a team April 17, 2024 17:47
@aldo-expensify

Copy link
Copy Markdown
Contributor

Added a constant for the command ConnectPolicyToQuickbooksOnline and its corresponding ConnectPolicyToQuickbooksOnlineParams types

@aldo-expensify

Copy link
Copy Markdown
Contributor

Created a follow up issue #40365 for the Desktop bug

marcaaron
marcaaron previously approved these changes Apr 17, 2024

@marcaaron marcaaron left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes LGTM. Did not have any hard blockers, but left some questions and small improvements. Noted that there are mistakes left in the code, but sounds like @aldo-expensify has plans to follow up and address them.

Comment thread src/ROUTES.ts
Cookie: `authToken=${session?.authToken}`,
},
}}
incognito // 'incognito' prop required for Android, issue here https://github.com/react-native-webview/react-native-webview/issues/1352

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NAB, but this comment suggests we should have a platform implementation where the incognito prop is only passed for Android if we don't need it on other platforms.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see what you are saying, but to me the code duplication of adding the index.android.ts is worse. This prop doesn't affect in a negative way for IOS.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we maybe remove the comment about Android?

One downside of leaving platform specific logic in the code is that the many contributors who work on this code will then think it's OK to bend one of our rules.

Comment thread src/components/ConnectToQuickbooksOnlineButton/types.ts Outdated
Comment thread src/libs/API/types.ts
[WRITE_COMMANDS.SET_POLICY_DISTANCE_RATES_UNIT]: Parameters.SetPolicyDistanceRatesUnitParams;
[WRITE_COMMANDS.SET_POLICY_DISTANCE_RATES_DEFAULT_CATEGORY]: Parameters.SetPolicyDistanceRatesDefaultCategoryParams;

// eslint-disable-next-line @typescript-eslint/no-explicit-any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Doesn't look like this was added in this PR but looks related to this project. Why do we need to have any here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ahh this was a problem cause by the generic of the param type here #39219 (comment). We are "forced" to choose something here and any seemed to work good enough.

An alternative would be to define different constants for each combination of <connectionName, settingName>, but that sounds worse I think.

Comment thread src/libs/ApiUtils.ts

if (shouldUseStagingServer) {
if (CONFIG.IS_USING_WEB_PROXY) {
if (CONFIG.IS_USING_WEB_PROXY && !request?.shouldSkipWebProxy) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: since we mainly use the proxy to avoid CORS errors and (I presume) there is no problem with CORS errors when using a WebView this could be updated to something like request.isForWebView. That way we are not exposing the underlying "proxy" or "no proxy" to other areas of the code that don't really need to know about it.

and a question - Is it a problem to use the proxy for this? 🤔 If so, can we please add a comment here about why the proxy does not work for webviews?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since we mainly use the proxy to avoid CORS errors and (I presume) there is no problem with CORS errors when using a WebView this could be updated to something like request.isForWebView.

This problem doesn't only apply to WebViews, it is also there in "web" when the URL opens in a new tab. The URL created when we use the proxy is /CommandName?xxx, it misses the domain, so then the function Link.openLink misses that it needs to get a short lived auth token for it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

isForWebViewOrNewTab 🙃

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

or maybe... requiresShortLivedAuthToken 😬

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah, I like that better.

Comment on lines +28 to +37
// {
// onyxMethod: Onyx.METHOD.MERGE,
// key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
// value: {
// errorFields: {
// avatar: ErrorUtils.getMicroSecondOnyxError('avatarWithImagePicker.deleteWorkspaceError'),
// },
// },
// },
];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it going to cause conflicts to delete this? 🤔

};
API.write(WRITE_COMMANDS.REMOVE_POLICY_CONNECTION, parameters, {optimisticData, failureData});
}
function updatePolicyConnectionConfig<TConnectionName extends ConnectionName, TSettingName extends keyof Connections[TConnectionName]['config']>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did we do too much TypeScript here? 😄

@aldo-expensify aldo-expensify Apr 17, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

haha, I though it could cause problems when using the function updatePolicyConnectionConfig, but it didn't and works pretty well on matching the settingName with the possible settingValues for a specific connection name (find some usages of updatePolicyConnectionConfig).

Comment on lines +96 to +102
[settingName]: settingValue,
pendingFields: {
[settingName]: null,
},
errorFields: {
[settingName]: null,
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

Comment thread src/pages/workspace/accounting/PolicyAccountingPage.tsx Outdated
Co-authored-by: Marc Glasser <marc@expensify.com>
aldo-expensify and others added 3 commits April 17, 2024 11:31
@aldo-expensify

Copy link
Copy Markdown
Contributor

Merged main and resolved conflicts.

@marcaaron
marcaaron self-requested a review April 17, 2024 19:50
@marcaaron
marcaaron merged commit 51bebd5 into main Apr 17, 2024
@marcaaron
marcaaron deleted the hayata-authenticate-with-qbo branch April 17, 2024 19:51
@OSBotify

Copy link
Copy Markdown
Contributor

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

@aldo-expensify

Copy link
Copy Markdown
Contributor

Created another follow up issue for the flashing "Set up" button:

#40377

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/marcaaron in version: 1.4.63-0 🚀

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

@lakchote

Copy link
Copy Markdown
Contributor

@hayata-suenaga @marcaaron @s77rt I think this is ready for another review.

I think we can deal with the WebView crash in another PR to avoid holding this one. The migration to RN 0.74 is on the works here: #37374 and that will most likely solve the issue.

We bumped our head too with Xero on this one... Glad you've posted about it here!

@aldo-expensify

Copy link
Copy Markdown
Contributor

@lakchote there are two issues that may impact your work:

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 1.4.63-21 🚀

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants