diff --git a/src/libs/API/parameters/ChangeTransactionsReportParams.ts b/src/libs/API/parameters/ChangeTransactionsReportParams.ts index cffe407df170..df2d4634ff7f 100644 --- a/src/libs/API/parameters/ChangeTransactionsReportParams.ts +++ b/src/libs/API/parameters/ChangeTransactionsReportParams.ts @@ -1,13 +1,15 @@ /** * A map linking the optimistic MOVED_TRANSACTION or UNREPORTED_TRANSACTION reportActionID to the transactionID. * If we're creating the transactionThread as part of moving the transaction, we should also send the optimistic - * transactionThreadReportID and transactionThreadCreatedReportActionID + * transactionThreadReportID and transactionThreadCreatedReportActionID. If the transaction is held before moving to selfDM, + * we should also send the unholdReportActionID. */ type TransactionThreadInfo = { movedReportActionID: string; moneyRequestPreviewReportActionID: string; transactionThreadReportID?: string; transactionThreadCreatedReportActionID?: string; + unholdReportActionID?: string; selfDMReportID?: string; selfDMCreatedReportActionID?: string; }; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index ec31dcf2c150..ff4232f81475 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -112,6 +112,7 @@ import { buildOptimisticReportPreview, buildOptimisticRoomDescriptionUpdatedReportAction, buildOptimisticSelfDMReport, + buildOptimisticUnHoldReportAction, buildOptimisticUnreportedTransactionAction, canUserPerformWriteAction as canUserPerformWriteActionReportUtils, findLastAccessedReport, @@ -158,6 +159,7 @@ import { } from '@libs/ReportUtils'; import shouldSkipDeepLinkNavigation from '@libs/shouldSkipDeepLinkNavigation'; import playSound, {SOUNDS} from '@libs/Sound'; +import {isOnHold} from '@libs/TransactionUtils'; import {addTrailingForwardSlash} from '@libs/Url'; import Visibility from '@libs/Visibility'; import type {FileObject} from '@pages/media/AttachmentModalScreen/types'; @@ -4802,7 +4804,7 @@ function deleteAppReport(reportID: string | undefined) { { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - value: {reportID: CONST.REPORT.UNREPORTED_REPORT_ID}, + value: {reportID: CONST.REPORT.UNREPORTED_REPORT_ID, comment: {hold: null}}, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -4815,7 +4817,7 @@ function deleteAppReport(reportID: string | undefined) { { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`, - value: {reportID: transaction?.reportID}, + value: {reportID: transaction?.reportID, comment: {hold: transaction?.comment?.hold}}, }, { onyxMethod: Onyx.METHOD.MERGE, @@ -4823,6 +4825,32 @@ function deleteAppReport(reportID: string | undefined) { value: transactionViolations, }, ); + + if (isOnHold(transaction)) { + const unHoldAction = buildOptimisticUnHoldReportAction(); + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${childReportID}`, + value: {[unHoldAction.reportActionID]: unHoldAction}, + }); + + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${childReportID}`, + value: {[unHoldAction.reportActionID]: {pendingAction: null}}, + }); + + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${childReportID}`, + value: {[unHoldAction.reportActionID]: null}, + }); + + transactionIDToReportActionAndThreadData[transactionID] = { + ...transactionIDToReportActionAndThreadData[transactionID], + unholdReportActionID: unHoldAction.reportActionID, + }; + } } // 2. Move the report action to self DM @@ -4906,6 +4934,7 @@ function deleteAppReport(reportID: string | undefined) { if (transactionID) { transactionIDToReportActionAndThreadData[transactionID] = { + ...transactionIDToReportActionAndThreadData[transactionID], moneyRequestPreviewReportActionID: newReportActionID, movedReportActionID: unreportedAction?.reportActionID, };