Skip to content

Commit 12dd146

Browse files
committed
Fix - Duplicate Expense Cards Appear in Report When Adding a Single Expense from Empty State
1 parent 6d7eaa6 commit 12dd146

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

src/libs/actions/Transaction.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,23 @@ function changeTransactionsReport(
823823
const oldReportID = isUnreportedExpense ? CONST.REPORT.UNREPORTED_REPORT_ID : transaction.reportID;
824824
const oldReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldReportID}`];
825825

826+
const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
827+
const optimisticMoneyRequestReportActionID = rand64();
828+
829+
const originalMessage = getOriginalMessage(oldIOUAction) as OriginalMessageIOU;
830+
const newIOUAction = {
831+
...oldIOUAction,
832+
originalMessage: {
833+
...originalMessage,
834+
IOUReportID: reportID,
835+
type: isUnreported ? CONST.IOU.REPORT_ACTION_TYPE.TRACK : CONST.IOU.REPORT_ACTION_TYPE.CREATE,
836+
},
837+
reportActionID: optimisticMoneyRequestReportActionID,
838+
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
839+
actionName: oldIOUAction?.actionName ?? CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION,
840+
created: oldIOUAction?.created ?? DateUtils.getDBTime(),
841+
};
842+
826843
// 1. Optimistically change the reportID on the passed transactions
827844
optimisticData.push({
828845
onyxMethod: Onyx.METHOD.MERGE,
@@ -832,6 +849,7 @@ function changeTransactionsReport(
832849
comment: {
833850
hold: null,
834851
},
852+
...(oldIOUAction ? {linkedTrackedExpenseReportAction: newIOUAction} : {}),
835853
},
836854
});
837855

@@ -940,7 +958,6 @@ function changeTransactionsReport(
940958
const allowNegative = shouldEnableNegative(newReport);
941959

942960
// 3. Keep track of the new report totals
943-
const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
944961
const targetReportID = isUnreported ? selfDMReportID : reportID;
945962
const {amount: transactionAmount = 0, currency: transactionCurrency} = getTransactionDetails(transaction, undefined, undefined, allowNegative) ?? {};
946963
const oldReportTotal = oldReport?.total ?? 0;
@@ -974,22 +991,6 @@ function changeTransactionsReport(
974991
}
975992

976993
// 4. Optimistically update the IOU action reportID
977-
const optimisticMoneyRequestReportActionID = rand64();
978-
979-
const originalMessage = getOriginalMessage(oldIOUAction) as OriginalMessageIOU;
980-
const newIOUAction = {
981-
...oldIOUAction,
982-
originalMessage: {
983-
...originalMessage,
984-
IOUReportID: reportID,
985-
type: isUnreported ? CONST.IOU.REPORT_ACTION_TYPE.TRACK : CONST.IOU.REPORT_ACTION_TYPE.CREATE,
986-
},
987-
reportActionID: optimisticMoneyRequestReportActionID,
988-
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
989-
actionName: oldIOUAction?.actionName ?? CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION,
990-
created: oldIOUAction?.created ?? DateUtils.getDBTime(),
991-
};
992-
993994
const trackExpenseActionableWhisper = isUnreportedExpense ? getTrackExpenseActionableWhisper(transaction.transactionID, selfDMReportID) : undefined;
994995

995996
if (oldIOUAction) {

src/pages/home/ReportScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
880880
// - IOU action already exists (not a legacy transaction)
881881
// - Transaction is pending addition (new transaction, not legacy)
882882
const iouAction = getIOUActionForReportID(reportID, transaction.transactionID);
883-
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
883+
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || !!transaction.linkedTrackedExpenseReportAction?.childReportID) {
884884
return;
885885
}
886886

0 commit comments

Comments
 (0)