Skip to content
Closed
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
4 changes: 2 additions & 2 deletions src/hooks/useSelectedTransactionsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
73 changes: 57 additions & 16 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10764,13 +10764,15 @@ function putTransactionsOnHold(transactionsID: string[], comment: string, report

/**
* Remove expense from HOLD
* @param transactionIndex Needed when requests are unheld in bulk. 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[] = [
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
{
Expand Down