From c5815e63d0484eabcbb3f40a057718a2aa68869e Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 23 Aug 2024 15:57:17 +0700 Subject: [PATCH 1/3] inital tenant API --- .../ConnectToXeroFlow/index.native.tsx | 2 +- src/components/ConnectToXeroFlow/index.tsx | 2 +- .../parameters/UpdateXeroGenericTypeParams.ts | 7 + src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 10 ++ src/libs/actions/connections/ConnectToXero.ts | 29 ---- src/libs/actions/connections/Xero.ts | 145 ++++++++++++++++++ src/pages/workspace/accounting/utils.tsx | 2 +- .../accounting/xero/XeroImportPage.tsx | 2 +- .../XeroOrganizationConfigurationPage.tsx | 4 +- .../XeroTrackingCategoryConfigurationPage.tsx | 2 +- 11 files changed, 170 insertions(+), 36 deletions(-) create mode 100644 src/libs/API/parameters/UpdateXeroGenericTypeParams.ts delete mode 100644 src/libs/actions/connections/ConnectToXero.ts create mode 100644 src/libs/actions/connections/Xero.ts diff --git a/src/components/ConnectToXeroFlow/index.native.tsx b/src/components/ConnectToXeroFlow/index.native.tsx index e603fece6bd0..735c4bf131a3 100644 --- a/src/components/ConnectToXeroFlow/index.native.tsx +++ b/src/components/ConnectToXeroFlow/index.native.tsx @@ -8,7 +8,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton'; import Modal from '@components/Modal'; import RequireTwoFactorAuthenticationModal from '@components/RequireTwoFactorAuthenticationModal'; import useLocalize from '@hooks/useLocalize'; -import {getXeroSetupLink} from '@libs/actions/connections/ConnectToXero'; +import {getXeroSetupLink} from '@libs/actions/connections/Xero'; import getUAForWebView from '@libs/getUAForWebView'; import Navigation from '@libs/Navigation/Navigation'; import CONST from '@src/CONST'; diff --git a/src/components/ConnectToXeroFlow/index.tsx b/src/components/ConnectToXeroFlow/index.tsx index ade4c1191bb0..0a3403be78ec 100644 --- a/src/components/ConnectToXeroFlow/index.tsx +++ b/src/components/ConnectToXeroFlow/index.tsx @@ -3,7 +3,7 @@ import {useOnyx} from 'react-native-onyx'; import RequireTwoFactorAuthenticationModal from '@components/RequireTwoFactorAuthenticationModal'; import useEnvironment from '@hooks/useEnvironment'; import useLocalize from '@hooks/useLocalize'; -import {getXeroSetupLink} from '@libs/actions/connections/ConnectToXero'; +import {getXeroSetupLink} from '@libs/actions/connections/Xero'; import Navigation from '@libs/Navigation/Navigation'; import * as Link from '@userActions/Link'; import ONYXKEYS from '@src/ONYXKEYS'; diff --git a/src/libs/API/parameters/UpdateXeroGenericTypeParams.ts b/src/libs/API/parameters/UpdateXeroGenericTypeParams.ts new file mode 100644 index 000000000000..02667483bdd3 --- /dev/null +++ b/src/libs/API/parameters/UpdateXeroGenericTypeParams.ts @@ -0,0 +1,7 @@ +type UpdateXeroGenericTypeParams = { + policyID: string; + settingValue: string; + idempotencyKey: string; +}; + +export default UpdateXeroGenericTypeParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index a72220c3d943..351b6da47505 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -279,3 +279,4 @@ export type {default as UpdateExpensifyCardTitleParams} from './UpdateExpensifyC export type {default as OpenCardDetailsPageParams} from './OpenCardDetailsPageParams'; export type {default as ToggleCardContinuousReconciliationParams} from './ToggleCardContinuousReconciliationParams'; export type {default as UpdateExpensifyCardLimitTypeParams} from './UpdateExpensifyCardLimitTypeParams'; +export type {default as UpdateXeroGenericTypeParams} from './UpdateXeroGenericTypeParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index de63ed032afe..cdd56bdc6f2e 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -335,6 +335,10 @@ const WRITE_COMMANDS = { CREATE_EXPENSIFY_CARD: 'CreateExpensifyCard', CREATE_ADMIN_ISSUED_VIRTUAL_CARD: 'CreateAdminIssuedVirtualCard', TOGGLE_CARD_CONTINUOUS_RECONCILIATION: 'ToggleCardContinuousReconciliation', + UPDATE_XERO_IMPORT_TRACKING_CATEGORIES: 'UpdateXeroImportTrackingCategories', + UPDATE_XERO_IMPORT_TAX_RATES: 'UpdateXeroImportTaxRates', + UPDATE_XERO_TENANT_ID: 'UpdateXeroTenantID', + UPDATE_XERO_MAPPING: 'UpdateXeroMappings', } as const; type WriteCommand = ValueOf; @@ -675,6 +679,12 @@ type WriteCommandParameters = { [WRITE_COMMANDS.CREATE_EXPENSIFY_CARD]: Parameters.CreateExpensifyCardParams; [WRITE_COMMANDS.CREATE_ADMIN_ISSUED_VIRTUAL_CARD]: Omit; [WRITE_COMMANDS.TOGGLE_CARD_CONTINUOUS_RECONCILIATION]: Parameters.ToggleCardContinuousReconciliationParams; + + // Xero API + [WRITE_COMMANDS.UPDATE_XERO_TENANT_ID]: Parameters.UpdateXeroGenericTypeParams; + [WRITE_COMMANDS.UPDATE_XERO_IMPORT_TAX_RATES]: Parameters.UpdateXeroGenericTypeParams; + [WRITE_COMMANDS.UPDATE_XERO_MAPPING]: Parameters.UpdateXeroGenericTypeParams; + [WRITE_COMMANDS.UPDATE_XERO_IMPORT_TRACKING_CATEGORIES]: Parameters.UpdateXeroGenericTypeParams; }; const READ_COMMANDS = { diff --git a/src/libs/actions/connections/ConnectToXero.ts b/src/libs/actions/connections/ConnectToXero.ts deleted file mode 100644 index e327b218989c..000000000000 --- a/src/libs/actions/connections/ConnectToXero.ts +++ /dev/null @@ -1,29 +0,0 @@ -import type {OnyxEntry} from 'react-native-onyx'; -import type {ConnectPolicyToAccountingIntegrationParams} from '@libs/API/parameters'; -import {READ_COMMANDS} from '@libs/API/types'; -import {getCommandURL} from '@libs/ApiUtils'; -import CONST from '@src/CONST'; -import type * as OnyxTypes from '@src/types/onyx'; -import type {XeroTrackingCategory} from '@src/types/onyx/Policy'; - -const getXeroSetupLink = (policyID: string) => { - const params: ConnectPolicyToAccountingIntegrationParams = {policyID}; - const commandURL = getCommandURL({command: READ_COMMANDS.CONNECT_POLICY_TO_XERO, shouldSkipWebProxy: true}); - return commandURL + new URLSearchParams(params).toString(); -}; - -const getTrackingCategories = (policy: OnyxEntry): Array => { - const {trackingCategories} = policy?.connections?.xero?.data ?? {}; - const {mappings} = policy?.connections?.xero?.config ?? {}; - - if (!trackingCategories) { - return []; - } - - return trackingCategories.map((category) => ({ - ...category, - value: mappings?.[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`] ?? '', - })); -}; - -export {getXeroSetupLink, getTrackingCategories}; diff --git a/src/libs/actions/connections/Xero.ts b/src/libs/actions/connections/Xero.ts new file mode 100644 index 000000000000..4339c0663fd0 --- /dev/null +++ b/src/libs/actions/connections/Xero.ts @@ -0,0 +1,145 @@ +import isObject from 'lodash/isObject'; +import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; +import * as API from '@libs/API'; +import type {ConnectPolicyToAccountingIntegrationParams, UpdateXeroGenericTypeParams} from '@libs/API/parameters'; +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 * as OnyxTypes from '@src/types/onyx'; +import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; +import type {Connections, XeroTrackingCategory} from '@src/types/onyx/Policy'; + +const getXeroSetupLink = (policyID: string) => { + const params: ConnectPolicyToAccountingIntegrationParams = {policyID}; + const commandURL = getCommandURL({command: READ_COMMANDS.CONNECT_POLICY_TO_XERO, shouldSkipWebProxy: true}); + return commandURL + new URLSearchParams(params).toString(); +}; + +const getTrackingCategories = (policy: OnyxEntry): Array => { + const {trackingCategories} = policy?.connections?.xero?.data ?? {}; + const {mappings} = policy?.connections?.xero?.config ?? {}; + + if (!trackingCategories) { + return []; + } + + return trackingCategories.map((category) => ({ + ...category, + value: mappings?.[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`] ?? '', + })); +}; + +function createXeroPendingFields( + settingName: TSettingName, + settingValue: Partial, + pendingValue: OnyxCommon.PendingAction, +) { + if (!isObject(settingValue)) { + return {[settingName]: pendingValue}; + } + + return Object.keys(settingValue).reduce>((acc, setting) => { + acc[setting] = pendingValue; + return acc; + }, {}); +} + +function createXeroErrorFields( + settingName: TSettingName, + settingValue: Partial, + errorValue: OnyxCommon.Errors | null, +) { + if (!isObject(settingValue)) { + return {[settingName]: errorValue}; + } + + return Object.keys(settingValue).reduce((acc, setting) => { + acc[setting] = errorValue; + return acc; + }, {}); +} + +function prepareXeroOptimisticData( + policyID: string, + settingName: TSettingName, + settingValue: Partial, + oldSettingValue?: Partial | null, +) { + const optimisticData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + xero: { + config: { + [settingName]: settingValue ?? null, + pendingFields: createXeroPendingFields(settingName, settingValue, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE), + errorFields: createXeroErrorFields(settingName, settingValue, null), + }, + }, + }, + }, + }, + ]; + + const failureData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + xero: { + config: { + [settingName]: oldSettingValue ?? null, + pendingFields: createXeroPendingFields(settingName, settingValue, null), + errorFields: createXeroErrorFields(settingName, settingValue, ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')), + }, + }, + }, + }, + }, + ]; + + const successData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, + value: { + connections: { + xero: { + config: { + pendingFields: createXeroPendingFields(settingName, settingValue, null), + errorFields: createXeroErrorFields(settingName, settingValue, null), + }, + }, + }, + }, + }, + ]; + + return {optimisticData, failureData, successData}; +} + +function updateXeroImportTrackingCategories() {} + +function updateXeroImportTaxRates() {} + +function updateXeroTenantID(policyID: string, settingValue: string, oldSettingValue?: string) { + const parameters: UpdateXeroGenericTypeParams = { + policyID, + settingValue: JSON.stringify(settingValue), + idempotencyKey: String(CONST.XERO_CONFIG.TENANT_ID), + }; + + const {optimisticData, successData, failureData} = prepareXeroOptimisticData(policyID, CONST.XERO_CONFIG.TENANT_ID, settingValue, oldSettingValue); + + API.write(WRITE_COMMANDS.UPDATE_XERO_TENANT_ID, parameters, {optimisticData, successData, failureData}); +} + +function updateXeroMappings() {} + +export {getXeroSetupLink, getTrackingCategories, updateXeroImportTrackingCategories, updateXeroImportTaxRates, updateXeroTenantID, updateXeroMappings}; diff --git a/src/pages/workspace/accounting/utils.tsx b/src/pages/workspace/accounting/utils.tsx index 22bc97236b70..05ee41b85b9b 100644 --- a/src/pages/workspace/accounting/utils.tsx +++ b/src/pages/workspace/accounting/utils.tsx @@ -6,7 +6,7 @@ import ConnectToXeroFlow from '@components/ConnectToXeroFlow'; import * as Expensicons from '@components/Icon/Expensicons'; import type {LocaleContextProps} from '@components/LocaleContextProvider'; import Navigation from '@navigation/Navigation'; -import {getTrackingCategories} from '@userActions/connections/ConnectToXero'; +import {getTrackingCategories} from '@userActions/connections/Xero'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; import type {Policy} from '@src/types/onyx'; diff --git a/src/pages/workspace/accounting/xero/XeroImportPage.tsx b/src/pages/workspace/accounting/xero/XeroImportPage.tsx index db0252098b89..87f4b3a8ac9a 100644 --- a/src/pages/workspace/accounting/xero/XeroImportPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroImportPage.tsx @@ -10,7 +10,7 @@ import {getCurrentXeroOrganizationName} from '@libs/PolicyUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import withPolicy from '@pages/workspace/withPolicy'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; -import {getTrackingCategories} from '@userActions/connections/ConnectToXero'; +import {getTrackingCategories} from '@userActions/connections/Xero'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; diff --git a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx index b23363c79963..5137c98811b8 100644 --- a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx @@ -9,7 +9,7 @@ import SelectionScreen from '@components/SelectionScreen'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import {updatePolicyXeroConnectionConfig} from '@libs/actions/connections'; +import {updateXeroTenantID} from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; @@ -59,7 +59,7 @@ function XeroOrganizationConfigurationPage({ return; } - updatePolicyXeroConnectionConfig(policyID, CONST.POLICY.CONNECTIONS.NAME.XERO, CONST.XERO_CONFIG.TENANT_ID, keyForList, xeroConfig?.tenantID); + updateXeroTenantID(policyID, keyForList, xeroConfig?.tenantID); Navigation.goBack(); }; diff --git a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx index 9d27c8887e6e..3a1b154e08d9 100644 --- a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx @@ -6,7 +6,7 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Connections from '@libs/actions/connections'; -import {getTrackingCategories} from '@libs/actions/connections/ConnectToXero'; +import {getTrackingCategories} from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import {areSettingsInErrorFields, settingsPendingAction} from '@libs/PolicyUtils'; From 1baf50fe5c4740c6810b8bcefec3f56f00643911 Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 23 Aug 2024 17:07:56 +0700 Subject: [PATCH 2/3] update rest of the api --- src/libs/actions/connections/Xero.ts | 49 +++++++++++++++++-- ...roMapTrackingCategoryConfigurationPage.tsx | 6 +-- .../xero/XeroTaxesConfigurationPage.tsx | 12 +---- .../XeroTrackingCategoryConfigurationPage.tsx | 12 +---- 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/src/libs/actions/connections/Xero.ts b/src/libs/actions/connections/Xero.ts index 4339c0663fd0..fa08dec2e391 100644 --- a/src/libs/actions/connections/Xero.ts +++ b/src/libs/actions/connections/Xero.ts @@ -124,9 +124,42 @@ function prepareXeroOptimisticData, + oldImportTrackingCategories?: Partial, +) { + const parameters: UpdateXeroGenericTypeParams = { + policyID, + settingValue: JSON.stringify(importTrackingCategories), + idempotencyKey: String(CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES), + }; + + const {optimisticData, failureData, successData} = prepareXeroOptimisticData( + policyID, + CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES, + importTrackingCategories, + oldImportTrackingCategories, + ); -function updateXeroImportTaxRates() {} + API.write(WRITE_COMMANDS.UPDATE_XERO_IMPORT_TRACKING_CATEGORIES, parameters, {optimisticData, failureData, successData}); +} + +function updateXeroImportTaxRates( + policyID: string, + importTaxesRate: Partial, + oldImportTaxesRate?: Partial, +) { + const parameters: UpdateXeroGenericTypeParams = { + policyID, + settingValue: JSON.stringify(importTaxesRate), + idempotencyKey: String(CONST.XERO_CONFIG.IMPORT_TAX_RATES), + }; + + const {optimisticData, failureData, successData} = prepareXeroOptimisticData(policyID, CONST.XERO_CONFIG.IMPORT_TAX_RATES, importTaxesRate, oldImportTaxesRate); + + API.write(WRITE_COMMANDS.UPDATE_XERO_IMPORT_TAX_RATES, parameters, {optimisticData, failureData, successData}); +} function updateXeroTenantID(policyID: string, settingValue: string, oldSettingValue?: string) { const parameters: UpdateXeroGenericTypeParams = { @@ -140,6 +173,16 @@ function updateXeroTenantID(policyID: string, settingValue: string, oldSettingVa API.write(WRITE_COMMANDS.UPDATE_XERO_TENANT_ID, parameters, {optimisticData, successData, failureData}); } -function updateXeroMappings() {} +function updateXeroMappings(policyID: string, mappingValue: Partial, oldMappingValue?: Partial) { + const parameters: UpdateXeroGenericTypeParams = { + policyID, + settingValue: JSON.stringify(mappingValue), + idempotencyKey: String(CONST.XERO_CONFIG.MAPPINGS), + }; + + const {optimisticData, failureData, successData} = prepareXeroOptimisticData(policyID, CONST.XERO_CONFIG.MAPPINGS, mappingValue, oldMappingValue); + + API.write(WRITE_COMMANDS.UPDATE_XERO_MAPPING, parameters, {optimisticData, failureData, successData}); +} export {getXeroSetupLink, getTrackingCategories, updateXeroImportTrackingCategories, updateXeroImportTaxRates, updateXeroTenantID, updateXeroMappings}; diff --git a/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx index 42e3f50bae0a..dae46f32dc54 100644 --- a/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroMapTrackingCategoryConfigurationPage.tsx @@ -6,7 +6,7 @@ import SelectionScreen from '@components/SelectionScreen'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Connections from '@libs/actions/connections'; +import * as Xero from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import {settingsPendingAction} from '@libs/PolicyUtils'; @@ -60,10 +60,8 @@ function XeroMapTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { const updateMapping = useCallback( (option: {value: string}) => { if (option.value !== categoryName) { - Connections.updatePolicyXeroConnectionConfig( + Xero.updateXeroMappings( policyID, - CONST.POLICY.CONNECTIONS.NAME.XERO, - CONST.XERO_CONFIG.MAPPINGS, categoryId ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`]: option.value} : {}, categoryId ? {[`${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${categoryId}`]: currentTrackingCategoryValue} : {}, ); diff --git a/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx index 57053cb30808..cf695b57aa38 100644 --- a/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroTaxesConfigurationPage.tsx @@ -2,7 +2,7 @@ import React from 'react'; import ConnectionLayout from '@components/ConnectionLayout'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Connections from '@libs/actions/connections'; +import * as Xero from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import * as PolicyUtils from '@libs/PolicyUtils'; import type {WithPolicyProps} from '@pages/workspace/withPolicy'; @@ -33,15 +33,7 @@ function XeroTaxesConfigurationPage({policy}: WithPolicyProps) { title={translate('workspace.accounting.import')} switchAccessibilityLabel={translate('workspace.xero.customers')} isActive={isSwitchOn} - onToggle={() => - Connections.updatePolicyXeroConnectionConfig( - policyID, - CONST.POLICY.CONNECTIONS.NAME.XERO, - CONST.XERO_CONFIG.IMPORT_TAX_RATES, - !xeroConfig?.importTaxRates, - xeroConfig?.importTaxRates, - ) - } + onToggle={() => Xero.updateXeroImportTaxRates(policyID, !xeroConfig?.importTaxRates, xeroConfig?.importTaxRates)} errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.IMPORT_TAX_RATES)} onCloseError={() => Policy.clearXeroErrorField(policyID, CONST.XERO_CONFIG.IMPORT_TAX_RATES)} pendingAction={PolicyUtils.settingsPendingAction([CONST.XERO_CONFIG.IMPORT_TAX_RATES], xeroConfig?.pendingFields)} diff --git a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx index 3a1b154e08d9..98b8bbb3a89c 100644 --- a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx @@ -5,7 +5,7 @@ import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import * as Connections from '@libs/actions/connections'; +import * as Xero from '@libs/actions/connections/Xero'; import {getTrackingCategories} from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; @@ -53,15 +53,7 @@ function XeroTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { switchAccessibilityLabel={translate('workspace.xero.trackingCategories')} isActive={isSwitchOn} wrapperStyle={styles.mv3} - onToggle={() => - Connections.updatePolicyXeroConnectionConfig( - policyID, - CONST.POLICY.CONNECTIONS.NAME.XERO, - CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES, - !xeroConfig?.importTrackingCategories, - xeroConfig?.importTrackingCategories, - ) - } + onToggle={() => Xero.updateXeroImportTrackingCategories(policyID, !xeroConfig?.importTrackingCategories, xeroConfig?.importTrackingCategories)} pendingAction={settingsPendingAction([CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES], xeroConfig?.pendingFields)} errors={ErrorUtils.getLatestErrorField(xeroConfig ?? {}, CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES)} onCloseError={() => Policy.clearXeroErrorField(policyID, CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES)} From 9485198ebba281dfdae1acf70b29680ce7aed7b2 Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 23 Aug 2024 17:21:51 +0700 Subject: [PATCH 3/3] small cleanup --- .../accounting/xero/XeroOrganizationConfigurationPage.tsx | 4 ++-- .../accounting/xero/XeroTrackingCategoryConfigurationPage.tsx | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx index 5137c98811b8..bb49c5212fb2 100644 --- a/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroOrganizationConfigurationPage.tsx @@ -9,7 +9,7 @@ import SelectionScreen from '@components/SelectionScreen'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import {updateXeroTenantID} from '@libs/actions/connections/Xero'; +import * as Xero from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; @@ -59,7 +59,7 @@ function XeroOrganizationConfigurationPage({ return; } - updateXeroTenantID(policyID, keyForList, xeroConfig?.tenantID); + Xero.updateXeroTenantID(policyID, keyForList, xeroConfig?.tenantID); Navigation.goBack(); }; diff --git a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx index 98b8bbb3a89c..5aa6b2cd4efe 100644 --- a/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx +++ b/src/pages/workspace/accounting/xero/XeroTrackingCategoryConfigurationPage.tsx @@ -6,7 +6,6 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Xero from '@libs/actions/connections/Xero'; -import {getTrackingCategories} from '@libs/actions/connections/Xero'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import {areSettingsInErrorFields, settingsPendingAction} from '@libs/PolicyUtils'; @@ -28,7 +27,7 @@ function XeroTrackingCategoryConfigurationPage({policy}: WithPolicyProps) { const isSwitchOn = !!xeroConfig?.importTrackingCategories; const menuItems = useMemo(() => { - const trackingCategories = getTrackingCategories(policy); + const trackingCategories = Xero.getTrackingCategories(policy); return trackingCategories.map((category: XeroTrackingCategory & {value: string}) => ({ id: category.id, description: translate('workspace.xero.mapTrackingCategoryTo', {categoryName: category.name}) as TranslationPaths,