Skip to content
Merged
Show file tree
Hide file tree
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
35 changes: 18 additions & 17 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import {getCurrentUserAccountID} from './Report';

const allTransactions: OnyxCollection<Transaction> = {};
Onyx.connect({

Check warning on line 56 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
callback: (transaction, key) => {
if (!key || !transaction) {
Expand All @@ -65,7 +65,7 @@
});

let allTransactionDrafts: OnyxCollection<Transaction> = {};
Onyx.connect({

Check warning on line 68 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -74,7 +74,7 @@
});

let allReports: OnyxCollection<Report> = {};
Onyx.connect({

Check warning on line 77 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -86,7 +86,7 @@
});

const allTransactionViolation: OnyxCollection<TransactionViolation[]> = {};
Onyx.connect({

Check warning on line 89 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
callback: (transactionViolation, key) => {
if (!key || !transactionViolation) {
Expand All @@ -98,7 +98,7 @@
});

let allTransactionViolations: TransactionViolations = [];
Onyx.connect({

Check warning on line 101 in src/libs/actions/Transaction.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
callback: (val) => (allTransactionViolations = val ?? []),
});
Expand Down Expand Up @@ -823,6 +823,23 @@
const oldReportID = isUnreportedExpense ? CONST.REPORT.UNREPORTED_REPORT_ID : transaction.reportID;
const oldReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${oldReportID}`];

const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
const optimisticMoneyRequestReportActionID = rand64();

const originalMessage = getOriginalMessage(oldIOUAction) as OriginalMessageIOU;
const newIOUAction = {
...oldIOUAction,
originalMessage: {
...originalMessage,
IOUReportID: reportID,
type: isUnreported ? CONST.IOU.REPORT_ACTION_TYPE.TRACK : CONST.IOU.REPORT_ACTION_TYPE.CREATE,
},
reportActionID: optimisticMoneyRequestReportActionID,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
actionName: oldIOUAction?.actionName ?? CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION,
created: oldIOUAction?.created ?? DateUtils.getDBTime(),
};

// 1. Optimistically change the reportID on the passed transactions
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -832,6 +849,7 @@
comment: {
hold: null,
},
...(oldIOUAction ? {linkedTrackedExpenseReportAction: newIOUAction} : {}),
},
});

Expand Down Expand Up @@ -940,7 +958,6 @@
const allowNegative = shouldEnableNegative(newReport);

// 3. Keep track of the new report totals
const isUnreported = reportID === CONST.REPORT.UNREPORTED_REPORT_ID;
const targetReportID = isUnreported ? selfDMReportID : reportID;
const {amount: transactionAmount = 0, currency: transactionCurrency} = getTransactionDetails(transaction, undefined, undefined, allowNegative) ?? {};
const oldReportTotal = oldReport?.total ?? 0;
Expand Down Expand Up @@ -974,22 +991,6 @@
}

// 4. Optimistically update the IOU action reportID
const optimisticMoneyRequestReportActionID = rand64();

const originalMessage = getOriginalMessage(oldIOUAction) as OriginalMessageIOU;
const newIOUAction = {
...oldIOUAction,
originalMessage: {
...originalMessage,
IOUReportID: reportID,
type: isUnreported ? CONST.IOU.REPORT_ACTION_TYPE.TRACK : CONST.IOU.REPORT_ACTION_TYPE.CREATE,
},
reportActionID: optimisticMoneyRequestReportActionID,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
actionName: oldIOUAction?.actionName ?? CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION,
created: oldIOUAction?.created ?? DateUtils.getDBTime(),
};

const trackExpenseActionableWhisper = isUnreportedExpense ? getTrackExpenseActionableWhisper(transaction.transactionID, selfDMReportID) : undefined;

if (oldIOUAction) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Search/SearchMoneyRequestReportPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function SearchMoneyRequestReportPage({route}: SearchMoneyRequestPageProps) {
}

const iouAction = getIOUActionForTransactionID(reportActions, transaction.transactionID);
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || !!transaction.linkedTrackedExpenseReportAction?.childReportID) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ function ReportScreen({route, navigation}: ReportScreenProps) {
// - IOU action already exists (not a legacy transaction)
// - Transaction is pending addition (new transaction, not legacy)
const iouAction = getIOUActionForReportID(reportID, transaction.transactionID);
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
if (iouAction || transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || !!transaction.linkedTrackedExpenseReportAction?.childReportID) {
return;
}

Expand Down
Loading