diff --git a/src/components/ConnectToQuickbooksOnlineButton/index.native.tsx b/src/components/ConnectToQuickbooksOnlineButton/index.native.tsx index 7e1d81cc4071..1776a0401403 100644 --- a/src/components/ConnectToQuickbooksOnlineButton/index.native.tsx +++ b/src/components/ConnectToQuickbooksOnlineButton/index.native.tsx @@ -12,7 +12,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import {removePolicyConnection} from '@libs/actions/connections'; -import {getQuickBooksOnlineSetupLink} from '@libs/actions/connections/QuickBooksOnline'; +import getQuickBooksOnlineSetupLink from '@libs/actions/connections/QuickBooksOnline'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Session} from '@src/types/onyx'; diff --git a/src/components/ConnectToQuickbooksOnlineButton/index.tsx b/src/components/ConnectToQuickbooksOnlineButton/index.tsx index 37fea2b957a2..2231f040bc27 100644 --- a/src/components/ConnectToQuickbooksOnlineButton/index.tsx +++ b/src/components/ConnectToQuickbooksOnlineButton/index.tsx @@ -6,7 +6,7 @@ import useLocalize from '@hooks/useLocalize'; import useNetwork from '@hooks/useNetwork'; import useThemeStyles from '@hooks/useThemeStyles'; import {removePolicyConnection} from '@libs/actions/connections'; -import {getQuickBooksOnlineSetupLink} from '@libs/actions/connections/QuickBooksOnline'; +import getQuickBooksOnlineSetupLink from '@libs/actions/connections/QuickBooksOnline'; import * as Link from '@userActions/Link'; import CONST from '@src/CONST'; import type {ConnectToQuickbooksOnlineButtonProps} from './types'; diff --git a/src/libs/API/parameters/SyncPolicyToXeroParams.ts b/src/libs/API/parameters/SyncPolicyToXeroParams.ts new file mode 100644 index 000000000000..0932f860c29e --- /dev/null +++ b/src/libs/API/parameters/SyncPolicyToXeroParams.ts @@ -0,0 +1,6 @@ +type SyncPolicyToXeroParams = { + policyID: string; + idempotencyKey: string; +}; + +export default SyncPolicyToXeroParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 52f130a28dd1..c9e2e342c5ae 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -13,6 +13,7 @@ export type {default as CloseAccountParams} from './CloseAccountParams'; export type {default as ConnectBankAccountParams} from './ConnectBankAccountParams'; export type {default as ConnectPolicyToAccountingIntegrationParams} from './ConnectPolicyToAccountingIntegrationParams'; export type {default as SyncPolicyToQuickbooksOnlineParams} from './SyncPolicyToQuickbooksOnlineParams'; +export type {default as SyncPolicyToXeroParams} from './SyncPolicyToXeroParams'; export type {default as DeleteContactMethodParams} from './DeleteContactMethodParams'; export type {default as DeletePaymentBankAccountParams} from './DeletePaymentBankAccountParams'; export type {default as DeletePaymentCardParams} from './DeletePaymentCardParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 08bc5eddd087..40deec85bc47 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -442,6 +442,7 @@ const READ_COMMANDS = { CONNECT_POLICY_TO_QUICKBOOKS_ONLINE: 'ConnectPolicyToQuickbooksOnline', CONNECT_POLICY_TO_XERO: 'ConnectPolicyToXero', SYNC_POLICY_TO_QUICKBOOKS_ONLINE: 'SyncPolicyToQuickbooksOnline', + SYNC_POLICY_TO_XERO: 'SyncPolicyToXero', OPEN_REIMBURSEMENT_ACCOUNT_PAGE: 'OpenReimbursementAccountPage', OPEN_WORKSPACE_VIEW: 'OpenWorkspaceView', GET_MAPBOX_ACCESS_TOKEN: 'GetMapboxAccessToken', @@ -488,6 +489,7 @@ type ReadCommandParameters = { [READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE]: Parameters.ConnectPolicyToAccountingIntegrationParams; [READ_COMMANDS.CONNECT_POLICY_TO_XERO]: Parameters.ConnectPolicyToAccountingIntegrationParams; [READ_COMMANDS.SYNC_POLICY_TO_QUICKBOOKS_ONLINE]: Parameters.SyncPolicyToQuickbooksOnlineParams; + [READ_COMMANDS.SYNC_POLICY_TO_XERO]: Parameters.SyncPolicyToXeroParams; [READ_COMMANDS.OPEN_REIMBURSEMENT_ACCOUNT_PAGE]: Parameters.OpenReimbursementAccountPageParams; [READ_COMMANDS.OPEN_WORKSPACE_VIEW]: Parameters.OpenWorkspaceViewParams; [READ_COMMANDS.GET_MAPBOX_ACCESS_TOKEN]: EmptyObject; diff --git a/src/libs/actions/connections/QuickBooksOnline.ts b/src/libs/actions/connections/QuickBooksOnline.ts index f507758e8d38..2642ad4056a9 100644 --- a/src/libs/actions/connections/QuickBooksOnline.ts +++ b/src/libs/actions/connections/QuickBooksOnline.ts @@ -1,41 +1,14 @@ -import type {OnyxUpdate} from 'react-native-onyx'; -import Onyx from 'react-native-onyx'; -import * as API from '@libs/API'; -import type {ConnectPolicyToAccountingIntegrationParams, SyncPolicyToQuickbooksOnlineParams} from '@libs/API/parameters'; +import type {ConnectPolicyToAccountingIntegrationParams} from '@libs/API/parameters'; import {READ_COMMANDS} from '@libs/API/types'; import {getCommandURL} from '@libs/ApiUtils'; -import CONST from '@src/CONST'; -import ONYXKEYS from '@src/ONYXKEYS'; function getQuickBooksOnlineSetupLink(policyID: string) { const params: ConnectPolicyToAccountingIntegrationParams = {policyID}; - const commandURL = getCommandURL({command: READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE, shouldSkipWebProxy: true}); + const commandURL = getCommandURL({ + command: READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE, + shouldSkipWebProxy: true, + }); return commandURL + new URLSearchParams(params).toString(); } -function syncConnection(policyID: string) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID}`, - value: { - stageInProgress: CONST.POLICY.CONNECTIONS.SYNC_STAGE_NAME.STARTING_IMPORT, - connectionName: CONST.POLICY.CONNECTIONS.NAME.QBO, - }, - }, - ]; - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID}`, - value: null, - }, - ]; - const parameters: SyncPolicyToQuickbooksOnlineParams = { - policyID, - idempotencyKey: policyID, - }; - API.read(READ_COMMANDS.SYNC_POLICY_TO_QUICKBOOKS_ONLINE, parameters, {optimisticData, failureData}); -} - -export {getQuickBooksOnlineSetupLink, syncConnection}; +export default getQuickBooksOnlineSetupLink; diff --git a/src/libs/actions/connections/index.ts b/src/libs/actions/connections/index.ts index 4a501910548b..8fd406f13231 100644 --- a/src/libs/actions/connections/index.ts +++ b/src/libs/actions/connections/index.ts @@ -1,8 +1,14 @@ -import Onyx from 'react-native-onyx'; import type {OnyxUpdate} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; -import type {RemovePolicyConnectionParams, UpdateManyPolicyConnectionConfigurationsParams, UpdatePolicyConnectionConfigParams} from '@libs/API/parameters'; -import {WRITE_COMMANDS} from '@libs/API/types'; +import type { + RemovePolicyConnectionParams, + SyncPolicyToQuickbooksOnlineParams, + SyncPolicyToXeroParams, + UpdateManyPolicyConnectionConfigurationsParams, + UpdatePolicyConnectionConfigParams, +} from '@libs/API/parameters'; +import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import * as ErrorUtils from '@libs/ErrorUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -115,6 +121,48 @@ function updatePolicyConnectionConfig>( policyID: string, connectionName: TConnectionName, @@ -183,4 +231,4 @@ function updateManyPolicyConnectionConfigs syncConnection(policyID), + onSelected: () => syncConnection(policyID, connectedIntegration), disabled: isOffline, }, { @@ -138,7 +137,7 @@ function PolicyAccountingPage({policy, connectionSyncProgress, isConnectionDataF onSelected: () => setIsDisconnectModalOpen(true), }, ], - [translate, policyID, isOffline], + [translate, policyID, isOffline, connectedIntegration], ); const connectionsMenuItems: MenuItemProps[] = useMemo(() => {