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 a94a36300da8..8402e0c38533 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -288,6 +288,7 @@ export type {default as EnablePolicyCompanyCardsParams} from './EnablePolicyComp export type {default as ToggleCardContinuousReconciliationParams} from './ToggleCardContinuousReconciliationParams'; export type {default as CardDeactivateParams} from './CardDeactivateParams'; export type {default as UpdateExpensifyCardLimitTypeParams} from './UpdateExpensifyCardLimitTypeParams'; +export type {default as UpdateQuickbooksOnlineAutoCreateVendorParams} from './UpdateQuickbooksOnlineAutoCreateVendorParams'; export type {default as ImportCategoriesSpreadsheetParams} from './ImportCategoriesSpreadsheet'; export type {default as UpdateXeroGenericTypeParams} from './UpdateXeroGenericTypeParams'; export type {default as UpdateCardSettlementFrequencyParams} from './UpdateCardSettlementFrequencyParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 7370bc2ccd96..0dfde7147c1c 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -221,6 +221,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', @@ -587,7 +592,12 @@ type WriteCommandParameters = { [WRITE_COMMANDS.SET_POLICY_BILLABLE_MODE]: Parameters.SetPolicyBillableMode; [WRITE_COMMANDS.SET_WORKSPACE_ERECEIPTS_ENABLED]: Parameters.SetWorkspaceEReceiptsEnabled; [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_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; + [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_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 a3216378add3..d758b6f3b073 100644 --- a/src/libs/actions/connections/QuickbooksOnline.ts +++ b/src/libs/actions/connections/QuickbooksOnline.ts @@ -2,13 +2,14 @@ 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'; 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; @@ -21,7 +22,11 @@ function getQuickbooksOnlineSetupLink(policyID: string) { return commandURL + new URLSearchParams(params).toString(); } -function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValue: boolean) { +function buildOnyxDataForMultipleQuickbooksConfigurations>( + policyID: string, + configUpdate: TConfigUpdate, + configCurrentData: TConfigUpdate, +) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -30,13 +35,9 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, - }, + ...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])), }, }, }, @@ -52,13 +53,11 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), - }, + ...configCurrentData, + pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), + errorFields: Object.fromEntries( + Object.keys(configUpdate).map((settingName) => [settingName, ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')]), + ), }, }, }, @@ -74,29 +73,26 @@ function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValu connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES]: null, - }, + pendingFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), + errorFields: Object.fromEntries(Object.keys(configUpdate).map((settingName) => [settingName, null])), }, }, }, }, }, ]; - - 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 buildOnyxDataForQuickbooksConfiguration( + policyID: string, + settingName: TSettingName, + settingValue: Partial, +) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -105,12 +101,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: settingValue ?? null, + [settingName]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + [settingName]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [settingName]: null, }, }, }, @@ -127,12 +123,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: settingValue ?? null, + [settingName]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [settingName]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [settingName]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -149,12 +145,12 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: connections: { [CONST.POLICY.CONNECTIONS.NAME.QBO]: { config: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: settingValue ?? null, + [settingName]: settingValue ?? null, pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [settingName]: null, }, errorFields: { - [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: null, + [settingName]: null, }, }, }, @@ -162,91 +158,117 @@ function updateQuickbooksOnlineAutoCreateVendor(policyID: string, settingValue: }, }, ]; + return { + optimisticData, + failureData, + successData, + }; +} + +function updateQuickbooksOnlineEnableNewCategories(policyID: string, settingValue: boolean) { + const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.ENABLE_NEW_CATEGORIES, 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_ENABLE_NEW_CATEGORIES, parameters, onyxData); +} + +function updateQuickbooksOnlineAutoCreateVendor>( + policyID: string, + configUpdate: TConfigUpdate, + configCurrentData: TConfigUpdate, +) { + const onyxData = buildOnyxDataForMultipleQuickbooksConfigurations(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, {optimisticData, failureData, successData}); + + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_AUTO_CREATE_VENDOR, parameters, onyxData); } function updateQuickbooksOnlineReimbursableExpensesAccount( 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 onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, 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.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 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, 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.REIMBURSABLE_EXPENSES_ACCOUNT]: settingValue ?? null, - pendingFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, - }, - errorFields: { - [CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT]: null, - }, - }, - }, - }, - }, - }, - ]; +function updateQuickbooksOnlineSyncLocations(policyID: string, settingValue: IntegrationEntityMap) { + const onyxData = buildOnyxDataForQuickbooksConfiguration(policyID, CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS, settingValue); const parameters: UpdateQuickbooksOnlineGenericTypeParams = { policyID, settingValue: JSON.stringify(settingValue), - idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT), + idempotencyKey: String(CONST.QUICK_BOOKS_CONFIG.SYNC_LOCATIONS), + }; + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_LOCATIONS, parameters, onyxData); +} + +function updateQuickbooksOnlineSyncCustomers(policyID: string, settingValue: IntegrationEntityMap) { + const onyxData = buildOnyxDataForQuickbooksConfiguration(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, onyxData); +} + +function updateQuickbooksOnlineSyncClasses(policyID: string, settingValue: IntegrationEntityMap) { + const onyxData = buildOnyxDataForQuickbooksConfiguration(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, onyxData); +} + +function updateQuickbooksOnlineNonReimbursableBillDefaultVendor(policyID: string, settingValue: string) { + const onyxData = buildOnyxDataForQuickbooksConfiguration(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, onyxData); +} + +function updateQuickbooksOnlineSyncTax(policyID: string, settingValue: boolean) { + const onyxData = buildOnyxDataForQuickbooksConfiguration(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_REIMBURSABLE_EXPENSES_ACCOUNT, parameters, {optimisticData, failureData, successData}); + API.write(WRITE_COMMANDS.UPDATE_QUICKBOOKS_ONLINE_SYNC_TAX, parameters, onyxData); } -export {getQuickbooksOnlineSetupLink, updateQuickbooksOnlineEnableNewCategories, updateQuickbooksOnlineAutoCreateVendor, updateQuickbooksOnlineReimbursableExpensesAccount}; +export { + getQuickbooksOnlineSetupLink, + updateQuickbooksOnlineEnableNewCategories, + updateQuickbooksOnlineAutoCreateVendor, + updateQuickbooksOnlineReimbursableExpensesAccount, + updateQuickbooksOnlineNonReimbursableBillDefaultVendor, + updateQuickbooksOnlineSyncTax, + updateQuickbooksOnlineSyncClasses, + updateQuickbooksOnlineSyncLocations, + updateQuickbooksOnlineSyncCustomers, +}; diff --git a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx index a0b89e4e5baf..385510cb7ff4 100644 --- a/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx +++ b/src/pages/workspace/accounting/qbo/advanced/QuickbooksAdvancedPage.tsx @@ -29,8 +29,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 +101,24 @@ 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) => { + 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]: nonReimbursableVendorUpdateValue, + }, + { + [CONST.QUICK_BOOKS_CONFIG.AUTO_CREATE_VENDOR]: !!autoCreateVendor, + [CONST.QUICK_BOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR]: nonReimbursableVendorCurrentValue, + }, + ); + }, 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), diff --git a/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx b/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx index d57da414b57b..368cecc5de3b 100644 --- a/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx +++ b/src/pages/workspace/accounting/qbo/export/QuickbooksNonReimbursableDefaultVendorSelectPage.tsx @@ -8,7 +8,7 @@ import RadioListItem from '@components/SelectionList/RadioListItem'; import type {ListItem} from '@components/SelectionList/types'; 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'; @@ -42,7 +42,7 @@ function QuickbooksNonReimbursableDefaultVendorSelectPage({policy}: WithPolicyCo const selectVendor = useCallback( (row: CardListItem) => { 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} />