From fd0a9a8769bc057d6b582b24085b4ec045dfa6be Mon Sep 17 00:00:00 2001 From: Yauheni Date: Mon, 19 Aug 2024 13:06:19 +0200 Subject: [PATCH 1/9] Update UpdatePolicyConnectionConfiguration to be 1:1:1 Part-3 --- src/libs/API/types.ts | 10 + .../actions/connections/QuickbooksOnline.ts | 389 +++++++++++++++++- ...NonReimbursableDefaultVendorSelectPage.tsx | 4 +- .../qbo/import/QuickbooksClassesPage.tsx | 6 +- .../qbo/import/QuickbooksCustomersPage.tsx | 6 +- .../qbo/import/QuickbooksLocationsPage.tsx | 6 +- .../qbo/import/QuickbooksTaxesPage.tsx | 4 +- 7 files changed, 407 insertions(+), 18 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index ef39e9bf005b..62efc0c4ad32 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -210,6 +210,11 @@ 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_SYNC_TAX: 'UpdateQuickbooksOnlineSyncTax', + UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS: 'UpdateQuickbooksOnlineSyncLocations', + UPDATE_QUICKBOOKS_ONLINE_SYNC_CUSTOMERS: 'UpdateQuickbooksOnlineSyncCustomers', + UPDATE_QUICKBOOKS_ONLINE_SYNC_CLASSES: 'UpdateQuickbooksOnlineSyncClasses', + UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_BILL_DEFAULT_VENDOR: 'UpdateQuickbooksOnlineNonReimbursableBillDefaultVendor', UPDATE_MANY_POLICY_CONNECTION_CONFIGS: 'UpdateManyPolicyConnectionConfigurations', REMOVE_POLICY_CONNECTION: 'RemovePolicyConnection', SET_POLICY_TAXES_ENABLED: 'SetPolicyTaxesEnabled', @@ -551,6 +556,11 @@ type WriteCommandParameters = { [WRITE_COMMANDS.CLEAR_OUTSTANDING_BALANCE]: null; [WRITE_COMMANDS.CANCEL_BILLING_SUBSCRIPTION]: Parameters.CancelBillingSubscriptionParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CUSTOMERS]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CLASSES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: 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_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index a3216378add3..b7646f848667 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, IntegrationEntityMap} from '@src/types/onyx/Policy'; type ConnectionNameExceptNetSuite = Exclude; @@ -249,4 +249,389 @@ function updateQuickbooksOnlineReimbursableExpensesAccount { if (row.value !== nonReimbursableBillDefaultVendor) { - Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, row.value); + QuickbooksOnline.updateQuickbooksOnlineNonReimbursableBillDefaultVendor(policyID, row.value); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_COMPANY_CARD_EXPENSE_ACCOUNT.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/qbo/import/QuickbooksClassesPage.tsx b/src/pages/workspace/accounting/qbo/import/QuickbooksClassesPage.tsx index 023c676d2018..af2d8da42216 100644 --- a/src/pages/workspace/accounting/qbo/import/QuickbooksClassesPage.tsx +++ b/src/pages/workspace/accounting/qbo/import/QuickbooksClassesPage.tsx @@ -9,7 +9,7 @@ import Switch from '@components/Switch'; 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 AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -48,10 +48,8 @@ function QuickbooksClassesPage({policy}: WithPolicyProps) { accessibilityLabel={translate('workspace.qbo.classes')} isOn={isSwitchOn} onToggle={() => - Connections.updatePolicyConnectionConfig( + QuickbooksOnline.updateQuickbooksOnlineSyncClasses( policyID, - CONST.POLICY.CONNECTIONS.NAME.QBO, - CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES, isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, ) } diff --git a/src/pages/workspace/accounting/qbo/import/QuickbooksCustomersPage.tsx b/src/pages/workspace/accounting/qbo/import/QuickbooksCustomersPage.tsx index 6d4f8c8c9f1e..949978492dc9 100644 --- a/src/pages/workspace/accounting/qbo/import/QuickbooksCustomersPage.tsx +++ b/src/pages/workspace/accounting/qbo/import/QuickbooksCustomersPage.tsx @@ -9,7 +9,7 @@ import Switch from '@components/Switch'; 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 AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -47,10 +47,8 @@ function QuickbooksCustomersPage({policy}: WithPolicyProps) { accessibilityLabel={translate('workspace.qbo.customers')} isOn={isSwitchOn} onToggle={() => - Connections.updatePolicyConnectionConfig( + QuickbooksOnline.updateQuickbooksOnlineSyncCustomers( policyID, - CONST.POLICY.CONNECTIONS.NAME.QBO, - CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS, isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, ) } diff --git a/src/pages/workspace/accounting/qbo/import/QuickbooksLocationsPage.tsx b/src/pages/workspace/accounting/qbo/import/QuickbooksLocationsPage.tsx index e1fd7ed0d160..5368d2ff8fb2 100644 --- a/src/pages/workspace/accounting/qbo/import/QuickbooksLocationsPage.tsx +++ b/src/pages/workspace/accounting/qbo/import/QuickbooksLocationsPage.tsx @@ -9,7 +9,7 @@ import Switch from '@components/Switch'; 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 AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -52,10 +52,8 @@ function QuickbooksLocationsPage({policy}: WithPolicyProps) { accessibilityLabel={translate('workspace.qbo.locations')} isOn={isSwitchOn} onToggle={() => - Connections.updatePolicyConnectionConfig( + QuickbooksOnline.updateQuickbooksOnlineSyncLocations( policyID, - CONST.POLICY.CONNECTIONS.NAME.QBO, - CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS, isSwitchOn ? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.TAG, ) } diff --git a/src/pages/workspace/accounting/qbo/import/QuickbooksTaxesPage.tsx b/src/pages/workspace/accounting/qbo/import/QuickbooksTaxesPage.tsx index 30680d2c935a..ecc1eaf7af5a 100644 --- a/src/pages/workspace/accounting/qbo/import/QuickbooksTaxesPage.tsx +++ b/src/pages/workspace/accounting/qbo/import/QuickbooksTaxesPage.tsx @@ -8,7 +8,7 @@ import Switch from '@components/Switch'; 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 AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -45,7 +45,7 @@ function QuickbooksTaxesPage({policy}: WithPolicyProps) { Connections.updatePolicyConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.QBO, CONST.QUICK_BOOKS_CONFIG.SYNC_TAX, !syncTax)} + onToggle={() => QuickbooksOnline.updateQuickbooksOnlineSyncTax(policyID, !syncTax)} disabled={!syncTax && isJournalExportEntity} /> From dd6fb2b45892e1049cfde18afc61ebe22a341c2b Mon Sep 17 00:00:00 2001 From: Yauheni Date: Tue, 20 Aug 2024 17:30:42 +0200 Subject: [PATCH 2/9] Refactor updateQuickbooks functions --- .../actions/connections/QuickbooksOnline.ts | 394 ++++-------------- 1 file changed, 75 insertions(+), 319 deletions(-) diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index b7646f848667..0eee1e3e9d22 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -21,7 +21,11 @@ function getQuickbooksOnlineSetupLink(policyID: string) { return commandURL + new URLSearchParams(params).toString(); } -function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValue: boolean) { +function updateQuickbooksOnyxData( + policyID: string, + settingName: TSettingName, + settingValue: Partial, +) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -30,12 +34,12 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, + [settingName]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + [settingName]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, + [settingName]: null, }, }, }, @@ -52,12 +56,12 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, + [settingName]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, + [settingName]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [settingName]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -74,12 +78,12 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, + [settingName]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, + [settingName]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, + [settingName]: null, }, }, }, @@ -87,16 +91,14 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu }, }, ]; - - const parameters: UpdateQuickbooksOnlineGenericTypeParams = { - policyID, - settingValue: JSON.stringify(settingValue), - idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES), + return { + optimisticData, + failureData, + successData, }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES, parameters, {optimisticData, failureData, successData}); } -function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: boolean) { +function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValue: boolean) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -105,12 +107,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: settingValue ?? null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, }, }, }, @@ -127,12 +129,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: settingValue ?? null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -149,12 +151,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: settingValue ?? null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, }, }, }, @@ -166,15 +168,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), - idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES, parameters, {optimisticData, failureData, successData}); } -function updateQuickbooksOnlineReimbursableExpensesAccount( - policyID: string, - settingValue: Partial, -) { +function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: boolean) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -183,12 +182,12 @@ function updateQuickbooksOnlineReimbursableExpensesAccount( + policyID: string, + settingValue: Partial, +) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -258,12 +260,12 @@ function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: Int connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: settingValue ?? null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, }, }, }, @@ -280,12 +282,12 @@ function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: Int connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: settingValue ?? null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -302,12 +304,12 @@ function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: Int connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: settingValue ?? null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS]: null, + [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, }, }, }, @@ -319,309 +321,63 @@ function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: Int const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), - idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData}); } -function updateQuickbooksOnlineSyncCustomers(policyID: string, settingValue: IntegrationEntityMap) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: null, - }, - }, - }, - }, - }, - }, - ]; +function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: IntegrationEntityMap) { + const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS, settingValue); - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), - }, - }, - }, - }, - }, - }, - ]; + const parameters: UpdateQuickbooksOnlineGenericTypeParams = { + policyID, + settingValue: JSON.stringify(settingValue), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS), + }; + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS, parameters, onyxData); +} - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS]: null, - }, - }, - }, - }, - }, - }, - ]; +function updateQuickbooksOnlineSyncCustomers(policyID: string, settingValue: IntegrationEntityMap) { + const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_CUSTOMERS), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CUSTOMERS, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CUSTOMERS, parameters, onyxData); } function updateQuickbooksOnlineSyncClasses(policyID: string, settingValue: IntegrationEntityMap) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: null, - }, - }, - }, - }, - }, - }, - ]; - - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), - }, - }, - }, - }, - }, - }, - ]; - - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES]: null, - }, - }, - }, - }, - }, - }, - ]; - + const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_CLASSES), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CLASSES, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CLASSES, parameters, onyxData); } function updateQuickbooksOnlineNonReimbursableBillDefaultVendor(policyID: string, settingValue: string) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: null, - }, - }, - }, - }, - }, - }, - ]; - - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), - }, - }, - }, - }, - }, - }, - ]; - - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: null, - }, - }, - }, - }, - }, - }, - ]; + const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, parameters, onyxData); } function updateQuickbooksOnlineSyncTax(policyID: string, settingValue: boolean) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: null, - }, - }, - }, - }, - }, - }, - ]; - - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), - }, - }, - }, - }, - }, - }, - ]; - - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.SYNC_TAX]: null, - }, - }, - }, - }, - }, - }, - ]; + const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.SYNC_TAX, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_TAX), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX, parameters, onyxData); } export { From 3ab6198cedd85176151da754c114f5e700ca91bf Mon Sep 17 00:00:00 2001 From: Yauheni Date: Tue, 27 Aug 2024 23:54:05 +0200 Subject: [PATCH 3/9] refactor few updateQuickbooksOnline evenets --- .../actions/connections/QuickbooksOnline.ts | 204 +----------------- 1 file changed, 6 insertions(+), 198 deletions(-) diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index 0eee1e3e9d22..f0af1ab9dc57 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -99,231 +99,39 @@ function updateQuickbooksOnyxData( policyID: string, settingValue: Partial, ) { - const optimisticData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, - }, - }, - }, - }, - }, - }, - ]; - - const failureData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), - }, - }, - }, - }, - }, - }, - ]; - - const successData: OnyxUpdate[] = [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, - value: { - connections: { - [CONST.POLICY.CONNECTIONS.NAME.QBO]: { - config: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, - }, - }, - }, - }, - }, - }, - ]; + const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT), }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, onyxData); } function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: IntegrationEntityMap) { From 24166f65be640cf44916830981c324feef5b79d7 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Wed, 28 Aug 2024 18:22:58 +0200 Subject: [PATCH 4/9] Update WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR --- src/libs/API/types.ts | 2 -- .../actions/connections/QuickbooksOnline.ts | 12 ---------- .../qbo/advanced/QuickbooksAdvancedPage.tsx | 23 +++++++++++++++---- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 864338dc6ffd..982ec596384e 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -211,7 +211,6 @@ const WRITE_COMMANDS = { CREATE_POLICY_TAX: 'CreatePolicyTax', UPDATE_POLICY_CONNECTION_CONFIG: 'UpdatePolicyConnectionConfiguration', UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES: 'UpdateQuickbooksOnlineEnableNewCategories', - UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR: 'UpdateQuickbooksOnlineAutoCreateVendor', UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineReimbursableExpensesAccount', UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX: 'UpdateQuickbooksOnlineSyncTax', UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS: 'UpdateQuickbooksOnlineSyncLocations', @@ -568,7 +567,6 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CUSTOMERS]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CLASSES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: 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_POLICY_CONNECTION_CONFIG]: Parameters.UpdatePolicyConnectionConfigParams; [WRITE_COMMANDS.UPDATE_MANY_POLICY_CONNECTION_CONFIGS]: Parameters.UpdateManyPolicyConnectionConfigurationsParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index f0af1ab9dc57..ef0fbb810c9a 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -109,17 +109,6 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES, parameters, onyxData); } -function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: boolean) { - const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR, settingValue); - - const parameters: UpdateQuickbooksOnlineGenericTypeParams = { - policyID, - settingValue: JSON.stringify(settingValue), - idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR), - }; - API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR, parameters, onyxData); -} - function updateQuickbooksOnlineReimbursableExpensesAccount( policyID: string, settingValue: Partial, @@ -191,7 +180,6 @@ function updateQuickbooksOnlineSyncTax(policyID: string, settingValue: boolean) export { getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, - updateQuickbooksOnlineAutoCreateVendor, updateQuickbooksOnlineReimbursableExpensesAccount, updateQuickbooksOnlineNonReimbursableBillDefaultVendor, updateQuickbooksOnlineSyncTax, diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index a0b89e4e5baf..b5bf70653792 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -9,7 +9,6 @@ import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import useWaitForNavigation from '@hooks/useWaitForNavigation'; import * as Connections from '@libs/actions/connections'; -import * as QuickbooksOnline from '@libs/actions/connections/QuickbooksOnline'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -29,8 +28,9 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { const policyID = policy?.id ?? '-1'; const qboConfig = policy?.connections?.quickbooksOnline?.config; const {autoSync, syncPeople, autoCreateVendor, pendingFields, collectionAccountID, reimbursementAccountID, errorFields} = qboConfig ?? {}; - const {bankAccounts, creditCards, otherCurrentAssetAccounts} = policy?.connections?.quickbooksOnline?.data ?? {}; - + const {bankAccounts, creditCards, otherCurrentAssetAccounts, vendors} = policy?.connections?.quickbooksOnline?.data ?? {}; + const {nonReimbursableBillDefaultVendor} = policy?.connections?.quickbooksOnline?.config ?? {}; + const nonReimbursableBillDefaultVendorObject = vendors?.find((vendor) => vendor.id === nonReimbursableBillDefaultVendor); const qboAccountOptions = useMemo(() => [...(bankAccounts ?? []), ...(creditCards ?? [])], [bankAccounts, creditCards]); const invoiceAccountCollectionOptions = useMemo(() => [...(bankAccounts ?? []), ...(otherCurrentAssetAccounts ?? [])], [bankAccounts, otherCurrentAssetAccounts]); @@ -100,7 +100,22 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { subtitle: translate('workspace.qbo.advancedConfig.createEntitiesDescription'), switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.createEntitiesDescription'), isActive: !!autoCreateVendor, - onToggle: () => QuickbooksOnline.updateQuickbooksOnlineAutoCreateVendor(policyID, !autoCreateVendor), + onToggle: (isOn) => { + Connections.updateManyPolicyConnectionConfigs( + policyID, + CONST.POLICY.CONNECTIONS.NAME.QBO, + { + [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: isOn, + [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: isOn + ? policy?.connections?.quickbooksOnline?.data?.vendors?.[0]?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE + : CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE, + }, + { + [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: autoCreateVendor, + [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableBillDefaultVendorObject?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE, + }, + ); + }, pendingAction: pendingFields?.autoCreateVendor, errors: ErrorUtils.getLatestErrorField(qboConfig ?? {}, CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR), onCloseError: () => Policy.clearQBOErrorField(policyID, CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR), From 2580c6b1a4c1b2e386b3b2e1a3da0115e7bb138e Mon Sep 17 00:00:00 2001 From: Yauheni Date: Thu, 29 Aug 2024 10:06:45 +0200 Subject: [PATCH 5/9] return updateQuickbooksOnlineAutoCreateVendor and add updateManyQuickbooksOnyxData --- ...eQuickbooksOnlineAutoCreateVendorParams.ts | 8 ++ src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 2 + .../actions/connections/QuickbooksOnline.ts | 85 +++++++++++++++++++ .../qbo/advanced/QuickbooksAdvancedPage.tsx | 4 +- 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/libs/API/parameters/UpdateQuickbooksOnlineAutoCreateVendorParams.ts diff --git a/src/libs/API/parameters/UpdateQuickbooksOnlineAutoCreateVendorParams.ts b/src/libs/API/parameters/UpdateQuickbooksOnlineAutoCreateVendorParams.ts new file mode 100644 index 000000000000..293db6795f07 --- /dev/null +++ b/src/libs/API/parameters/UpdateQuickbooksOnlineAutoCreateVendorParams.ts @@ -0,0 +1,8 @@ +type UpdateQuickbooksOnlineAutoCreateVendorParams = { + policyID: string; + autoCreateVendor: string; + nonReimbursableBillDefaultVendor: string; + idempotencyKey: string; +}; + +export default UpdateQuickbooksOnlineAutoCreateVendorParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 9696f4213a48..4657922f2e11 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -280,3 +280,4 @@ export type {default as OpenCardDetailsPageParams} from './OpenCardDetailsPagePa export type {default as EnablePolicyCompanyCardsParams} from './EnablePolicyCompanyCardsParams'; export type {default as ToggleCardContinuousReconciliationParams} from './ToggleCardContinuousReconciliationParams'; export type {default as UpdateExpensifyCardLimitTypeParams} from './UpdateExpensifyCardLimitTypeParams'; +export type {default as UpdateQuickbooksOnlineAutoCreateVendorParams} from './UpdateQuickbooksOnlineAutoCreateVendorParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 982ec596384e..7f1298466b0c 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -211,6 +211,7 @@ const WRITE_COMMANDS = { CREATE_POLICY_TAX: 'CreatePolicyTax', UPDATE_POLICY_CONNECTION_CONFIG: 'UpdatePolicyConnectionConfiguration', UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES: 'UpdateQuickbooksOnlineEnableNewCategories', + UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR: 'UpdateQuickbooksOnlineAutoCreateVendor', UPDATE_QUICKBOOKS_ONLINE_REIMBURSABLE_EXPENSES_ACCOUNT: 'UpdateQuickbooksOnlineReimbursableExpensesAccount', UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX: 'UpdateQuickbooksOnlineSyncTax', UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS: 'UpdateQuickbooksOnlineSyncLocations', @@ -562,6 +563,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.CLEAR_OUTSTANDING_BALANCE]: null; [WRITE_COMMANDS.CANCEL_BILLING_SUBSCRIPTION]: Parameters.CancelBillingSubscriptionParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; + [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR]: Parameters.UpdateQuickbooksOnlineAutoCreateVendorParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; [WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_CUSTOMERS]: Parameters.UpdateQuickbooksOnlineGenericTypeParams; diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index ef0fbb810c9a..6d46fe9eb370 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -2,6 +2,7 @@ import type {OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; import * as API from '@libs/API'; import type {ConnectPolicyToAccountingIntegrationParams} from '@libs/API/parameters'; +import type UpdateQuickbooksOnlineAutoCreateVendorParams from '@libs/API/parameters/UpdateQuickbooksOnlineAutoCreateVendorParams'; import type UpdateQuickbooksOnlineGenericTypeParams from '@libs/API/parameters/UpdateQuickbooksOnlineGenericTypeParams'; import {READ_COMMANDS, WRITE_COMMANDS} from '@libs/API/types'; import {getCommandURL} from '@libs/ApiUtils'; @@ -21,6 +22,72 @@ function getQuickbooksOnlineSetupLink(policyID: string) { return commandURL + new URLSearchParams(params).toString(); } +function updateManyQuickbooksOnyxData>( + policyID: string, + configUpdate: TConfigUpdate, + configCurrentData: TConfigUpdate, +) { + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + ...configUpdate, + pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE])), + errorFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), + }, + }, + }, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + [CONST.POLICY.CONNECTIONS.NAME.QBO]: { + config: { + ...configCurrentData, + pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), + errorFields: Object.fromEntries( + Object.keys(configUpdate).map((settingName) => [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: { + pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), + errorFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), + }, + }, + }, + }, + }, + ]; + return { + optimisticData, + failureData, + successData, + }; +} + function updateQuickbooksOnyxData( policyID: string, settingName: TSettingName, @@ -109,6 +176,23 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_ENABLE_NEW_CATEGORIES, parameters, onyxData); } +function updateQuickbooksOnlineAutoCreateVendor>( + policyID: string, + configUpdate: TConfigUpdate, + configCurrentData: TConfigUpdate, +) { + const onyxData = updateManyQuickbooksOnyxData(policyID, configUpdate, configCurrentData); + + const parameters: UpdateQuickbooksOnlineAutoCreateVendorParams = { + policyID, + autoCreateVendor: JSON.stringify(configUpdate.autoCreateVendor), + nonReimbursableBillDefaultVendor: JSON.stringify(configUpdate.nonReimbursableBillDefaultVendor), + idempotencyKey: CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR, + }; + + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR, parameters, onyxData); +} + function updateQuickbooksOnlineReimbursableExpensesAccount( policyID: string, settingValue: Partial, @@ -180,6 +264,7 @@ function updateQuickbooksOnlineSyncTax(policyID: string, settingValue: boolean) export { getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, + updateQuickbooksOnlineAutoCreateVendor, updateQuickbooksOnlineReimbursableExpensesAccount, updateQuickbooksOnlineNonReimbursableBillDefaultVendor, updateQuickbooksOnlineSyncTax, diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index b5bf70653792..80a15270ebad 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -9,6 +9,7 @@ import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import useWaitForNavigation from '@hooks/useWaitForNavigation'; import * as Connections from '@libs/actions/connections'; +import * as QuickbooksOnline from '@libs/actions/connections/QuickbooksOnline'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; @@ -101,9 +102,8 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.createEntitiesDescription'), isActive: !!autoCreateVendor, onToggle: (isOn) => { - Connections.updateManyPolicyConnectionConfigs( + QuickbooksOnline.updateQuickbooksOnlineAutoCreateVendor( policyID, - CONST.POLICY.CONNECTIONS.NAME.QBO, { [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: isOn, [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: isOn From 25a21b0dde92757a6f7794c306ab3b13ced99b78 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Thu, 29 Aug 2024 10:32:25 +0200 Subject: [PATCH 6/9] fix react-compiler issue --- .../qbo/advanced/QuickbooksAdvancedPage.tsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index 80a15270ebad..52cf856ac8a4 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -102,17 +102,22 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.createEntitiesDescription'), isActive: !!autoCreateVendor, onToggle: (isOn) => { + const autoCreateVendorKey = CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR; + const nonReimbursableVendorKey = CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR; + const nonReimbursableVendorUpdateValue = isOn + ? policy?.connections?.quickbooksOnline?.data?.vendors?.[0]?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE + : CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE; + const nonReimbursableVendorCurrentValue = nonReimbursableBillDefaultVendorObject?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE; + QuickbooksOnline.updateQuickbooksOnlineAutoCreateVendor( policyID, { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: isOn, - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: isOn - ? policy?.connections?.quickbooksOnline?.data?.vendors?.[0]?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE - : CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE, + [autoCreateVendorKey]: isOn, + [nonReimbursableVendorKey]: nonReimbursableVendorUpdateValue, }, { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: autoCreateVendor, - [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableBillDefaultVendorObject?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE, + [autoCreateVendorKey]: autoCreateVendor, + [nonReimbursableVendorKey]: nonReimbursableVendorCurrentValue, }, ); }, From 5248360dd977e795b3643d081c294a3ff5159030 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Thu, 29 Aug 2024 10:34:44 +0200 Subject: [PATCH 7/9] refactor code --- .../accounting/qbo/advanced/QuickbooksAdvancedPage.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index 52cf856ac8a4..a8a35df1c449 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -102,8 +102,6 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.qbo.advancedConfig.createEntitiesDescription'), isActive: !!autoCreateVendor, onToggle: (isOn) => { - const autoCreateVendorKey = CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR; - const nonReimbursableVendorKey = CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR; const nonReimbursableVendorUpdateValue = isOn ? policy?.connections?.quickbooksOnline?.data?.vendors?.[0]?.id ?? CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE : CONST.INTEGRATION_ENTITY_MAP_TYPES.NONE; @@ -112,12 +110,12 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { QuickbooksOnline.updateQuickbooksOnlineAutoCreateVendor( policyID, { - [autoCreateVendorKey]: isOn, - [nonReimbursableVendorKey]: nonReimbursableVendorUpdateValue, + [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: isOn, + [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorUpdateValue, }, { - [autoCreateVendorKey]: autoCreateVendor, - [nonReimbursableVendorKey]: nonReimbursableVendorCurrentValue, + [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: autoCreateVendor, + [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorCurrentValue, }, ); }, From 61ea5b318bc6eeef7bc6475f5301700a914b2115 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Thu, 29 Aug 2024 10:57:11 +0200 Subject: [PATCH 8/9] update autoCreateVendor for updateQuickbooksOnlineAutoCreateVendor --- .../accounting/qbo/advanced/QuickbooksAdvancedPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index a8a35df1c449..385510cb7ff4 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -114,7 +114,7 @@ function QuickbooksAdvancedPage({policy}: WithPolicyConnectionsProps) { [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorUpdateValue, }, { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: autoCreateVendor, + [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: !!autoCreateVendor, [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorCurrentValue, }, ); From a15ebccd7963d0bc75478aea43fa31a9d588fde5 Mon Sep 17 00:00:00 2001 From: Yauheni Date: Fri, 30 Aug 2024 17:01:47 +0200 Subject: [PATCH 9/9] rename builders for onyxData for Quickbooks --- .../actions/connections/QuickbooksOnline.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/connections/QuickbooksOnline.ts b/src/libs/actions/connections/QuickbooksOnline.ts index 6d46fe9eb370..d758b6f3b073 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -22,7 +22,7 @@ function getQuickbooksOnlineSetupLink(policyID: string) { return commandURL + new URLSearchParams(params).toString(); } -function updateManyQuickbooksOnyxData>( +function buildOnyxDataForMultipleQuickbooksConfigurations>( policyID: string, configUpdate: TConfigUpdate, configCurrentData: TConfigUpdate, @@ -88,7 +88,7 @@ function updateManyQuickbooksOnyxData( +function buildOnyxDataForQuickbooksConfiguration( policyID: string, settingName: TSettingName, settingValue: Partial, @@ -166,7 +166,7 @@ function updateQuickbooksOnyxData, ) { - const onyxData = updateQuickbooksOnyxData(policyID, CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, settingValue); + const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, @@ -208,7 +208,7 @@ function updateQuickbooksOnlineReimbursableExpensesAccount