From 1338df1074f4377136b27ca649583731d3026553 Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 29 Aug 2024 20:30:18 +0700 Subject: [PATCH 1/6] Update UpdateQuickbooksOnlineReceivableAccount to 1:1:1 --- src/libs/API/types.ts | 2 + .../actions/connections/QuickbooksOnline.ts | 95 ++++++++++++++++++- ...ickbooksExportInvoiceAccountSelectPage.tsx | 4 +- 3 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 457eeb7c9b03..37815c637389 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -219,6 +219,7 @@ const WRITE_COMMANDS = { UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES: 'UpdateQuickbooksOnlineEnableNewCategories', UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR: 'UpdateQuickbooksOnlineAutoCreateVendor', UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineReimbursableExpensesAccount', + UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT: 'UpdateQuickbooksOnlineReceivableAccount', UPDATE_MANY_POLICY_CONNECTION_CONFIGS: 'UpdateManyPolicyConnectionConfigurations', REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection', SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled', @@ -579,6 +580,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams; [WRITE_COMMANDS.UPDATE_MANY_POLICY_CONNECTION_CONFIGS]: Parameters.UpdateManyPolicyConnectionConfigurationsParams; [WRITE_COMMANDS.REMOVE_POLICY_CONNECTION]: Parameters.RemovePolicyConnectionParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index a3216378add3..c54efc89187a 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -8,7 +8,7 @@ import {getCommandURL} from '@libs/ApiUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {ConnectionName, Connections} from '@src/types/onyx/Policy'; +import type {ConnectionName, Connections, QBOConnectionConfig} from '@src/types/onyx/Policy'; type ConnectionNameExceptNetSuite = Exclude; @@ -21,6 +21,80 @@ function getQuickbooksOnlineSetupLink(policyID: string) { return commandURL + new URLSearchParams(params).toString(); } +function buildQuickbooksOnlineUpdateConfigOnyxData( + policyID: string, + settingName: TSettingName, + settingValue: Partial, +) { + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + [settingName]: settingValue ?? null, + pendingFields: { + [settingName]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + }, + errorFields: { + [settingName]: null, + }, + }, + }, + }, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + [settingName]: settingValue ?? null, + pendingFields: { + [settingName]: null, + }, + errorFields: { + [settingName]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + }, + }, + }, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + [settingName]: settingValue ?? null, + pendingFields: { + [settingName]: null, + }, + errorFields: { + [settingName]: null, + }, + }, + }, + }, + }, + }, + ]; + + return {optimisticData, failureData, successData}; +} + function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValue: boolean) { const optimisticData: OnyxUpdate[] = [ { @@ -249,4 +323,21 @@ function updateQuickbooksOnlineReimbursableExpensesAccount { if (row.value.id !== receivableAccount?.id) { - Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.RECEIVABLE_ACCOUNT, row.value); + QuickbooksOnline.updateQuickbooksOnlineReceivableAccount(policyID, row.value); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_INVOICE_ACCOUNT_SELECT.getRoute(policyID)); }, From c946df979d997252026c049426ee52eedc21104b Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 29 Aug 2024 20:39:09 +0700 Subject: [PATCH 2/6] Update UpdateQuickbooksOnlineExportDate to 1:1:1 --- src/libs/API/types.ts | 2 ++ src/libs/actions/connections/QuickbooksOnline.ts | 12 ++++++++++++ .../qbo/export/QuickbooksExportDateSelectPage.tsx | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 37815c637389..0feb34abf215 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -220,6 +220,7 @@ const WRITE_COMMANDS = { UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR: 'UpdateQuickbooksOnlineAutoCreateVendor', UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineReimbursableExpensesAccount', UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT: 'UpdateQuickbooksOnlineReceivableAccount', + UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE: 'UpdateQuickbooksOnlineExportDate', UPDATE_MANY_POLICY_CONNECTION_CONFIGS: 'UpdateManyPolicyConnectionConfigurations', REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection', SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled', @@ -581,6 +582,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams; [WRITE_COMMANDS.UPDATE_MANY_POLICY_CONNECTION_CONFIGS]: Parameters.UpdateManyPolicyConnectionConfigurationsParams; [WRITE_COMMANDS.REMOVE_POLICY_CONNECTION]: Parameters.RemovePolicyConnectionParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index c54efc89187a..cc0ee98431fb 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -334,10 +334,22 @@ function updateQuickbooksOnlineReceivableAccount(policyID: string, settingValue: API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT, parameters, {optimisticData, failureData, successData}); } +function updateQuickbooksOnlineExportDate(policyID: string, settingValue: QBOConnectionConfig['exportDate']) { + const {optimisticData, failureData, successData} = buildQuickbooksOnlineUpdateConfigOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE, settingValue); + + const parameters: UpdateQuickbooksOnlineGenericTypeParams = { + policyID, + settingValue: JSON.stringify(settingValue), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE), + }; + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE, parameters, {optimisticData, failureData, successData}); +} + export { getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, updateQuickbooksOnlineAutoCreateVendor, updateQuickbooksOnlineReimbursableExpensesAccount, updateQuickbooksOnlineReceivableAccount, + updateQuickbooksOnlineExportDate, }; diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksExportDateSelectPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksExportDateSelectPage.tsx index 89fbd6a96b33..8a8110c121ec 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksExportDateSelectPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksExportDateSelectPage.tsx @@ -8,7 +8,7 @@ import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Connections from '@libs/actions/connections'; +import * as QuickbooksOnline from '@libs/actions/connections/QuickbooksOnline'; import Navigation from '@navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; @@ -35,7 +35,7 @@ function QuickbooksExportDateSelectPage({policy}: WithPolicyConnectionsProps) { const selectExportDate = useCallback( (row: CardListItem) => { if (row.value !== exportDate) { - Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE, row.value); + QuickbooksOnline.updateQuickbooksOnlineExportDate(policyID, row.value); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT_DATE_SELECT.getRoute(policyID)); }, From 7e9d080756df29d3df9d23db739c00e32ee381fb Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 29 Aug 2024 22:25:19 +0700 Subject: [PATCH 3/6] Update UpdateQuickbooksOnlineNonReimbursableExpensesAccount to 1:1:1 --- src/libs/API/types.ts | 2 ++ src/libs/actions/connections/QuickbooksOnline.ts | 12 ++++++++++++ ...QuickbooksCompanyCardExpenseAccountSelectPage.tsx | 4 ++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 0feb34abf215..a7d3350d93a5 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -221,6 +221,7 @@ const WRITE_COMMANDS = { UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineReimbursableExpensesAccount', UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT: 'UpdateQuickbooksOnlineReceivableAccount', UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE: 'UpdateQuickbooksOnlineExportDate', + UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineNonReimbursableExpensesAccount', UPDATE_MANY_POLICY_CONNECTION_CONFIGS: 'UpdateManyPolicyConnectionConfigurations', REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection', SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled', @@ -583,6 +584,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams; [WRITE_COMMANDS.UPDATE_MANY_POLICY_CONNECTION_CONFIGS]: Parameters.UpdateManyPolicyConnectionConfigurationsParams; [WRITE_COMMANDS.REMOVE_POLICY_CONNECTION]: Parameters.RemovePolicyConnectionParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index cc0ee98431fb..8feb6b761818 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -345,6 +345,17 @@ function updateQuickbooksOnlineExportDate(policyID: string, settingValue: QBOCon API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE, parameters, {optimisticData, failureData, successData}); } +function updateQuickbooksOnlineNonReimbursableExpensesAccount(policyID: string, settingValue: QBOConnectionConfig['nonReimbursableExpensesAccount']) { + const {optimisticData, failureData, successData} = buildQuickbooksOnlineUpdateConfigOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT, settingValue); + + const parameters: UpdateQuickbooksOnlineGenericTypeParams = { + policyID, + settingValue: JSON.stringify(settingValue), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT), + }; + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData}); +} + export { getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, @@ -352,4 +363,5 @@ export { updateQuickbooksOnlineReimbursableExpensesAccount, updateQuickbooksOnlineReceivableAccount, updateQuickbooksOnlineExportDate, + updateQuickbooksOnlineNonReimbursableExpensesAccount, }; diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectPage.tsx index 8bee7d206180..46f615b835f3 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksCompanyCardExpenseAccountSelectPage.tsx @@ -9,7 +9,7 @@ import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Connections from '@libs/actions/connections'; +import * as QuickbooksOnline from '@libs/actions/connections/QuickbooksOnline'; import * as ConnectionUtils from '@libs/ConnectionUtils'; import Navigation from '@navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -59,7 +59,7 @@ function QuickbooksCompanyCardExpenseAccountSelectPage({policy}: WithPolicyConne const selectExportAccount = useCallback( (row: CardListItem) => { if (row.value.id !== nonReimbursableExpensesAccount?.id) { - Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT, row.value); + QuickbooksOnline.updateQuickbooksOnlineNonReimbursableExpensesAccount(policyID, row.value); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT.getRoute(policyID)); }, From 7addeb3a4b4742004c958a5e449a009b81a576de Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 29 Aug 2024 22:30:17 +0700 Subject: [PATCH 4/6] Update UpdateQuickbooksOnlineCollectionAccountID to 1:1:1 --- src/libs/API/types.ts | 2 ++ src/libs/actions/connections/QuickbooksOnline.ts | 12 ++++++++++++ .../qbo/advanced/QuickbooksAdvancedPage.tsx | 7 +------ .../advanced/QuickbooksInvoiceAccountSelectPage.tsx | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index a7d3350d93a5..902e300a03d6 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -222,6 +222,7 @@ const WRITE_COMMANDS = { UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT: 'UpdateQuickbooksOnlineReceivableAccount', UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE: 'UpdateQuickbooksOnlineExportDate', UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineNonReimbursableExpensesAccount', + UPDATE_QUICKBOOKS_ONLINE_COLLECTION_ACCOUNT_ID: 'UpdateQuickbooksOnlineCollectionAccountID', UPDATE_MANY_POLICY_CONNECTION_CONFIGS: 'UpdateManyPolicyConnectionConfigurations', REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection', SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled', @@ -585,6 +586,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_COLLECTION_ACCOUNT_ID]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams; [WRITE_COMMANDS.UPDATE_MANY_POLICY_CONNECTION_CONFIGS]: Parameters.UpdateManyPolicyConnectionConfigurationsParams; [WRITE_COMMANDS.REMOVE_POLICY_CONNECTION]: Parameters.RemovePolicyConnectionParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index 8feb6b761818..e6a2d551b037 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -356,6 +356,17 @@ function updateQuickbooksOnlineNonReimbursableExpensesAccount(policyID: string, API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData}); } +function updateQuickbooksOnlineCollectionAccountID(policyID: string, settingValue: QBOConnectionConfig['collectionAccountID']) { + const {optimisticData, failureData, successData} = buildQuickbooksOnlineUpdateConfigOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID, settingValue); + + const parameters: UpdateQuickbooksOnlineGenericTypeParams = { + policyID, + settingValue: JSON.stringify(settingValue), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID), + }; + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_COLLECTION_ACCOUNT_ID, parameters, {optimisticData, failureData, successData}); +} + export { getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, @@ -364,4 +375,5 @@ export { updateQuickbooksOnlineReceivableAccount, updateQuickbooksOnlineExportDate, updateQuickbooksOnlineNonReimbursableExpensesAccount, + updateQuickbooksOnlineCollectionAccountID, }; diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index a0b89e4e5baf..3f824e1e3f83 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -112,12 +112,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.reimbursedReportsDescription'), isActive: isSyncReimbursedSwitchOn, onToggle: () => - Connections.updatePolicyConnectionConfig( - policyID, - CONST.POLICY.CONNECTIONS.NAME.QBO, - CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID, - isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions][0].id, - ), + QuickbooksOnline.updateQuickbooksOnlineCollectionAccountID(policyID, isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions][0].id), pendingAction: pendingFields?.collectionAccountID, errors: ErrorUtils.getLatestErrorField(qboConfig ?? {}, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID), onCloseError: () => Policy.clearQBOErrorField(policyID, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID), diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksInvoiceAccountSelectPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksInvoiceAccountSelectPage.tsx index 69acda4e1ba6..100bda4189df 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksInvoiceAccountSelectPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksInvoiceAccountSelectPage.tsx @@ -10,7 +10,7 @@ import type {ListItem} from '@components/SelectionList/types'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Connections from '@libs/actions/connections'; +import * as QuickbooksOnline from '@libs/actions/connections/QuickbooksOnline'; import Navigation from '@libs/Navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; @@ -56,7 +56,7 @@ function QuickbooksInvoiceAccountSelectPage({policy}: WithPolicyConnectionsProps const updateAccount = useCallback( ({value}: SelectorType) => { - Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID, value); + QuickbooksOnline.updateQuickbooksOnlineCollectionAccountID(policyID, value); Navigation.goBack(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID)); }, [policyID], From db94778e322e50ad7f27627cdb61a4e36ea4488b Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 5 Sep 2024 22:43:25 +0700 Subject: [PATCH 5/6] Pass oldSettingValue --- .../actions/connections/QuickbooksOnline.ts | 30 +++++++++++++------ .../qbo/advanced/QuickbooksAdvancedPage.tsx | 6 +++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index 1fd9145bba51..b030f60059f2 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -9,7 +9,7 @@ import {getCommandURL} from '@libs/ApiUtils'; import * as ErrorUtils from '@libs/ErrorUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; -import type {Connections} from '@src/types/onyx/Policy'; +import type {Connections, QBOConnectionConfig} from '@src/types/onyx/Policy'; function getQuickbooksOnlineSetupLink(policyID: string) { const params: ConnectPolicyToAccountingIntegrationParams = {policyID}; @@ -266,8 +266,12 @@ function updateQuickbooksOnlineNonReimbursableBillDefaultVendor( + policyID: string, + settingValue: TSettingValue, + oldSettingValue?: TSettingValue, +) { + const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.RECEIVABLE_ACCOUNT, settingValue, oldSettingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, @@ -277,8 +281,8 @@ function updateQuickbooksOnlineReceivableAccount(policyID: string, settingValue: API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_RECEIVABLE_ACCOUNT, parameters, {optimisticData, failureData, successData}); } -function updateQuickbooksOnlineExportDate(policyID: string, settingValue: QBOConnectionConfig['exportDate']) { - const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE, settingValue); +function updateQuickbooksOnlineExportDate(policyID: string, settingValue: TSettingValue, oldSettingValue?: TSettingValue) { + const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE, settingValue, oldSettingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, @@ -288,8 +292,12 @@ function updateQuickbooksOnlineExportDate(policyID: string, settingValue: QBOCon API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE, parameters, {optimisticData, failureData, successData}); } -function updateQuickbooksOnlineNonReimbursableExpensesAccount(policyID: string, settingValue: QBOConnectionConfig['nonReimbursableExpensesAccount']) { - const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT, settingValue); +function updateQuickbooksOnlineNonReimbursableExpensesAccount( + policyID: string, + settingValue: TSettingValue, + oldSettingValue?: TSettingValue, +) { + const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_ACCOUNT, settingValue, oldSettingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, @@ -299,8 +307,12 @@ function updateQuickbooksOnlineNonReimbursableExpensesAccount(policyID: string, API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData}); } -function updateQuickbooksOnlineCollectionAccountID(policyID: string, settingValue: QBOConnectionConfig['collectionAccountID']) { - const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID, settingValue); +function updateQuickbooksOnlineCollectionAccountID( + policyID: string, + settingValue: TSettingValue, + oldSettingValue?: TSettingValue, +) { + const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.COLLECTION_ACCOUNT_ID, settingValue, oldSettingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index 25066e5f8335..6b4d395832bf 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -148,7 +148,11 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.reimbursedReportsDescription'), isActive: isSyncReimbursedSwitchOn, onToggle: () => - QuickbooksOnline.updateQuickbooksOnlineCollectionAccountID(policyID, isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions][0].id), + QuickbooksOnline.updateQuickbooksOnlineCollectionAccountID( + policyID, + isSyncReimbursedSwitchOn ? '' : [...qboAccountOptions, ...invoiceAccountCollectionOptions][0].id, + qboConfig?.collectionAccountID, + ), subscribedSetting: CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID, errors: ErrorUtils.getLatestErrorField(qboConfig, CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID), pendingAction: settingsPendingAction([CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID], qboConfig?.pendingFields), From 4c5afefba564c0583f96c0d8939326d0355c7fd3 Mon Sep 17 00:00:00 2001 From: VH Date: Thu, 5 Sep 2024 22:48:41 +0700 Subject: [PATCH 6/6] Change to new constant --- .../actions/connections/QuickbooksOnline.ts | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index b030f60059f2..a32363289268 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -271,23 +271,23 @@ function updateQuickbooksOnlineReceivableAccount(policyID: string, settingValue: TSettingValue, oldSettingValue?: TSettingValue) { - const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE, settingValue, oldSettingValue); + const {optimisticData, failureData, successData} = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICKBOOKS_CONFIG.EXPORT_DATE, settingValue, oldSettingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), - idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.EXPORT_DATE), + idempotencyKey: String(CONST.QUICKBOOKS_CONFIG.EXPORT_DATE), }; API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_EXPORT_DATE, parameters, {optimisticData, failureData, successData}); } @@ -297,12 +297,17 @@ function updateQuickbooksOnlineNonReimbursableExpensesAccount