From 0a783d5a9894df8560f7ece4bf457b2c5b62e809 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Wed, 7 Aug 2024 17:11:43 +0200 Subject: [PATCH 1/4] offline pattern toggle and selection list --- src/libs/actions/connections/SageIntacct.ts | 114 ++++++++++++------ .../intacct/SageIntacctEntityPage.tsx | 2 +- .../SageIntacctPaymentAccountPage.tsx | 2 +- .../intacct/export/SageIntacctDatePage.tsx | 2 +- .../export/SageIntacctDefaultVendorPage.tsx | 2 +- ...ctNonReimbursableCreditCardAccountPage.tsx | 2 +- ...SageIntacctNonReimbursableExpensesPage.tsx | 9 +- .../SageIntacctPreferredExporterPage.tsx | 2 +- .../SageIntacctReimbursableExpensesPage.tsx | 4 +- .../import/SageIntacctMappingsTypePage.tsx | 4 +- .../import/SageIntacctToggleMappingsPage.tsx | 4 +- 11 files changed, 96 insertions(+), 51 deletions(-) diff --git a/src/libs/actions/connections/SageIntacct.ts b/src/libs/actions/connections/SageIntacct.ts index 3f0ea96a37df..e047a3835531 100644 --- a/src/libs/actions/connections/SageIntacct.ts +++ b/src/libs/actions/connections/SageIntacct.ts @@ -30,7 +30,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 +68,9 @@ function prepareOnyxDataForMappingUpdate(policyID: string, mappingName: keyof Sa connections: { intacct: { config: { + mappings: { + [mappingName]: oldMappingValue ?? null, + }, pendingFields: { [mappingName]: null, }, @@ -105,7 +113,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 +133,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 +435,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 +449,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 +463,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 +473,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 +483,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 +498,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 +508,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 +522,7 @@ 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 prepareOnyxDataForConfigUpdate(policyID: string, settingName: keyof SageIntacctConnectionsConfig, settingValue: string | boolean | null, oldSettingValue?: string | boolean | null) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -526,6 +553,7 @@ function prepareOnyxDataForConfigUpdate(policyID: string, settingName: keyof Sag connections: { intacct: { config: { + [settingName]: oldSettingValue ?? null, pendingFields: { [settingName]: null, }, @@ -563,7 +591,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 +624,9 @@ function prepareOnyxDataForSyncUpdate(policyID: string, settingName: keyof Conne connections: { intacct: { config: { + sync: { + [settingName]: oldSettingValue ?? null, + }, pendingFields: { [settingName]: null, }, @@ -666,6 +697,9 @@ function prepareOnyxDataForAutoSyncUpdate(policyID: string, settingName: keyof C connections: { intacct: { config: { + autoSync: { + [settingName]: !settingValue, + }, pendingFields: { [settingName]: null, }, @@ -714,7 +748,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 +759,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 +775,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 +784,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 +794,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 { 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 ca9a7c61ce12..4b0073ff0005 100644 --- a/src/pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage.tsx +++ b/src/pages/workspace/accounting/intacct/export/SageIntacctDefaultVendorPage.tsx @@ -65,7 +65,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/SageIntacctMappingsTypePage.tsx b/src/pages/workspace/accounting/intacct/import/SageIntacctMappingsTypePage.tsx index cfa09fa0dc50..5e9f676e81d5 100644 --- a/src/pages/workspace/accounting/intacct/import/SageIntacctMappingsTypePage.tsx +++ b/src/pages/workspace/accounting/intacct/import/SageIntacctMappingsTypePage.tsx @@ -69,10 +69,10 @@ function SageIntacctMappingsTypePage({route}: SageIntacctMappingsTypePageProps) const updateMapping = useCallback( ({value}: SelectorType) => { - 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 d4f502227144..377827ec2f45 100644 --- a/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx +++ b/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx @@ -83,10 +83,10 @@ function SageIntacctToggleMappingsPage({route}: SageIntacctToggleMappingsPagePro onToggle={() => { if (importMapping) { setImportMapping(false); - updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.NONE); + updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.NONE, config?.mappings?.[mappingName]); } else { setImportMapping(true); - updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.TAG); + updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.TAG, config?.mappings?.[mappingName]); } }} pendingAction={settingsPendingAction([mappingName], config?.pendingFields)} From 375b7dd6a2dd4dcc17475c2ce096298d11d30162 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Thu, 8 Aug 2024 15:58:27 +0200 Subject: [PATCH 2/4] add offline patterns to udd --- src/libs/actions/connections/SageIntacct.ts | 42 +++++++++++++++---- .../SageIntacctEditUserDimensionsPage.tsx | 18 +++++++- .../import/SageIntacctToggleMappingsPage.tsx | 18 +++----- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/connections/SageIntacct.ts b/src/libs/actions/connections/SageIntacct.ts index e047a3835531..85d83b1c4452 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, @@ -234,7 +235,14 @@ function updateSageIntacctSyncTaxConfiguration(policyID: string, enabled: boolea API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_SYNC_TAX_CONFIGURATION, {policyID, enabled}, {optimisticData, failureData, successData}); } -function prepareOnyxDataForUserDimensionUpdate(policyID: string, dimensionName: string, newDimensions: SageIntacctDimension[]) { +function prepareOnyxDataForUserDimensionUpdate( + policyID: string, + dimensionName: string, + newDimensions: SageIntacctDimension[], + pendingAction: OnyxCommon.PendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, + oldDimensions?: SageIntacctDimension[], + oldDimensionName?: string, +) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -246,7 +254,7 @@ function prepareOnyxDataForUserDimensionUpdate(policyID: string, dimensionName: mappings: { dimensions: newDimensions, }, - pendingFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimensionName}`]: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}, + pendingFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimensionName}`]: pendingAction}, errorFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimensionName}`]: null}, }, }, @@ -255,6 +263,8 @@ function prepareOnyxDataForUserDimensionUpdate(policyID: string, dimensionName: }, ]; + const pendingActionAfterFailure = pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD ? pendingAction : null; + const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -264,11 +274,12 @@ function prepareOnyxDataForUserDimensionUpdate(policyID: string, dimensionName: intacct: { config: { mappings: { - dimensions: newDimensions, + dimensions: oldDimensions ?? newDimensions, }, - pendingFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimensionName}`]: null}, + pendingFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${oldDimensionName ?? dimensionName}`]: pendingActionAfterFailure}, errorFields: { - [`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimensionName}`]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${oldDimensionName ?? dimensionName}`]: + ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -311,7 +322,7 @@ function addSageIntacctUserDimensions( API.write( WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, {policyID, dimensions: JSON.stringify(newDimensions)}, - prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions), + prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, undefined), ); } @@ -329,7 +340,11 @@ function editSageIntacctUserDimensions( return userDimension; }); - API.write(WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, {policyID, dimensions: JSON.stringify(newDimensions)}, prepareOnyxDataForUserDimensionUpdate(policyID, name, newDimensions)); + API.write( + WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, + {policyID, dimensions: JSON.stringify(newDimensions)}, + prepareOnyxDataForUserDimensionUpdate(policyID, name, newDimensions, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, existingUserDimensions, previousName), + ); } function removeSageIntacctUserDimensions(policyID: string, dimensionName: string, existingUserDimensions: SageIntacctDimension[]) { @@ -338,7 +353,7 @@ function removeSageIntacctUserDimensions(policyID: string, dimensionName: string API.write( WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, {policyID, dimensions: JSON.stringify(newDimensions)}, - prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions), + prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions, CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, existingUserDimensions), ); } @@ -522,6 +537,15 @@ function clearSageIntacctErrorField(policyID: string, key: SageIntacctOfflineSta Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {connections: {intacct: {config: {errorFields: {[key]: 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[] = [ { @@ -810,8 +834,10 @@ export { updateSageIntacctMappingValue, editSageIntacctUserDimensions, removeSageIntacctUserDimensions, + removeSageIntacctUserDimensionsByName, updateSageIntacctExporter, clearSageIntacctErrorField, + clearSageIntacctPendingField, updateSageIntacctExportDate, updateSageIntacctReimbursableExpensesExportDestination, updateSageIntacctNonreimbursableExpensesExportDestination, diff --git a/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx b/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx index e9965de0d1ae..7106f857c001 100644 --- a/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx +++ b/src/pages/workspace/accounting/intacct/import/SageIntacctEditUserDimensionsPage.tsx @@ -13,7 +13,13 @@ import OfflineWithFeedback from '@components/OfflineWithFeedback'; import TextInput from '@components/TextInput'; import useLocalize from '@hooks/useLocalize'; 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}`); + }} > { - if (importMapping) { - setImportMapping(false); - updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.NONE, config?.mappings?.[mappingName]); - } else { - setImportMapping(true); - updateSageIntacctMappingValue(policyID, mappingName, CONST.SAGE_INTACCT_MAPPING_VALUE.TAG, config?.mappings?.[mappingName]); - } + isActive={config?.mappings?.[mappingName] !== CONST.SAGE_INTACCT_MAPPING_VALUE.NONE} + 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 && ( + {config?.mappings?.[mappingName] !== CONST.SAGE_INTACCT_MAPPING_VALUE.NONE && ( Date: Mon, 12 Aug 2024 10:04:48 +0200 Subject: [PATCH 3/4] Review suggestions --- src/libs/actions/connections/SageIntacct.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/connections/SageIntacct.ts b/src/libs/actions/connections/SageIntacct.ts index 85d83b1c4452..8cc554b7ec79 100644 --- a/src/libs/actions/connections/SageIntacct.ts +++ b/src/libs/actions/connections/SageIntacct.ts @@ -239,9 +239,9 @@ function prepareOnyxDataForUserDimensionUpdate( policyID: string, dimensionName: string, newDimensions: SageIntacctDimension[], - pendingAction: OnyxCommon.PendingAction = CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, - oldDimensions?: SageIntacctDimension[], - oldDimensionName?: string, + oldDimensions: SageIntacctDimension[], + oldDimensionName: string, + pendingAction: OnyxCommon.PendingAction, ) { const optimisticData: OnyxUpdate[] = [ { @@ -274,12 +274,11 @@ function prepareOnyxDataForUserDimensionUpdate( intacct: { config: { mappings: { - dimensions: oldDimensions ?? newDimensions, + dimensions: oldDimensions, }, - pendingFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${oldDimensionName ?? dimensionName}`]: pendingActionAfterFailure}, + pendingFields: {[`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${oldDimensionName}`]: pendingActionAfterFailure}, errorFields: { - [`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${oldDimensionName ?? dimensionName}`]: - ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), + [`${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${oldDimensionName}`]: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'), }, }, }, @@ -322,7 +321,7 @@ function addSageIntacctUserDimensions( API.write( WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, {policyID, dimensions: JSON.stringify(newDimensions)}, - prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, undefined), + prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions, newDimensions, dimensionName, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD), ); } @@ -343,7 +342,7 @@ function editSageIntacctUserDimensions( API.write( WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, {policyID, dimensions: JSON.stringify(newDimensions)}, - prepareOnyxDataForUserDimensionUpdate(policyID, name, newDimensions, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE, existingUserDimensions, previousName), + prepareOnyxDataForUserDimensionUpdate(policyID, name, newDimensions, existingUserDimensions, previousName, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE), ); } @@ -353,7 +352,7 @@ function removeSageIntacctUserDimensions(policyID: string, dimensionName: string API.write( WRITE_COMMANDS.UPDATE_SAGE_INTACCT_USER_DIMENSION, {policyID, dimensions: JSON.stringify(newDimensions)}, - prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions, CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, existingUserDimensions), + prepareOnyxDataForUserDimensionUpdate(policyID, dimensionName, newDimensions, existingUserDimensions, dimensionName, CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE), ); } From bd6cc8598ac46e5cd0940a78ff1c6aeb771474c8 Mon Sep 17 00:00:00 2001 From: 289Adam289 Date: Tue, 13 Aug 2024 11:36:54 +0200 Subject: [PATCH 4/4] review suggestions --- .../intacct/import/SageIntacctToggleMappingsPage.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx b/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx index f0cd40cd8b5d..56a8278346c3 100644 --- a/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx +++ b/src/pages/workspace/accounting/intacct/import/SageIntacctToggleMappingsPage.tsx @@ -54,7 +54,7 @@ function SageIntacctToggleMappingsPage({route}: SageIntacctToggleMappingsPagePro const config = policy?.connections?.intacct?.config; const translationKeys = getDisplayTypeTranslationKeys(config?.mappings?.[mappingName]); - + const isImportMappingEnable = config?.mappings?.[mappingName] !== CONST.SAGE_INTACCT_MAPPING_VALUE.NONE; return ( { const mappingValue = enabled ? CONST.SAGE_INTACCT_MAPPING_VALUE.TAG : CONST.SAGE_INTACCT_MAPPING_VALUE.NONE; updateSageIntacctMappingValue(policyID, mappingName, mappingValue, config?.mappings?.[mappingName]); @@ -86,7 +86,7 @@ function SageIntacctToggleMappingsPage({route}: SageIntacctToggleMappingsPagePro errors={ErrorUtils.getLatestErrorField(config ?? {}, mappingName)} onCloseError={() => clearSageIntacctErrorField(policyID, mappingName)} /> - {config?.mappings?.[mappingName] !== CONST.SAGE_INTACCT_MAPPING_VALUE.NONE && ( + {isImportMappingEnable && (