diff --git a/src/libs/actions/connections/NetSuiteCommands.ts b/src/libs/actions/connections/NetSuiteCommands.ts index 7d25d9ae3e35..7c0d4f2f418a 100644 --- a/src/libs/actions/connections/NetSuiteCommands.ts +++ b/src/libs/actions/connections/NetSuiteCommands.ts @@ -439,7 +439,7 @@ function updateNetSuiteExportToNextOpenPeriod(policyID: string, value: boolean, API.write(WRITE_COMMANDS.UPDATE_NETSUITE_EXPORT_TO_NEXT_OPEN_PERIOD, parameters, onyxData); } -function updateNetSuiteAutoSync(policyID: string, value: boolean, oldValue: boolean) { +function updateNetSuiteAutoSync(policyID: string, value: boolean) { const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -473,7 +473,7 @@ function updateNetSuiteAutoSync(policyID: string, value: boolean, oldValue: bool netsuite: { config: { autoSync: { - enabled: oldValue, + enabled: !value, }, pendingFields: { autoSync: null, @@ -519,8 +519,8 @@ function updateNetSuiteAutoSync(policyID: string, value: boolean, oldValue: bool API.write(WRITE_COMMANDS.UPDATE_NETSUITE_AUTO_SYNC, parameters, {optimisticData, failureData, successData}); } -function updateNetSuiteSyncReimbursedReports(policyID: string, value: boolean, oldValue: boolean) { - const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS, value, oldValue); +function updateNetSuiteSyncReimbursedReports(policyID: string, value: boolean) { + const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS, value, !value); const parameters = { policyID, @@ -529,8 +529,8 @@ function updateNetSuiteSyncReimbursedReports(policyID: string, value: boolean, o API.write(WRITE_COMMANDS.UPDATE_NETSUITE_SYNC_REIMBURSED_REPORTS, parameters, onyxData); } -function updateNetSuiteSyncPeople(policyID: string, value: boolean, oldValue: boolean) { - const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_PEOPLE, value, oldValue); +function updateNetSuiteSyncPeople(policyID: string, value: boolean) { + const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_PEOPLE, value, !value); const parameters = { policyID, @@ -539,8 +539,8 @@ function updateNetSuiteSyncPeople(policyID: string, value: boolean, oldValue: bo API.write(WRITE_COMMANDS.UPDATE_NETSUITE_SYNC_PEOPLE, parameters, onyxData); } -function updateNetSuiteAutoCreateEntities(policyID: string, value: boolean, oldValue: boolean) { - const onyxData = updateNetSuiteOnyxData(policyID, CONST.NETSUITE_CONFIG.AUTO_CREATE_ENTITIES, value, oldValue); +function updateNetSuiteAutoCreateEntities(policyID: string, value: boolean) { + const onyxData = updateNetSuiteOnyxData(policyID, CONST.NETSUITE_CONFIG.AUTO_CREATE_ENTITIES, value, !value); const parameters = { policyID, @@ -549,8 +549,8 @@ function updateNetSuiteAutoCreateEntities(policyID: string, value: boolean, oldV API.write(WRITE_COMMANDS.UPDATE_NETSUITE_AUTO_CREATE_ENTITIES, parameters, onyxData); } -function updateNetSuiteEnableNewCategories(policyID: string, value: boolean, oldValue?: boolean) { - const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.ENABLE_NEW_CATEGORIES, value, oldValue); +function updateNetSuiteEnableNewCategories(policyID: string, value: boolean) { + const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.ENABLE_NEW_CATEGORIES, value, !value); const parameters = { policyID, @@ -559,12 +559,12 @@ function updateNetSuiteEnableNewCategories(policyID: string, value: boolean, old API.write(WRITE_COMMANDS.UPDATE_NETSUITE_ENABLE_NEW_CATEGORIES, parameters, onyxData); } -function updateNetSuiteCustomFormIDOptionsEnabled(policyID: string, value: boolean, oldValue?: boolean) { +function updateNetSuiteCustomFormIDOptionsEnabled(policyID: string, value: boolean) { const data = { enabled: value, }; const oldData = { - enabled: oldValue, + enabled: !value, }; const onyxData = updateNetSuiteOnyxData(policyID, CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_OPTIONS, data, oldData); diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index ae8381b746b8..741395555f4a 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -48,7 +48,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.netsuite.advancedConfig.autoSyncDescription'), shouldPlaceSubtitleBelowSwitch: true, onCloseError: () => Policy.clearNetSuiteAutoSyncErrorField(policyID), - onToggle: () => Connections.updateNetSuiteAutoSync(policyID, !autoSyncConfig?.autoSync.enabled, !!autoSyncConfig?.autoSync.enabled), + onToggle: (isEnabled) => Connections.updateNetSuiteAutoSync(policyID, isEnabled), pendingAction: autoSyncConfig?.pendingFields?.autoSync, errors: ErrorUtils.getLatestErrorField(autoSyncConfig, CONST.NETSUITE_CONFIG.AUTO_SYNC), }, @@ -64,7 +64,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.netsuite.advancedConfig.reimbursedReportsDescription'), shouldPlaceSubtitleBelowSwitch: true, onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS), - onToggle: () => Connections.updateNetSuiteSyncReimbursedReports(policyID, !config?.syncOptions.syncReimbursedReports, !!config?.syncOptions.syncReimbursedReports), + onToggle: (isEnabled) => Connections.updateNetSuiteSyncReimbursedReports(policyID, isEnabled), pendingAction: config?.syncOptions.pendingFields?.syncReimbursedReports, errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS), shouldHide: config?.reimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY, @@ -102,7 +102,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { shouldPlaceSubtitleBelowSwitch: true, shouldParseSubtitle: true, onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_PEOPLE), - onToggle: () => Connections.updateNetSuiteSyncPeople(policyID, !config?.syncOptions.syncPeople, !!config?.syncOptions.syncPeople), + onToggle: (isEnabled) => Connections.updateNetSuiteSyncPeople(policyID, isEnabled), pendingAction: config?.syncOptions.pendingFields?.syncPeople, errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_PEOPLE), }, @@ -112,7 +112,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { isActive: !!config?.autoCreateEntities, switchAccessibilityLabel: translate('workspace.netsuite.advancedConfig.autoCreateEntities'), onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.AUTO_CREATE_ENTITIES), - onToggle: () => Connections.updateNetSuiteAutoCreateEntities(policyID, !config?.autoCreateEntities, !!config?.autoCreateEntities), + onToggle: (isEnabled) => Connections.updateNetSuiteAutoCreateEntities(policyID, isEnabled), pendingAction: config?.pendingFields?.autoCreateEntities, errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.AUTO_CREATE_ENTITIES), }, @@ -126,7 +126,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { isActive: !!config?.syncOptions.enableNewCategories, switchAccessibilityLabel: translate('workspace.netsuite.advancedConfig.enableCategories'), onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.ENABLE_NEW_CATEGORIES), - onToggle: () => Connections.updateNetSuiteEnableNewCategories(policyID, !config?.syncOptions.enableNewCategories, config?.syncOptions.enableNewCategories), + onToggle: (isEnabled) => Connections.updateNetSuiteEnableNewCategories(policyID, isEnabled), pendingAction: config?.syncOptions.pendingFields?.enableNewCategories, errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.ENABLE_NEW_CATEGORIES), }, @@ -193,7 +193,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { switchAccessibilityLabel: translate('workspace.netsuite.advancedConfig.customFormIDDescription'), shouldPlaceSubtitleBelowSwitch: true, onCloseError: () => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_OPTIONS), - onToggle: () => Connections.updateNetSuiteCustomFormIDOptionsEnabled(policyID, !config?.customFormIDOptions?.enabled, config?.customFormIDOptions?.enabled), + onToggle: (isEnabled) => Connections.updateNetSuiteCustomFormIDOptionsEnabled(policyID, isEnabled), pendingAction: config?.pendingFields?.customFormIDOptions, errors: ErrorUtils.getLatestErrorField(config, CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_OPTIONS), },