-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41044 from Expensify/aldo_sync-command
Add QBO Sync functionality
- Loading branch information
Showing
7 changed files
with
51 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/libs/API/parameters/SyncPolicyToQuickbooksOnlineParams.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type SyncPolicyToQuickbooksOnlineParams = { | ||
policyID: string; | ||
idempotencyKey: string; | ||
}; | ||
|
||
export default SyncPolicyToQuickbooksOnlineParams; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
import type {ConnectPolicyToQuickbooksOnlineParams} from '@libs/API/parameters'; | ||
import type {OnyxUpdate} from 'react-native-onyx'; | ||
import Onyx from 'react-native-onyx'; | ||
import * as API from '@libs/API'; | ||
import type {ConnectPolicyToQuickbooksOnlineParams, SyncPolicyToQuickbooksOnlineParams} 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: ConnectPolicyToQuickbooksOnlineParams = {policyID}; | ||
const commandURL = getCommandURL({command: READ_COMMANDS.CONNECT_POLICY_TO_QUICKBOOKS_ONLINE, shouldSkipWebProxy: true}); | ||
return commandURL + new URLSearchParams(params).toString(); | ||
} | ||
|
||
// More action functions will be added later | ||
// eslint-disable-next-line import/prefer-default-export | ||
export {getQuickBooksOnlineSetupLink}; | ||
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}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters