Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Fix NSQS sync trigger #56428

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -997,6 +997,10 @@ function getIntegrationLastSuccessfulDate(connection?: Connections[keyof Connect
return syncSuccessfulDate;
}

function getNSQSCompanyID(policy: Policy | undefined) {
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 @@ -1358,6 +1362,7 @@ export {
getNetSuiteReceivableAccountOptions,
getNetSuiteInvoiceItemOptions,
getNetSuiteTaxAccountOptions,
getNSQSCompanyID,
getSageIntacctVendors,
getSageIntacctNonReimbursableActiveDefaultVendor,
getSageIntacctCreditCards,
Expand Down
18 changes: 13 additions & 5 deletions src/libs/actions/connections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
import Onyx from 'react-native-onyx';
import * as API from '@libs/API';
import type {
RemovePolicyConnectionParams,
RemovePolicyConnectionParams, SyncPolicyToNSQSParams,

Check failure on line 7 in src/libs/actions/connections/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `⏎···`

Check failure on line 7 in src/libs/actions/connections/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `⏎···`
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';

Check failure on line 14 in src/libs/actions/connections/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `·from·'@libs/PolicyUtils';⏎import·{getNSQSCompanyID}`

Check failure on line 14 in src/libs/actions/connections/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `·from·'@libs/PolicyUtils';⏎import·{getNSQSCompanyID}`
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {ConnectionName, Connections, PolicyConnectionName, PolicyConnectionSyncProgress} from '@src/types/onyx/Policy';
import type Policy from '@src/types/onyx/Policy';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

Check failure on line 20 in src/libs/actions/connections/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Delete `;⏎import·{getNSQSCompanyID}·from·"@libs/PolicyUtils"`

Check failure on line 20 in src/libs/actions/connections/index.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Delete `;⏎import·{getNSQSCompanyID}·from·"@libs/PolicyUtils"`
import {getNSQSCompanyID} from "@libs/PolicyUtils";

type ConnectionNameExceptNetSuite = Exclude<ConnectionName, typeof CONST.POLICY.CONNECTIONS.NAME.NETSUITE>;

Expand Down Expand Up @@ -222,14 +223,15 @@
/**
* 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 +257,20 @@
},
];

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

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

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 @@ -38,7 +38,7 @@
getConnectedIntegration,
getCurrentSageIntacctEntityName,
getCurrentXeroOrganizationName,
getIntegrationLastSuccessfulDate,
getIntegrationLastSuccessfulDate, getNSQSCompanyID,

Check failure on line 41 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Insert `⏎···`

Check failure on line 41 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

'getNSQSCompanyID' is defined but never used

Check failure on line 41 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

Insert `⏎···`

Check failure on line 41 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

'getNSQSCompanyID' is defined but never used
getXeroTenants,
hasUnsupportedIntegration,
isControlPolicy,
Expand Down Expand Up @@ -102,7 +102,7 @@

const shouldShowEnterCredentials = connectedIntegration && !!synchronizationError && isAuthenticationError(policy, connectedIntegration);

const policyID = policy?.id ?? '-1';

Check failure on line 105 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

// Get the last successful date of the integration. Then, if `connectionSyncProgress` is the same integration displayed and the state is 'jobDone', get the more recent update time of the two.
const successfulDate = getIntegrationLastSuccessfulDate(
connectedIntegration ? policy?.connections?.[connectedIntegration] : undefined,
Expand Down Expand Up @@ -147,7 +147,7 @@
{
icon: Expensicons.Sync,
text: translate('workspace.accounting.syncNow'),
onSelected: () => syncConnection(policyID, connectedIntegration),
onSelected: () => syncConnection(policy, connectedIntegration),
disabled: isOffline,
},
]),
Expand All @@ -158,7 +158,7 @@
shouldCallAfterModalHide: true,
},
],
[shouldShowEnterCredentials, shouldShowReinstallConnectorMenuItem, translate, isOffline, policyID, connectedIntegration, startIntegrationFlow],

Check warning on line 161 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

React Hook useMemo has a missing dependency: 'policy'. Either include it or remove the dependency array

Check warning on line 161 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint check

React Hook useMemo has a missing dependency: 'policy'. Either include it or remove the dependency array
);

useFocusEffect(
Expand Down Expand Up @@ -209,7 +209,7 @@
if (!(tenants.length > 1)) {
return;
}
Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_ORGANIZATION.getRoute(policyID, currentXeroOrganization?.id ?? '-1'));

Check failure on line 212 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

},
pendingAction: settingsPendingAction([CONST.XERO_CONFIG.TENANT_ID], policy?.connections?.xero?.config?.pendingFields),
brickRoadIndicator: areSettingsInErrorFields([CONST.XERO_CONFIG.TENANT_ID], policy?.connections?.xero?.config?.errorFields)
Expand Down Expand Up @@ -633,7 +633,7 @@
/>
<View style={[!isLargeScreenWidth ? styles.flexColumn : styles.flexRow]}>
<Text style={styles.textSupporting}>{translate('workspace.accounting.needAnotherAccounting')}</Text>
<TextLink onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(chatReportID ?? ''))}>{chatTextLink}</TextLink>

Check failure on line 636 in src/pages/workspace/accounting/PolicyAccountingPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

</View>
</View>
)}
Expand Down
Loading