Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 14 additions & 38 deletions src/libs/actions/Policy/DistanceRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,29 +398,19 @@ function deletePolicyDistanceRates(
transactionViolations: OnyxCollection<TransactionViolation[]>,
) {
const currentRates = customUnit.rates;
const optimisticRates: Record<string, Rate> = {};
const successRates: Record<string, Rate> = {};
const failureRates: Record<string, Rate> = {};

for (const rateID of Object.keys(currentRates)) {
if (rateIDsToDelete.includes(rateID)) {
optimisticRates[rateID] = {
...currentRates[rateID],
enabled: false,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
};
failureRates[rateID] = {
...currentRates[rateID],
pendingAction: null,
errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
};
} else {
optimisticRates[rateID] = currentRates[rateID];
successRates[rateID] = {
...currentRates[rateID],
pendingAction: null,
};
}
const optimisticRates: Record<string, Partial<Rate>> = {};
const failureRates: Record<string, Partial<Rate>> = {};

for (const rateID of rateIDsToDelete) {
optimisticRates[rateID] = {
enabled: false,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
};
failureRates[rateID] = {
enabled: currentRates[rateID].enabled,
pendingAction: null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reset enabled field?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. Updated!

errors: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage'),
};
}

const optimisticData: OnyxUpdate[] = [
Expand All @@ -437,20 +427,6 @@ function deletePolicyDistanceRates(
},
];

const successData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
customUnits: {
[customUnit.customUnitID]: {
rates: successRates,
},
},
},
},
];

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand Down Expand Up @@ -503,7 +479,7 @@ function deletePolicyDistanceRates(
customUnitRateID: rateIDsToDelete,
};

API.write(WRITE_COMMANDS.DELETE_POLICY_DISTANCE_RATES, params, {optimisticData, successData, failureData});
API.write(WRITE_COMMANDS.DELETE_POLICY_DISTANCE_RATES, params, {optimisticData, failureData});
}

function updateDistanceTaxClaimableValue(policyID: string, customUnit: CustomUnit, customUnitRates: Rate[]) {
Expand Down
Loading