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 all commits
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) {
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 @@ -1389,6 +1393,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 @@ -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],
[shouldShowEnterCredentials, shouldShowReinstallConnectorMenuItem, translate, isOffline, policy, connectedIntegration, startIntegrationFlow],
);

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
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

function QuickBooksDesktopSetupFlowSyncPage({route}: QuickBooksDesktopSetupFlowSyncPageProps) {
const policyID: string = route.params.policyID;
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID ?? '-1'}`);

Check failure on line 16 in src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupFlowSyncPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policyID ?? '-1'}`);

Check failure on line 17 in src/pages/workspace/accounting/qbd/QuickBooksDesktopSetupFlowSyncPage.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


useEffect(() => {
if (!policyID) {
Expand All @@ -23,7 +23,7 @@

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
Loading