From f18d630662c17ddd147c9604b0beaefe8ca74cbb Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 17 Jun 2025 22:33:59 +0300 Subject: [PATCH 1/2] adding unhold report action --- src/hooks/useSelectedTransactionsActions.ts | 4 +- src/libs/actions/IOU.ts | 73 ++++++++++++++++----- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/hooks/useSelectedTransactionsActions.ts b/src/hooks/useSelectedTransactionsActions.ts index f73dcb4a97d0..97d707d2852a 100644 --- a/src/hooks/useSelectedTransactionsActions.ts +++ b/src/hooks/useSelectedTransactionsActions.ts @@ -145,12 +145,12 @@ function useSelectedTransactionsActions({ icon: Expensicons.Stopwatch, value: UNHOLD, onSelected: () => { - selectedTransactionIDs.forEach((transactionID) => { + selectedTransactionIDs.forEach((transactionID, transactionIndex) => { const action = getIOUActionForTransactionID(reportActions, transactionID); if (!action?.childReportID) { return; } - unholdRequest(transactionID, action?.childReportID); + unholdRequest(transactionID, action?.childReportID, transactionIndex); }); clearSelectedTransactions(true); }, diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index c27b18edec5c..770268a37584 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -10764,13 +10764,15 @@ function putTransactionsOnHold(transactionsID: string[], comment: string, report /** * Remove expense from HOLD + * @param transactionIndex Needed when unholding requests in bulk to only create one report action for the IOU. See unhold option in useSelectedTransactionsActions.ts + * */ -function unholdRequest(transactionID: string, reportID: string) { - const createdReportAction = buildOptimisticUnHoldReportAction(); +function unholdRequest(transactionID: string, reportID: string, transactionIndex = 0) { const transactionViolations = allTransactionViolations[`${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transactionID}`]; const transaction = allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`]; const iouReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${transaction?.reportID}`]; const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const createdReportAction = buildOptimisticUnHoldReportAction(); const optimisticData: OnyxUpdate[] = [ { @@ -10804,20 +10806,6 @@ function unholdRequest(transactionID: string, reportID: string) { }, ]; - if (iouReport && iouReport.currency === transaction?.currency) { - const isExpenseReportLocal = isExpenseReport(iouReport); - const coefficient = isExpenseReportLocal ? -1 : 1; - const transactionAmount = getAmount(transaction, isExpenseReportLocal) * coefficient; - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, - value: { - unheldTotal: (iouReport.unheldTotal ?? 0) + transactionAmount, - unheldNonReimbursableTotal: !transaction?.reimbursable ? (iouReport.unheldNonReimbursableTotal ?? 0) + transactionAmount : iouReport.unheldNonReimbursableTotal, - }, - }); - } - const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -10861,6 +10849,59 @@ function unholdRequest(transactionID: string, reportID: string) { }, ]; + if (iouReport) { + if (iouReport.currency === transaction?.currency) { + const isExpenseReportLocal = isExpenseReport(iouReport); + const coefficient = isExpenseReportLocal ? -1 : 1; + const transactionAmount = getAmount(transaction, isExpenseReportLocal) * coefficient; + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + unheldTotal: (iouReport.unheldTotal ?? 0) + transactionAmount, + unheldNonReimbursableTotal: !transaction?.reimbursable ? (iouReport.unheldNonReimbursableTotal ?? 0) + transactionAmount : iouReport.unheldNonReimbursableTotal, + }, + }); + } + + if (transactionIndex == 0 && iouReport.reportID !== reportID) { + const unHoldActionForIOUReport = buildOptimisticUnHoldReportAction(); + optimisticData.push( + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + value: { + [unHoldActionForIOUReport.reportActionID]: unHoldActionForIOUReport, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + lastVisibleActionCreated: unHoldActionForIOUReport.created, + }, + }, + ); + + failureData.push( + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`, + value: { + [unHoldActionForIOUReport.reportActionID]: null, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`, + value: { + lastVisibleActionCreated: iouReport?.lastVisibleActionCreated, + }, + }, + ); + } + } + API.write( 'UnHoldRequest', { From b70ae78653f89043c87543244d3cd8b001428791 Mon Sep 17 00:00:00 2001 From: Antony Kithinzi Date: Tue, 17 Jun 2025 23:36:11 +0300 Subject: [PATCH 2/2] lint and spelling --- src/libs/actions/IOU.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 770268a37584..bfb13b7025b4 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -10764,7 +10764,7 @@ function putTransactionsOnHold(transactionsID: string[], comment: string, report /** * Remove expense from HOLD - * @param transactionIndex Needed when unholding requests in bulk to only create one report action for the IOU. See unhold option in useSelectedTransactionsActions.ts + * @param transactionIndex Needed when requests are unheld in bulk. See unhold option in useSelectedTransactionsActions.ts * */ function unholdRequest(transactionID: string, reportID: string, transactionIndex = 0) { @@ -10864,7 +10864,7 @@ function unholdRequest(transactionID: string, reportID: string, transactionIndex }); } - if (transactionIndex == 0 && iouReport.reportID !== reportID) { + if (transactionIndex === 0 && iouReport.reportID !== reportID) { const unHoldActionForIOUReport = buildOptimisticUnHoldReportAction(); optimisticData.push( {