Skip to content

Commit 5ff0dc5

Browse files
committed
fix unreport offline mode
1 parent 00a0b0a commit 5ff0dc5

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

src/libs/actions/Transaction.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -719,19 +719,21 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
719719
const oldReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldReportID}`];
720720

721721
// 1. Optimistically change the reportID on the passed transactions
722+
const targetReportID = reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? selfDMReportID : reportID;
723+
722724
optimisticData.push({
723725
onyxMethod: Onyx.METHOD.MERGE,
724726
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
725727
value: {
726-
reportID,
728+
reportID: targetReportID,
727729
},
728730
});
729731

730732
successData.push({
731733
onyxMethod: Onyx.METHOD.MERGE,
732734
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
733735
value: {
734-
reportID,
736+
reportID: targetReportID,
735737
},
736738
});
737739

@@ -801,7 +803,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
801803
updatedReportTotals[oldReportID] = (updatedReportTotals[oldReportID] ? updatedReportTotals[oldReportID] : (oldReport?.total ?? 0)) + transactionAmount;
802804
}
803805
if (reportID && newReport) {
804-
updatedReportTotals[reportID] = (updatedReportTotals[reportID] ? updatedReportTotals[reportID] : (newReport.total ?? 0)) - transactionAmount;
806+
updatedReportTotals[targetReportID] = (updatedReportTotals[targetReportID] ? updatedReportTotals[targetReportID] : (newReport.total ?? 0)) - transactionAmount;
805807
}
806808

807809
// 4. Optimistically update the IOU action reportID
@@ -818,7 +820,6 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
818820
const trackExpenseActionableWhisper = isUnreported ? getTrackExpenseActionableWhisper(transaction.transactionID, selfDMReportID) : undefined;
819821

820822
if (oldIOUAction) {
821-
const targetReportID = reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? (existingSelfDMReportID ?? selfDMReport.reportID) : reportID;
822823
optimisticData.push({
823824
onyxMethod: Onyx.METHOD.MERGE,
824825
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetReportID}`,
@@ -854,7 +855,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
854855

855856
successData.push({
856857
onyxMethod: Onyx.METHOD.MERGE,
857-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
858+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetReportID}`,
858859
value: {
859860
[newIOUAction.reportActionID]: {pendingAction: null},
860861
},
@@ -863,7 +864,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
863864
failureData.push(
864865
{
865866
onyxMethod: Onyx.METHOD.MERGE,
866-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
867+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetReportID}`,
867868
value: {
868869
[newIOUAction.reportActionID]: null,
869870
},
@@ -884,7 +885,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
884885
onyxMethod: Onyx.METHOD.MERGE,
885886
key: `${ONYXKEYS.COLLECTION.REPORT}${newIOUAction.childReportID}`,
886887
value: {
887-
parentReportID: reportID,
888+
parentReportID: targetReportID,
888889
parentReportActionID: optimisticMoneyRequestReportActionID,
889890
policyID: reportID !== CONST.REPORT.UNREPORTED_REPORT_ID && newReport ? newReport.policyID : CONST.POLICY.ID_FAKE,
890891
},
@@ -906,7 +907,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
906907
let transactionThreadReportID = newIOUAction.childReportID;
907908
let transactionThreadCreatedReportActionID;
908909
if (!transactionThreadReportID) {
909-
const optimisticTransactionThread = buildTransactionThread(newIOUAction, newReport);
910+
const optimisticTransactionThread = buildTransactionThread(newIOUAction, reportID === CONST.REPORT.UNREPORTED_REPORT_ID ? undefined : newReport);
910911
const optimisticCreatedActionForTransactionThread = buildOptimisticCreatedReportAction(currentUserEmail);
911912
transactionThreadReportID = optimisticTransactionThread.reportID;
912913
transactionThreadCreatedReportActionID = optimisticCreatedActionForTransactionThread.reportActionID;
@@ -925,7 +926,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
925926
},
926927
{
927928
onyxMethod: Onyx.METHOD.MERGE,
928-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
929+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetReportID}`,
929930
value: {[newIOUAction.reportActionID]: {childReportID: optimisticTransactionThread.reportID}},
930931
},
931932
);
@@ -956,7 +957,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
956957
},
957958
{
958959
onyxMethod: Onyx.METHOD.MERGE,
959-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
960+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetReportID}`,
960961
value: {[newIOUAction.reportActionID]: {childReportID: null}},
961962
},
962963
);
@@ -965,7 +966,7 @@ function changeTransactionsReport(transactionIDs: string[], reportID: string, po
965966
// 7. Add MOVED_TRANSACTION or UNREPORTED_TRANSACTION report actions
966967
const movedAction =
967968
reportID === CONST.REPORT.UNREPORTED_REPORT_ID
968-
? buildOptimisticUnreportedTransactionAction(transactionThreadReportID, transaction.reportID)
969+
? buildOptimisticUnreportedTransactionAction(transactionThreadReportID, oldReportID)
969970
: buildOptimisticMovedTransactionAction(transactionThreadReportID, reportID);
970971

971972
optimisticData.push({

0 commit comments

Comments
 (0)