Skip to content

Commit

Permalink
Made code DRY for syncTax
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Jul 3, 2024
1 parent 4bb20b4 commit c816f5a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 79 deletions.
80 changes: 1 addition & 79 deletions src/libs/actions/connections/NetSuiteCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,85 +264,7 @@ function updateNetSuiteSubsidiary(policyID: string, newSubsidiary: SubsidiaryPar
}

function updateNetSuiteSyncTaxConfiguration(policyID: string, isSyncTaxEnabled: boolean) {
const onyxData: OnyxData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
netsuite: {
options: {
config: {
syncOptions: {
syncTax: isSyncTaxEnabled,
},
// TODO: Fixing in the PR for Import Mapping https://github.com/Expensify/App/pull/44743
// pendingFields: {
// syncTax: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
// },
errorFields: {
syncTax: null,
},
},
},
},
},
},
},
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
netsuite: {
options: {
config: {
syncOptions: {
syncTax: isSyncTaxEnabled,
},
// TODO: Fixing in the PR for Import Mapping https://github.com/Expensify/App/pull/44743
// pendingFields: {
// syncTax: null
// },
errorFields: {
syncTax: null,
},
},
},
},
},
},
},
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
connections: {
netsuite: {
options: {
config: {
syncOptions: {
syncTax: !isSyncTaxEnabled,
},
// pendingFields: {
// syncTax: null,
// },
errorFields: {
syncTax: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
},
},
},
},
},
},
},
],
};
const onyxData = updateNetSuiteSyncOptionsOnyxData(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_TAX, isSyncTaxEnabled, !isSyncTaxEnabled);

const params = {
policyID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function NetSuiteImportPage({policy}: WithPolicyConnectionsProps) {
onToggle={(isEnabled: boolean) => {
updateNetSuiteSyncTaxConfiguration(policyID, isEnabled);
}}
pendingAction={config?.syncOptions.pendingFields?.syncTax}
errors={ErrorUtils.getLatestErrorField(config ?? {}, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_TAX)}
onCloseError={() => Policy.clearNetSuiteErrorField(policyID, CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_TAX)}
/>
Expand Down

0 comments on commit c816f5a

Please sign in to comment.