Skip to content

Commit 7975501

Browse files
Merge pull request Expensify#71870 from nkdengineer/fix/71379
fix: expense total appears grayed out after editing
2 parents 1d4ac0b + 6daedba commit 7975501

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/libs/TransactionUtils/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,30 @@ function areRequiredFieldsEmpty(transaction: OnyxEntry<Transaction>, reportTrans
448448
return (isMerchantRequired && isMerchantMissing(transaction)) || isAmountMissing(transaction) || isCreatedMissing(transaction);
449449
}
450450

451+
function getClearedPendingFields(transactionChanges: TransactionChanges) {
452+
return {
453+
...Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, null])),
454+
...(Object.hasOwn(transactionChanges, 'comment') && {comment: null}),
455+
...(Object.hasOwn(transactionChanges, 'created') && {created: null}),
456+
...(Object.hasOwn(transactionChanges, 'amount') && {amount: null}),
457+
...(Object.hasOwn(transactionChanges, 'currency') && {currency: null}),
458+
...(Object.hasOwn(transactionChanges, 'merchant') && {merchant: null}),
459+
...(Object.hasOwn(transactionChanges, 'waypoints') && {waypoints: null}),
460+
...(Object.hasOwn(transactionChanges, 'reimbursable') && {reimbursable: null}),
461+
...(Object.hasOwn(transactionChanges, 'billable') && {billable: null}),
462+
...(Object.hasOwn(transactionChanges, 'category') && {category: null}),
463+
...(Object.hasOwn(transactionChanges, 'tag') && {tag: null}),
464+
...(Object.hasOwn(transactionChanges, 'taxAmount') && {taxAmount: null}),
465+
...(Object.hasOwn(transactionChanges, 'taxCode') && {taxCode: null}),
466+
...(Object.hasOwn(transactionChanges, 'attendees') && {attendees: null}),
467+
...(Object.hasOwn(transactionChanges, 'distance') && {
468+
quantity: null,
469+
amount: null,
470+
merchant: null,
471+
}),
472+
};
473+
}
474+
451475
/**
452476
* Given the edit made to the expense, return an updated transaction object.
453477
*/
@@ -1972,6 +1996,7 @@ export {
19721996
getTaxName,
19731997
getEnabledTaxRateCount,
19741998
getUpdatedTransaction,
1999+
getClearedPendingFields,
19752000
getDescription,
19762001
getRequestType,
19772002
getExpenseType,

src/libs/actions/IOU.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ import {
210210
getAmount,
211211
getCategoryTaxCodeAndAmount,
212212
getChildTransactions,
213+
getClearedPendingFields,
213214
getCurrency,
214215
getDistanceInMeters,
215216
getMerchant,
@@ -4232,7 +4233,7 @@ function getUpdateMoneyRequestParams(params: GetUpdateMoneyRequestParamsType): U
42324233

42334234
// Step 1: Set any "pending fields" (ones updated while the user was offline) to have error messages in the failureData
42344235
const pendingFields: OnyxTypes.Transaction['pendingFields'] = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE]));
4235-
const clearedPendingFields = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, null]));
4236+
const clearedPendingFields = getClearedPendingFields(transactionChanges);
42364237
const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}]));
42374238

42384239
// Step 2: Get all the collections being updated
@@ -4693,7 +4694,7 @@ function getUpdateTrackExpenseParams(
46934694

46944695
// Step 1: Set any "pending fields" (ones updated while the user was offline) to have error messages in the failureData
46954696
const pendingFields = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE]));
4696-
const clearedPendingFields = Object.fromEntries(Object.keys(transactionChanges).map((key) => [key, null]));
4697+
const clearedPendingFields = getClearedPendingFields(transactionChanges);
46974698
const errorFields = Object.fromEntries(Object.keys(pendingFields).map((key) => [key, {[DateUtils.getMicroseconds()]: Localize.translateLocal('iou.error.genericEditFailureMessage')}]));
46984699

46994700
// Step 2: Get all the collections being updated

0 commit comments

Comments
 (0)