diff --git a/src/libs/actions/connections/SageIntacct.ts b/src/libs/actions/connections/SageIntacct.ts index 3f0ea96a37df..8cc554b7ec79 100644 --- a/src/libs/actions/connections/SageIntacct.ts +++ b/src/libs/actions/connections/SageIntacct.ts @@ -7,6 +7,7 @@ import {WRITE_COMMANDS} from '@libs/API/types'; import * as ErrorUtils from '@libs/ErrorUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; import type { Connections, SageIntacctConnectionsConfig, @@ -30,7 +31,12 @@ function connectToSageIntacct(policyID: string, credentials: SageIntacctCredenti API.write(WRITE_COMMANDS.CONNECT_POLICY_TO_SAGE_INTACCT, parameters, {}); } -function prepareOnyxDataForMappingUpdate(policyID: string, mappingName: keyof SageIntacctMappingType, mappingValue: boolean | SageIntacctMappingValue) { +function prepareOnyxDataForMappingUpdate( + policyID: string, + mappingName: keyof SageIntacctMappingType, + mappingValue: boolean | SageIntacctMappingValue, + oldMappingValue?: boolean | SageIntacctMappingValue, +) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -63,6 +69,9 @@ function prepareOnyxDataForMappingUpdate(policyID: string, mappingName: keyof Sa connections: { intacct: { config: { + mappings: { + [mappingName]: oldMappingValue ?? null, + }, pendingFields: { [mappingName]: null, }, @@ -105,7 +114,7 @@ function updateSageIntacctBillable(policyID: string, enabled: boolean) { policyID, enabled, }; - API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_BILLABLE, parameters, prepareOnyxDataForMappingUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.SYNC_ITEMS, enabled)); + API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_BILLABLE, parameters, prepareOnyxDataForMappingUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.SYNC_ITEMS, enabled, !enabled)); } function getCommandForMapping(mappingName: ValueOf) { @@ -125,13 +134,13 @@ function getCommandForMapping(mappingName: ValueOf) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.EXPORT_DATE, date); +function updateSageIntacctExportDate(policyID: string, date: ValueOf, oldDate?: ValueOf) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.EXPORT_DATE, date, oldDate); const parameters = { policyID, value: date, @@ -421,8 +449,12 @@ function updateSageIntacctExportDate(policyID: string, date: ValueOf) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE, reimbursable); +function updateSageIntacctReimbursableExpensesExportDestination( + policyID: string, + reimbursable: ValueOf, + oldReimbursable?: ValueOf, +) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE, reimbursable, oldReimbursable); const parameters = { policyID, value: reimbursable, @@ -431,8 +463,12 @@ function updateSageIntacctReimbursableExpensesExportDestination(policyID: string API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctNonreimbursableExpensesExportDestination(policyID: string, nonReimbursable: ValueOf) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE, nonReimbursable); +function updateSageIntacctNonreimbursableExpensesExportDestination( + policyID: string, + nonReimbursable: ValueOf, + oldNonReimbursable?: ValueOf, +) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE, nonReimbursable, oldNonReimbursable); const parameters = { policyID, value: nonReimbursable, @@ -441,8 +477,8 @@ function updateSageIntacctNonreimbursableExpensesExportDestination(policyID: str API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID: string, vendor: string) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor); +function updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID: string, vendor: string, oldVendor?: string) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor, oldVendor); const parameters = { policyID, vendorID: vendor, @@ -451,8 +487,8 @@ function updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_REIMBURSABLE_EXPENSES_REPORT_EXPORT_DEFAULT_VENDOR, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendor(policyID: string, vendor: string) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor); +function updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendor(policyID: string, vendor: string, oldVendor?: string) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor, oldVendor); const parameters = { policyID, vendorID: vendor, @@ -461,8 +497,13 @@ function updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVe API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_CREDIT_CARD_CHARGE_EXPORT_DEFAULT_VENDOR, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctNonreimbursableExpensesExportAccount(policyID: string, nonReimbursableAccount: string) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT, nonReimbursableAccount); +function updateSageIntacctNonreimbursableExpensesExportAccount(policyID: string, nonReimbursableAccount: string, oldReimbursableAccount?: string) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate( + policyID, + CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT, + nonReimbursableAccount, + oldReimbursableAccount, + ); const parameters = { policyID, creditCardAccountID: nonReimbursableAccount, @@ -471,8 +512,8 @@ function updateSageIntacctNonreimbursableExpensesExportAccount(policyID: string, API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_ACCOUNT, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctNonreimbursableExpensesExportVendor(policyID: string, vendor: string) { - const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR, vendor); +function updateSageIntacctNonreimbursableExpensesExportVendor(policyID: string, vendor: string, oldVendor?: string) { + const {optimisticData, failureData, successData} = prepareOnyxDataForExportUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR, vendor, oldVendor); const parameters = { policyID, vendorID: vendor, @@ -481,13 +522,13 @@ function updateSageIntacctNonreimbursableExpensesExportVendor(policyID: string, API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES_EXPORT_VENDOR, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctDefaultVendor(policyID: string, settingName: keyof SageIntacctExportConfig, vendor: string) { +function updateSageIntacctDefaultVendor(policyID: string, settingName: keyof SageIntacctExportConfig, vendor: string, oldVendor?: string) { if (settingName === CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR) { - updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID, vendor); + updateSageIntacctReimbursableExpensesReportExportDefaultVendor(policyID, vendor, oldVendor); } else if (settingName === CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR) { - updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendor(policyID, vendor); + updateSageIntacctNonreimbursableExpensesCreditCardChargeExportDefaultVendor(policyID, vendor, oldVendor); } else if (settingName === CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR) { - updateSageIntacctNonreimbursableExpensesExportVendor(policyID, vendor); + updateSageIntacctNonreimbursableExpensesExportVendor(policyID, vendor, oldVendor); } } @@ -495,7 +536,16 @@ function clearSageIntacctErrorField(policyID: string, key: SageIntacctOfflineSta Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {intacct: {config: {errorFields: {[key]: null}}}}}); } -function prepareOnyxDataForConfigUpdate(policyID: string, settingName: keyof SageIntacctConnectionsConfig, settingValue: string | boolean | null) { +function clearSageIntacctPendingField(policyID: string, key: SageIntacctOfflineStateKeys | keyof SageIntacctConnectionsConfig) { + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {intacct: {config: {pendingFields: {[key]: null}}}}}); +} + +function removeSageIntacctUserDimensionsByName(dimensions: SageIntacctDimension[], policyID: string, dimensionName: string) { + const Dimensions = dimensions.filter((dimension) => dimension.dimension !== dimensionName); + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {intacct: {config: {mappings: {dimensions: Dimensions}}}}}); +} + +function prepareOnyxDataForConfigUpdate(policyID: string, settingName: keyof SageIntacctConnectionsConfig, settingValue: string | boolean | null, oldSettingValue?: string | boolean | null) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -526,6 +576,7 @@ function prepareOnyxDataForConfigUpdate(policyID: string, settingName: keyof Sag connections: { intacct: { config: { + [settingName]: oldSettingValue ?? null, pendingFields: { [settingName]: null, }, @@ -563,7 +614,7 @@ function prepareOnyxDataForConfigUpdate(policyID: string, settingName: keyof Sag return {optimisticData, failureData, successData}; } -function prepareOnyxDataForSyncUpdate(policyID: string, settingName: keyof Connections['intacct']['config']['sync'], settingValue: string | boolean) { +function prepareOnyxDataForSyncUpdate(policyID: string, settingName: keyof Connections['intacct']['config']['sync'], settingValue: string | boolean, oldSettingValue?: string | boolean) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -596,6 +647,9 @@ function prepareOnyxDataForSyncUpdate(policyID: string, settingName: keyof Conne connections: { intacct: { config: { + sync: { + [settingName]: oldSettingValue ?? null, + }, pendingFields: { [settingName]: null, }, @@ -666,6 +720,9 @@ function prepareOnyxDataForAutoSyncUpdate(policyID: string, settingName: keyof C connections: { intacct: { config: { + autoSync: { + [settingName]: !settingValue, + }, pendingFields: { [settingName]: null, }, @@ -714,7 +771,7 @@ function updateSageIntacctAutoSync(policyID: string, enabled: boolean) { } function updateSageIntacctImportEmployees(policyID: string, enabled: boolean) { - const {optimisticData, failureData, successData} = prepareOnyxDataForConfigUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES, enabled); + const {optimisticData, failureData, successData} = prepareOnyxDataForConfigUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES, enabled, !enabled); const parameters = { policyID, enabled, @@ -725,7 +782,13 @@ function updateSageIntacctImportEmployees(policyID: string, enabled: boolean) { function updateSageIntacctApprovalMode(policyID: string, enabled: boolean) { const approvalModeSettingValue = enabled ? CONST.SAGE_INTACCT.APPROVAL_MODE.APPROVAL_MANUAL : ''; - const {optimisticData, failureData, successData} = prepareOnyxDataForConfigUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE, approvalModeSettingValue); + const oldApprovalModeSettingValue = enabled ? '' : CONST.SAGE_INTACCT.APPROVAL_MODE.APPROVAL_MANUAL; + const {optimisticData, failureData, successData} = prepareOnyxDataForConfigUpdate( + policyID, + CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE, + approvalModeSettingValue, + oldApprovalModeSettingValue, + ); const parameters = { policyID, value: approvalModeSettingValue, @@ -735,7 +798,7 @@ function updateSageIntacctApprovalMode(policyID: string, enabled: boolean) { } function updateSageIntacctSyncReimbursedReports(policyID: string, enabled: boolean) { - const {optimisticData, failureData, successData} = prepareOnyxDataForSyncUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS, enabled); + const {optimisticData, failureData, successData} = prepareOnyxDataForSyncUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS, enabled, !enabled); const parameters = { policyID, enabled, @@ -744,8 +807,8 @@ function updateSageIntacctSyncReimbursedReports(policyID: string, enabled: boole API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_SYNC_REIMBURSED_REPORTS, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctSyncReimbursementAccountID(policyID: string, vendorID: string) { - const {optimisticData, failureData, successData} = prepareOnyxDataForSyncUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSEMENT_ACCOUNT_ID, vendorID); +function updateSageIntacctSyncReimbursementAccountID(policyID: string, vendorID: string, oldVendorID?: string) { + const {optimisticData, failureData, successData} = prepareOnyxDataForSyncUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSEMENT_ACCOUNT_ID, vendorID, oldVendorID); const parameters = { policyID, vendorID, @@ -754,12 +817,12 @@ function updateSageIntacctSyncReimbursementAccountID(policyID: string, vendorID: API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_SYNC_REIMBURSEMENT_ACCOUNT_ID, parameters, {optimisticData, failureData, successData}); } -function updateSageIntacctEntity(policyID: string, entity: string) { +function updateSageIntacctEntity(policyID: string, entity: string, oldEntity: string) { const parameters = { policyID, entity, }; - API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_ENTITY, parameters, prepareOnyxDataForConfigUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.ENTITY, entity)); + API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_ENTITY, parameters, prepareOnyxDataForConfigUpdate(policyID, CONST.SAGE_INTACCT_CONFIG.ENTITY, entity, oldEntity)); } export { @@ -770,8 +833,10 @@ export { updateSageIntacctMappingValue, editSageIntacctUserDimensions, removeSageIntacctUserDimensions, + removeSageIntacctUserDimensionsByName, updateSageIntacctExporter, clearSageIntacctErrorField, + clearSageIntacctPendingField, updateSageIntacctExportDate, updateSageIntacctReimbursableExpensesExportDestination, updateSageIntacctNonreimbursableExpensesExportDestination, diff --git a/src/pages/workspace/accounting/intacct/SageIntacctEntityPage.tsx b/src/pages/workspace/accounting/intacct/SageIntacctEntityPage.tsx index a841954563e7..f96ca2738480 100644 --- a/src/pages/workspace/accounting/intacct/SageIntacctEntityPage.tsx +++ b/src/pages/workspace/accounting/intacct/SageIntacctEntityPage.tsx @@ -38,7 +38,7 @@ function SageIntacctEntityPage({policy}: WithPolicyProps) { }); const saveSelection = ({keyForList}: ListItem) => { - updateSageIntacctEntity(policyID, keyForList ?? ''); + updateSageIntacctEntity(policyID, keyForList ?? '', entityID); Navigation.goBack(); }; diff --git a/src/pages/workspace/accounting/intacct/advanced/SageIntacctPaymentAccountPage.tsx b/src/pages/workspace/accounting/intacct/advanced/SageIntacctPaymentAccountPage.tsx index 558f5668702b..5bb6205b8160 100644 --- a/src/pages/workspace/accounting/intacct/advanced/SageIntacctPaymentAccountPage.tsx +++ b/src/pages/workspace/accounting/intacct/advanced/SageIntacctPaymentAccountPage.tsx @@ -30,7 +30,7 @@ function SageIntacctPaymentAccountPage({policy}: WithPolicyConnectionsProps) { const updateDefaultVendor = useCallback( ({value}: SelectorType) => { if (value !== config?.sync?.reimbursementAccountID) { - updateSageIntacctSyncReimbursementAccountID(policyID, value); + updateSageIntacctSyncReimbursementAccountID(policyID, value, config?.sync?.reimbursementAccountID); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_ADVANCED.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctDatePage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctDatePage.tsx index bb6316d934dc..bf4a3dbf058d 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctDatePage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctDatePage.tsx @@ -48,7 +48,7 @@ function SageIntacctDatePage({policy}: WithPolicyProps) { const selectExportDate = useCallback( (row: MenuListItem) => { if (row.value !== exportConfig?.exportDate) { - updateSageIntacctExportDate(policyID, row.value); + updateSageIntacctExportDate(policyID, row.value, exportConfig?.exportDate); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage.tsx index dea44fe68856..9070ba0820fe 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage.tsx @@ -64,7 +64,7 @@ function SageIntacctDefaultVendorPage({route}: SageIntacctDefaultVendorPageProps const updateDefaultVendor = useCallback( ({value}: SelectorType) => { if (value !== defaultVendor) { - updateSageIntacctDefaultVendor(policyID, settingName, value); + updateSageIntacctDefaultVendor(policyID, settingName, value, defaultVendor); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableCreditCardAccountPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableCreditCardAccountPage.tsx index 671cd8924bcd..1eaeaeaad0c3 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableCreditCardAccountPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableCreditCardAccountPage.tsx @@ -30,7 +30,7 @@ function SageIntacctNonReimbursableCreditCardAccountPage({policy}: WithPolicyCon const updateCreditCardAccount = useCallback( ({value}: SelectorType) => { if (value !== exportConfig?.nonReimbursableAccount) { - updateSageIntacctNonreimbursableExpensesExportAccount(policyID, value); + updateSageIntacctNonreimbursableExpensesExportAccount(policyID, value, exportConfig?.nonReimbursableAccount); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_NON_REIMBURSABLE_EXPENSES.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx index 563f0654ef80..808c497c05da 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctNonReimbursableExpensesPage.tsx @@ -48,7 +48,7 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { if (row.value === config?.export.nonReimbursable) { return; } - updateSageIntacctNonreimbursableExpensesExportDestination(policyID, row.value); + updateSageIntacctNonreimbursableExpensesExportDestination(policyID, row.value, config?.export.nonReimbursable); }, [config?.export.nonReimbursable, policyID], ); @@ -152,7 +152,12 @@ function SageIntacctNonReimbursableExpensesPage({policy}: WithPolicyProps) { isActive={!!config?.export.nonReimbursableCreditCardChargeDefaultVendor} onToggle={(enabled) => { const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; - updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, vendor); + updateSageIntacctDefaultVendor( + policyID, + CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, + vendor, + config?.export.nonReimbursableCreditCardChargeDefaultVendor, + ); }} wrapperStyle={[styles.ph5, styles.pv3]} pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR], config?.pendingFields)} diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctPreferredExporterPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctPreferredExporterPage.tsx index 63d99396fc51..0617b8b690fe 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctPreferredExporterPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctPreferredExporterPage.tsx @@ -67,7 +67,7 @@ function SageIntacctPreferredExporterPage({policy}: WithPolicyProps) { const selectExporter = useCallback( (row: CardListItem) => { if (row.value !== exportConfiguration?.exporter) { - updateSageIntacctExporter(policyID, row.value); + updateSageIntacctExporter(policyID, row.value, exportConfiguration?.exporter); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx index e0c23bd7f7d4..360da1ac7a2d 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctReimbursableExpensesPage.tsx @@ -47,7 +47,7 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) { const selectReimbursableDestination = useCallback( (row: MenuListItem) => { if (row.value !== reimbursable) { - updateSageIntacctReimbursableExpensesExportDestination(policyID, row.value); + updateSageIntacctReimbursableExpensesExportDestination(policyID, row.value, reimbursable); } if (row.value === CONST.SAGE_INTACCT_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL) { // Employee default mapping value is not allowed when expense type is VENDOR_BILL, so we have to change mapping value to Tag @@ -124,7 +124,7 @@ function SageIntacctReimbursableExpensesPage({policy}: WithPolicyProps) { isActive={!!reimbursableExpenseReportDefaultVendor} onToggle={(enabled) => { const vendor = enabled ? policy?.connections?.intacct?.data?.vendors?.[0].id ?? '' : ''; - updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor); + updateSageIntacctDefaultVendor(policyID, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, vendor, reimbursableExpenseReportDefaultVendor); }} pendingAction={settingsPendingAction([CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR], config?.pendingFields)} errors={ErrorUtils.getLatestErrorField(config, CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR)} diff --git a/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx b/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx index 7bbb25f3d7cb..cd10e270d7d2 100644 --- a/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx +++ b/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx @@ -13,7 +13,13 @@ import TextInput from '@components/TextInput'; import useLocalize from '@hooks/useLocalize'; import usePolicy from '@hooks/usePolicy'; import useThemeStyles from '@hooks/useThemeStyles'; -import {clearSageIntacctErrorField, editSageIntacctUserDimensions, removeSageIntacctUserDimensions} from '@libs/actions/connections/SageIntacct'; +import { + clearSageIntacctErrorField, + clearSageIntacctPendingField, + editSageIntacctUserDimensions, + removeSageIntacctUserDimensions, + removeSageIntacctUserDimensionsByName, +} from '@libs/actions/connections/SageIntacct'; import * as ErrorUtils from '@libs/ErrorUtils'; import Navigation from '@libs/Navigation/Navigation'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; @@ -89,7 +95,15 @@ function SageIntacctEditUserDimensionsPage({route}: SageIntacctEditUserDimension pendingAction={settingsPendingAction([`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${editedUserDimensionName}`], config?.pendingFields)} errors={ErrorUtils.getLatestErrorField(config ?? {}, `${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${editedUserDimensionName}`)} errorRowStyles={[styles.pb3]} - onClose={() => clearSageIntacctErrorField(policyID, `${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${editedUserDimensionName}`)} + onClose={() => { + clearSageIntacctErrorField(policyID, `${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${editedUserDimensionName}`); + const pendingAction = settingsPendingAction([`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${editedUserDimensionName}`], config?.pendingFields); + if (pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) { + removeSageIntacctUserDimensionsByName(userDimensions ?? [], policyID, editedUserDimensionName); + Navigation.goBack(); + } + clearSageIntacctPendingField(policyID, `${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${editedUserDimensionName}`); + }} > { - updateSageIntacctMappingValue(policyID, mappingName, value as SageIntacctMappingValue); + updateSageIntacctMappingValue(policyID, mappingName, value as SageIntacctMappingValue, mappings?.[mappingName]); Navigation.goBack(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_TOGGLE_MAPPINGS.getRoute(policyID, mappingName)); }, - [mappingName, policyID], + [mappingName, policyID, mappings], ); return ( diff --git a/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx b/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx index 9d74fa5cee97..56a8278346c3 100644 --- a/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx +++ b/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx @@ -1,6 +1,6 @@ import type {StackScreenProps} from '@react-navigation/stack'; import {Str} from 'expensify-common'; -import React, {useState} from 'react'; +import React from 'react'; import ConnectionLayout from '@components/ConnectionLayout'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; @@ -54,8 +54,7 @@ function SageIntacctToggleMappingsPage({route}: SageIntacctToggleMappingsPagePro const config = policy?.connections?.intacct?.config; const translationKeys = getDisplayTypeTranslationKeys(config?.mappings?.[mappingName]); - const [importMapping, setImportMapping] = useState(config?.mappings?.[mappingName] && config?.mappings?.[mappingName] !== CONST.SAGE_INTACCT_MAPPING_VALUE.NONE); - + const isImportMappingEnable = config?.mappings?.[mappingName] !== CONST.SAGE_INTACCT_MAPPING_VALUE.NONE; return ( { - if (importMapping) { - setImportMapping(false); - updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.NONE); - } else { - setImportMapping(true); - updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.TAG); - } + isActive={isImportMappingEnable} + onToggle={(enabled) => { + const mappingValue = enabled ? CONST.SAGE_INTACCT_MAPPING_VALUE.TAG : CONST.SAGE_INTACCT_MAPPING_VALUE.NONE; + updateSageIntacctMappingValue(policyID, mappingName, mappingValue, config?.mappings?.[mappingName]); }} pendingAction={settingsPendingAction([mappingName], config?.pendingFields)} errors={ErrorUtils.getLatestErrorField(config ?? {}, mappingName)} onCloseError={() => clearSageIntacctErrorField(policyID, mappingName)} /> - {importMapping && ( + {isImportMappingEnable && (