Skip to content

Commit

Permalink
Simplified logic
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Jul 4, 2024
1 parent fcf928e commit e508286
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/libs/actions/connections/NetSuiteCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -473,7 +473,7 @@ function updateNetSuiteAutoSync(policyID: string, value: boolean, oldValue: bool
netsuite: {
config: {
autoSync: {
enabled: oldValue,
enabled: !value,
},
pendingFields: {
autoSync: null,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand All @@ -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,
Expand Down Expand Up @@ -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),
},
Expand All @@ -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),
},
Expand All @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down

0 comments on commit e508286

Please sign in to comment.