Skip to content

Commit

Permalink
Merge pull request #56428 from Expensify/yuwen-nsqs
Browse files Browse the repository at this point in the history
[No QA] Fix NSQS sync trigger
  • Loading branch information
MonilBhavsar authored Feb 12, 2025
2 parents e97ee83 + 5ece578 commit ead436a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/libs/API/parameters/SyncPolicyToNSQSParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
type SyncPolicyToNSQSParams = {
policyID: string;
netSuiteAccountID: string;
idempotencyKey: string;
};

Expand Down
5 changes: 5 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,10 @@ function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connect
return syncSuccessfulDate;
}

function getNSQSCompanyID(policy: Policy) {
return policy.connections?.netsuiteQuickStart?.config?.credentials?.companyID;
}

function getCurrentSageIntacctEntityName(policy: Policy | undefined, defaultNameIfNoEntity: string): string | undefined {
const currentEntityID = policy?.connections?.intacct?.config?.entity;
if (!currentEntityID) {
Expand Down Expand Up @@ -1407,6 +1411,7 @@ export {
getNetSuiteReceivableAccountOptions,
getNetSuiteInvoiceItemOptions,
getNetSuiteTaxAccountOptions,
getNSQSCompanyID,
getSageIntacctVendors,
getSageIntacctNonReimbursableActiveDefaultVendor,
getSageIntacctCreditCards,
Expand Down
14 changes: 10 additions & 4 deletions src/libs/actions/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import type {
RemovePolicyConnectionParams,
SyncPolicyToNSQSParams,
SyncPolicyToQuickbooksDesktopParams,
UpdateManyPolicyConnectionConfigurationsParams,
UpdatePolicyConnectionConfigParams,
} from '@libs/API/parameters';
import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {getNSQSCompanyID} from '@libs/PolicyUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
Expand Down Expand Up @@ -222,14 +224,15 @@ function getSyncConnectionParameters(connectionName: PolicyConnectionName) {
/**
* This method helps in syncing policy to the connected accounting integration.
*
* @param policyID - ID of the policy for which the sync is needed
* @param policy - Policy for which the sync is needed
* @param connectionName - Name of the connection, QBO/Xero
* @param forceDataRefresh - If true, it will trigger a full data refresh
*/
function syncConnection(policyID: string, connectionName: PolicyConnectionName | undefined, forceDataRefresh = false) {
if (!connectionName) {
function syncConnection(policy: Policy | undefined, connectionName: PolicyConnectionName | undefined, forceDataRefresh = false) {
if (!connectionName || !policy) {
return;
}
const policyID = policy.id;
const syncConnectionData = getSyncConnectionParameters(connectionName);

if (!syncConnectionData) {
Expand All @@ -255,14 +258,17 @@ function syncConnection(policyID: string, connectionName: PolicyConnectionName |
},
];

const parameters: SyncPolicyToQuickbooksDesktopParams = {
const parameters: SyncPolicyToQuickbooksDesktopParams | SyncPolicyToNSQSParams = {
policyID,
idempotencyKey: policyID,
};

if (connectionName === CONST.POLICY.CONNECTIONS.NAME.QBD) {
parameters.forceDataRefresh = forceDataRefresh;
}
if (connectionName === CONST.POLICY.CONNECTIONS.NAME.NSQS) {
(parameters as SyncPolicyToNSQSParams).netSuiteAccountID = getNSQSCompanyID(policy) ?? '';
}

API.read(syncConnectionData.readCommand, parameters, {
optimisticData,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
{
icon: Expensicons.Sync,
text: translate('workspace.accounting.syncNow'),
onSelected: () => syncConnection(policyID, connectedIntegration),
onSelected: () => syncConnection(policy, connectedIntegration),
disabled: isOffline,
},
]),
Expand All @@ -158,7 +158,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
shouldCallAfterModalHide: true,
},
],
[shouldShowEnterCredentials, shouldShowReinstallConnectorMenuItem, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow],
[shouldShowEnterCredentials, shouldShowReinstallConnectorMenuItem, translate, isOffline, policy, connectedIntegration, startIntegrationFlow],
);

useFocusEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function QuickBooksDesktopSetupFlowSyncPage({route}: QuickBooksDesktopSetupFlowS

const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy);
if (!isSyncInProgress) {
syncConnection(policyID, CONST.POLICY.CONNECTIONS.NAME.QBD, true);
syncConnection(policy, CONST.POLICY.CONNECTIONS.NAME.QBD, true);
}

Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING.getRoute(policyID));
Expand Down

0 comments on commit ead436a

Please sign in to comment.