Skip to content

Commit

Permalink
Merge pull request #39219 from Expensify/hayata-authenticate-with-qbo
Browse files Browse the repository at this point in the history
Authenticate with QBO
  • Loading branch information
marcaaron authored Apr 17, 2024
2 parents 97632e6 + bdf2d18 commit 51bebd5
Show file tree
Hide file tree
Showing 39 changed files with 480 additions and 381 deletions.
3 changes: 2 additions & 1 deletion src/CONFIG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
EXPENSIFY: {
// Note: This will be EXACTLY what is set for EXPENSIFY_URL whether the proxy is enabled or not.
EXPENSIFY_URL: expensifyURL,
SECURE_EXPENSIFY_URL: secureExpensifyUrl,
NEW_EXPENSIFY_URL: newExpensifyURL,

// The DEFAULT API is the API used by most environments, except staging, where we use STAGING (defined below)
Expand All @@ -72,7 +73,7 @@ export default {
IS_USING_LOCAL_WEB: useNgrok || expensifyURLRoot.includes('dev'),
PUSHER: {
APP_KEY: get(Config, 'PUSHER_APP_KEY', '268df511a204fbb60884'),
SUFFIX: get(Config, 'PUSHER_DEV_SUFFIX', ''),
SUFFIX: ENVIRONMENT === CONST.ENVIRONMENT.DEV ? get(Config, 'PUSHER_DEV_SUFFIX', '') : '',
CLUSTER: 'mt1',
},
SITE_TITLE: 'New Expensify',
Expand Down
28 changes: 13 additions & 15 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1215,9 +1215,9 @@ const CONST = {
NOT_IMPORTED: 'NOT_IMPORTED',
IMPORTED: 'IMPORTED',
},
QUICK_BOOKS_ONLINE: 'quickbooksOnline',
QUICKBOOKS_ONLINE: 'quickbooksOnline',

QUICK_BOOKS_IMPORTS: {
QUICKBOOKS_IMPORTS: {
SYNC_CLASSES: 'syncClasses',
ENABLE_NEW_CATEGORIES: 'enableNewCategories',
SYNC_CUSTOMERS: 'syncCustomers',
Expand Down Expand Up @@ -1614,25 +1614,23 @@ const CONST = {
GENERAL_SETTINGS: 'generalSettings',
},
CONNECTIONS: {
SYNC_STATUS: {
STARTING: 'starting',
FINISHED: 'finished',
PROGRESS: 'progress',
},
NAME: {
// Here we will add other connections names when we add support for them
QBO: 'quickbooksOnline',
},
SYNC_STAGE_NAME: {
STARTING_IMPORT: 'startingImport',
QBO_CUSTOMERS: 'quickbooksOnlineImportCustomers',
QBO_EMPLOYEES: 'quickbooksOnlineImportEmployees',
QBO_ACCOUNTS: 'quickbooksOnlineImportAccounts',
QBO_CLASSES: 'quickbooksOnlineImportClasses',
QBO_LOCATIONS: 'quickbooksOnlineImportLocations',
QBO_PROCESSING: 'quickbooksOnlineImportProcessing',
QBO_PAYMENTS: 'quickbooksOnlineSyncBillPayments',
QBO_TAX_CODES: 'quickbooksOnlineSyncTaxCodes',
QBO_IMPORT_MAIN: 'quickbooksOnlineImportMain',
QBO_IMPORT_CUSTOMERS: 'quickbooksOnlineImportCustomers',
QBO_IMPORT_EMPLOYEES: 'quickbooksOnlineImportEmployees',
QBO_IMPORT_ACCOUNTS: 'quickbooksOnlineImportAccounts',
QBO_IMPORT_CLASSES: 'quickbooksOnlineImportClasses',
QBO_IMPORT_LOCATIONS: 'quickbooksOnlineImportLocations',
QBO_IMPORT_PROCESSING: 'quickbooksOnlineImportProcessing',
QBO_SYNC_PAYMENTS: 'quickbooksOnlineSyncBillPayments',
QBO_IMPORT_TAX_CODES: 'quickbooksOnlineSyncTaxCodes',
QBO_CHECK_CONNECTION: 'quickbooksOnlineCheckConnection',
JOB_DONE: 'jobDone',
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ const ONYXKEYS = {
// object should mirror the data as it's stored in the database.
POLICY_HAS_CONNECTIONS_DATA_BEEN_FETCHED: 'policyHasConnectionsDataBeenFetched_',
OLD_POLICY_RECENTLY_USED_TAGS: 'policyRecentlyUsedTags_',
POLICY_CONNECTION_SYNC_PROGRESS: 'policyConnectionSyncProgress_',
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_',
REPORT: 'report_',
Expand Down Expand Up @@ -355,8 +356,6 @@ const ONYXKEYS = {

/** This is deprecated, but needed for a migration, so we still need to include it here so that it will be initialized in Onyx.init */
DEPRECATED_POLICY_MEMBER_LIST: 'policyMemberList_',

POLICY_CONNECTION_SYNC_PROGRESS: 'policyConnectionSyncProgress_',
},

/** List of Form ids */
Expand Down
14 changes: 7 additions & 7 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ const ROUTES = {
route: 'settings/workspaces/:policyID/members',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/members` as const,
},
WORKSPACE_ACCOUNTING: {
POLICY_ACCOUNTING: {
route: 'settings/workspaces/:policyID/accounting',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting` as const,
},
Expand Down Expand Up @@ -707,27 +707,27 @@ const ROUTES = {
route: 'r/:reportID/transaction/:transactionID/receipt',
getRoute: (reportID: string, transactionID: string) => `r/${reportID}/transaction/${transactionID}/receipt` as const,
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_IMPORT: {
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_IMPORT: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/import',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/import` as const,
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_CHART_OF_ACCOUNTS: {
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_CHART_OF_ACCOUNTS: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/import/accounts',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/import/accounts` as const,
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_CLASSES: {
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_CLASSES: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/import/classes',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/import/classes` as const,
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_CUSTOMERS: {
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_CUSTOMERS: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/import/customers',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/import/customers` as const,
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_LOCATIONS: {
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_LOCATIONS: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/import/locations',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/import/locations` as const,
},
WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_TAXES: {
POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_TAXES: {
route: 'settings/workspaces/:policyID/accounting/quickbooks-online/import/taxes',
getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/quickbooks-online/import/taxes` as const,
},
Expand Down
16 changes: 9 additions & 7 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ const SCREENS = {
},

WORKSPACE: {
ACCOUNTING: {
ROOT: 'Policy_Accounting',
QUICKBOOKS_ONLINE_IMPORT: 'Policy_Accounting_Quickbooks_Online_Import',
QUICKBOOKS_ONLINE_CHART_OF_ACCOUNTS: 'Policy_Accounting_Quickbooks_Online_Import_Chart_Of_Accounts',
QUICKBOOKS_ONLINE_CLASSES: 'Policy_Accounting_Quickbooks_Online_Import_Classes',
QUICKBOOKS_ONLINE_CUSTOMERS: 'Policy_Accounting_Quickbooks_Online_Import_Customers',
QUICKBOOKS_ONLINE_LOCATIONS: 'Policy_Accounting_Quickbooks_Online_Import_Locations',
QUICKBOOKS_ONLINE_TAXES: 'Policy_Accounting_Quickbooks_Online_Import_Taxes',
},
INITIAL: 'Workspace_Initial',
PROFILE: 'Workspace_Profile',
CARD: 'Workspace_Card',
Expand All @@ -214,7 +223,6 @@ const SCREENS = {
INVOICES: 'Workspace_Invoices',
TRAVEL: 'Workspace_Travel',
MEMBERS: 'Workspace_Members',
ACCOUNTING: 'Workspace_Accounting',
INVITE: 'Workspace_Invite',
INVITE_MESSAGE: 'Workspace_Invite_Message',
CATEGORIES: 'Workspace_Categories',
Expand Down Expand Up @@ -254,12 +262,6 @@ const SCREENS = {
DISTANCE_RATES: 'Distance_Rates',
CREATE_DISTANCE_RATE: 'Create_Distance_Rate',
DISTANCE_RATES_SETTINGS: 'Distance_Rates_Settings',
QUICKBOOKS_ONLINE_IMPORT: 'Workspace_Accounting_Quickbooks_Online_Import',
QUICKBOOKS_ONLINE_CHART_OF_ACCOUNTS: 'Workspace_Accounting_Quickbooks_Online_Import_Chart_Of_Accounts',
QUICKBOOKS_ONLINE_CLASSES: 'Workspace_Accounting_Quickbooks_Online_Import_Classes',
QUICKBOOKS_ONLINE_CUSTOMERS: 'Workspace_Accounting_Quickbooks_Online_Import_Customers',
QUICKBOOKS_ONLINE_LOCATIONS: 'Workspace_Accounting_Quickbooks_Online_Import_Locations',
QUICKBOOKS_ONLINE_TAXES: 'Workspace_Accounting_Quickbooks_Online_Import_Taxes',
DISTANCE_RATE_DETAILS: 'Distance_Rate_Details',
DISTANCE_RATE_EDIT: 'Distance_Rate_Edit',
},
Expand Down
68 changes: 68 additions & 0 deletions src/components/ConnectToQuickbooksOnlineButton/index.native.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, {useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import {WebView} from 'react-native-webview';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import Button from '@components/Button';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import Modal from '@components/Modal';
import useLocalize from '@hooks/useLocalize';
import {getQuickBooksOnlineSetupLink} from '@libs/actions/connections/QuickBooksOnline';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Session} from '@src/types/onyx';
import type {ConnectToQuickbooksOnlineButtonProps} from './types';

type ConnectToQuickbooksOnlineButtonOnyxProps = {
/** Session info for the currently logged in user. */
session: OnyxEntry<Session>;
};

const renderLoading = () => <FullScreenLoadingIndicator />;

function ConnectToQuickbooksOnlineButton({policyID, session}: ConnectToQuickbooksOnlineButtonProps & ConnectToQuickbooksOnlineButtonOnyxProps) {
const [isModalOpen, setIsModalOpen] = useState(false);
const {translate} = useLocalize();

return (
<>
<Button
onPress={() => setIsModalOpen(true)}
text={translate('workspace.accounting.setup')}
/>
<Modal
fullscreen
onClose={() => setIsModalOpen(false)}
isVisible={isModalOpen}
type={CONST.MODAL.MODAL_TYPE.CENTERED}
>
<HeaderWithBackButton
title={translate('workspace.accounting.title')}
onBackButtonPress={() => setIsModalOpen(false)}
/>
<FullPageOfflineBlockingView>
<WebView
source={{
uri: getQuickBooksOnlineSetupLink(policyID),
headers: {
Cookie: `authToken=${session?.authToken}`,
},
}}
incognito // 'incognito' prop required for Android, issue here https://github.com/react-native-webview/react-native-webview/issues/1352
startInLoadingState
renderLoading={renderLoading}
/>
</FullPageOfflineBlockingView>
</Modal>
</>
);
}

ConnectToQuickbooksOnlineButton.displayName = 'ConnectToQuickbooksOnlineButton';

export default withOnyx<ConnectToQuickbooksOnlineButtonProps & ConnectToQuickbooksOnlineButtonOnyxProps, ConnectToQuickbooksOnlineButtonOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
})(ConnectToQuickbooksOnlineButton);
25 changes: 25 additions & 0 deletions src/components/ConnectToQuickbooksOnlineButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import Button from '@components/Button';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {getQuickBooksOnlineSetupLink} from '@libs/actions/connections/QuickBooksOnline';
import * as Link from '@userActions/Link';
import type {ConnectToQuickbooksOnlineButtonProps} from './types';

function ConnectToQuickbooksOnlineButton({policyID}: ConnectToQuickbooksOnlineButtonProps) {
const {translate} = useLocalize();
const {environmentURL} = useEnvironment();
const styles = useThemeStyles();
return (
<Button
onPress={() => Link.openLink(getQuickBooksOnlineSetupLink(policyID), environmentURL, false)}
text={translate('workspace.accounting.setup')}
style={styles.justifyContentCenter}
/>
);
}

ConnectToQuickbooksOnlineButton.displayName = 'ConnectToQuickbooksOnlineButton';

export default ConnectToQuickbooksOnlineButton;
6 changes: 6 additions & 0 deletions src/components/ConnectToQuickbooksOnlineButton/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type ConnectToQuickbooksOnlineButtonProps = {
policyID: string;
};

// eslint-disable-next-line import/prefer-default-export
export type {ConnectToQuickbooksOnlineButtonProps};
13 changes: 12 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,18 @@ export default {
return 'Importing accounts';
case 'quickbooksOnlineImportClasses':
return 'Importing classes';

case 'quickbooksOnlineImportLocations':
return 'Importing locations';
case 'quickbooksOnlineImportProcessing':
return 'Processing imported data';
case 'quickbooksOnlineSyncBillPayments':
return 'Synchronizing reimbursed reports and bill Payments';
case 'quickbooksOnlineSyncTaxCodes':
return 'Importing tax codes';
case 'quickbooksOnlineCheckConnection':
return 'Checking QuickBooks Online connection';
case 'quickbooksOnlineImportMain':
return 'Importing your QuickBooks Online data';
default: {
return `Translation missing for stage: ${stage}`;
}
Expand Down
19 changes: 15 additions & 4 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2082,12 +2082,23 @@ export default {
case 'quickbooksOnlineImportCustomers':
return 'Importando clientes';
case 'quickbooksOnlineImportEmployees':
return 'Importing employees';
return 'Importando empleados';
case 'quickbooksOnlineImportAccounts':
return 'Importing accounts';
return 'Importando cuentas';
case 'quickbooksOnlineImportClasses':
return 'Importing classes';

return 'Importando clases';
case 'quickbooksOnlineImportLocations':
return 'Importando localidades';
case 'quickbooksOnlineImportProcessing':
return 'Procesando datos importados';
case 'quickbooksOnlineSyncBillPayments':
return 'Sincronizando reportes reembolsados y facturas pagadas';
case 'quickbooksOnlineSyncTaxCodes':
return 'Importando tipos de impuestos';
case 'quickbooksOnlineCheckConnection':
return 'Revisando conexión a QuickBooks Online';
case 'quickbooksOnlineImportMain':
return 'Importando datos desde QuickBooks Online';
default: {
return `Translation missing for stage: ${stage}`;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type ConnectPolicyToQuickbooksOnlineParams = {
policyID: string;
};

export default ConnectPolicyToQuickbooksOnlineParams;
8 changes: 8 additions & 0 deletions src/libs/API/parameters/RemovePolicyConnectionParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type {PolicyConnectionName} from '@src/types/onyx/Policy';

type RemovePolicyConnectionParams = {
policyID: string;
connectionName: PolicyConnectionName;
};

export default RemovePolicyConnectionParams;
2 changes: 2 additions & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {default as BeginGoogleSignInParams} from './BeginGoogleSignInParams
export type {default as BeginSignInParams} from './BeginSignInParams';
export type {default as CloseAccountParams} from './CloseAccountParams';
export type {default as ConnectBankAccountParams} from './ConnectBankAccountParams';
export type {default as ConnectPolicyToQuickbooksOnlineParams} from './ConnectPolicyToQuickbooksOnlineParams';
export type {default as DeleteContactMethodParams} from './DeleteContactMethodParams';
export type {default as DeletePaymentBankAccountParams} from './DeletePaymentBankAccountParams';
export type {default as DeletePaymentCardParams} from './DeletePaymentCardParams';
Expand Down Expand Up @@ -204,6 +205,7 @@ export type {default as SetPolicyCustomTaxNameParams} from './SetPolicyCustomTax
export type {default as SetPolicyForeignCurrencyDefaultParams} from './SetPolicyForeignCurrencyDefaultParams';
export type {default as SetPolicyCurrencyDefaultParams} from './SetPolicyCurrencyDefaultParams';
export type {default as UpdatePolicyConnectionConfigParams} from './UpdatePolicyConnectionConfigParams';
export type {default as RemovePolicyConnectionParams} from './RemovePolicyConnectionParams';
export type {default as RenamePolicyTaxParams} from './RenamePolicyTaxParams';
export type {default as DismissTrackExpenseActionableWhisperParams} from './DismissTrackExpenseActionableWhisperParams';
export type {default as ConvertTrackedExpenseToRequestParams} from './ConvertTrackedExpenseToRequestParams';
Expand Down
5 changes: 5 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const WRITE_COMMANDS = {
DECLINE_JOIN_REQUEST: 'DeclineJoinRequest',
CREATE_POLICY_TAX: 'CreatePolicyTax',
UPDATE_POLICY_CONNECTION_CONFIG: 'UpdatePolicyConnectionConfig',
REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection',
SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled',
DELETE_POLICY_TAXES: 'DeletePolicyTaxes',
UPDATE_POLICY_TAX_VALUE: 'UpdatePolicyTaxValue',
Expand Down Expand Up @@ -409,8 +410,10 @@ type WriteCommandParameters = {
[WRITE_COMMANDS.RENAME_POLICY_TAX]: Parameters.RenamePolicyTaxParams;
[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
[WRITE_COMMANDS.UPDATE_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams<any, any>;
[WRITE_COMMANDS.REMOVE_POLICY_CONNECTION]: Parameters.RemovePolicyConnectionParams;
[WRITE_COMMANDS.UPDATE_POLICY_DISTANCE_RATE_VALUE]: Parameters.UpdatePolicyDistanceRateValueParams;
[WRITE_COMMANDS.SET_POLICY_DISTANCE_RATES_ENABLED]: Parameters.SetPolicyDistanceRatesEnabledParams;
[WRITE_COMMANDS.DELETE_POLICY_DISTANCE_RATES]: Parameters.DeletePolicyDistanceRatesParams;
Expand All @@ -422,6 +425,7 @@ type WriteCommandParameters = {
};

const READ_COMMANDS = {
CONNECT_POLICY_TO_QUICKBOOKS_ONLINE: 'ConnectPolicyToQuickbooksOnline',
OPEN_REIMBURSEMENT_ACCOUNT_PAGE: 'OpenReimbursementAccountPage',
OPEN_WORKSPACE_VIEW: 'OpenWorkspaceView',
GET_MAPBOX_ACCESS_TOKEN: 'GetMapboxAccessToken',
Expand Down Expand Up @@ -463,6 +467,7 @@ const READ_COMMANDS = {
type ReadCommand = ValueOf<typeof READ_COMMANDS>;

type ReadCommandParameters = {
[READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE]: Parameters.ConnectPolicyToQuickbooksOnlineParams;
[READ_COMMANDS.OPEN_REIMBURSEMENT_ACCOUNT_PAGE]: Parameters.OpenReimbursementAccountPageParams;
[READ_COMMANDS.OPEN_WORKSPACE_VIEW]: Parameters.OpenWorkspaceViewParams;
[READ_COMMANDS.GET_MAPBOX_ACCESS_TOKEN]: EmptyObject;
Expand Down
Loading

0 comments on commit 51bebd5

Please sign in to comment.