@@ -611,7 +611,7 @@ type OptimisticModifiedExpenseReportAction = Pick<
611
611
| 'delegateAccountID'
612
612
> & { reportID ?: string } ;
613
613
614
- type OptimisticMoneyRequestEntities = {
614
+ type BaseOptimisticMoneyRequestEntities = {
615
615
iouReport : Report ;
616
616
type : ValueOf < typeof CONST . IOU . REPORT_ACTION_TYPE > ;
617
617
amount : number ;
@@ -629,6 +629,10 @@ type OptimisticMoneyRequestEntities = {
629
629
linkedTrackedExpenseReportAction ?: ReportAction ;
630
630
} ;
631
631
632
+ type OptimisticMoneyRequestEntities = BaseOptimisticMoneyRequestEntities & { shouldGenerateOptimisticTransactionThread ?: boolean } ;
633
+ type OptimisticMoneyRequestEntitiesWithTransactionThreadFlag = BaseOptimisticMoneyRequestEntities & { shouldGenerateOptimisticTransactionThread : boolean } ;
634
+ type OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag = BaseOptimisticMoneyRequestEntities ;
635
+
632
636
type OptimisticTaskReport = SetRequired <
633
637
Pick <
634
638
Report ,
@@ -3996,16 +4000,16 @@ const changeMoneyRequestHoldStatus = (reportAction: OnyxEntry<ReportAction>, sea
3996
4000
3997
4001
const transactionID = getOriginalMessage ( reportAction ) ?. IOUTransactionID ;
3998
4002
3999
- if ( ! transactionID || ! reportAction . childReportID ) {
4000
- Log . warn ( 'Missing transactionID and reportAction.childReportID during the change of the money request hold status' ) ;
4003
+ if ( ! transactionID ) {
4004
+ Log . warn ( 'Missing transactionID during the change of the money request hold status' ) ;
4001
4005
return ;
4002
4006
}
4003
4007
4004
4008
const transaction = allTransactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ] ?? ( { } as Transaction ) ;
4005
4009
const isOnHold = isOnHoldTransactionUtils ( transaction ) ;
4006
4010
const policy = allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ moneyRequestReport . policyID } ` ] ?? null ;
4007
4011
4008
- if ( isOnHold ) {
4012
+ if ( isOnHold && reportAction . childReportID ) {
4009
4013
unholdRequest ( transactionID , reportAction . childReportID , searchHash ) ;
4010
4014
} else {
4011
4015
const activeRoute = encodeURIComponent ( Navigation . getActiveRoute ( ) ) ;
@@ -7346,6 +7350,7 @@ function buildTransactionThread(
7346
7350
reportAction : OnyxEntry < ReportAction | OptimisticIOUReportAction > ,
7347
7351
moneyRequestReport : OnyxEntry < Report > ,
7348
7352
existingTransactionThreadReportID ?: string ,
7353
+ optimisticTransactionThreadReportID ?: string ,
7349
7354
) : OptimisticChatReport {
7350
7355
const participantAccountIDs = [ ...new Set ( [ currentUserAccountID , Number ( reportAction ?. actorAccountID ) ] ) ] . filter ( Boolean ) as number [ ] ;
7351
7356
const existingTransactionThreadReport = getReportOrDraftReport ( existingTransactionThreadReportID ) ;
@@ -7368,6 +7373,7 @@ function buildTransactionThread(
7368
7373
notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . HIDDEN ,
7369
7374
parentReportActionID : reportAction ?. reportActionID ,
7370
7375
parentReportID : moneyRequestReport ?. reportID ,
7376
+ optimisticReportID : optimisticTransactionThreadReportID ,
7371
7377
} ) ;
7372
7378
}
7373
7379
@@ -7380,6 +7386,12 @@ function buildTransactionThread(
7380
7386
* 4. Transaction Thread linked to the IOU action via `parentReportActionID`
7381
7387
* 5. CREATED action for the Transaction Thread
7382
7388
*/
7389
+ function buildOptimisticMoneyRequestEntities (
7390
+ optimisticMoneyRequestEntities : OptimisticMoneyRequestEntitiesWithoutTransactionThreadFlag ,
7391
+ ) : [ OptimisticCreatedReportAction , OptimisticCreatedReportAction , OptimisticIOUReportAction , OptimisticChatReport , OptimisticCreatedReportAction | null ] ;
7392
+ function buildOptimisticMoneyRequestEntities (
7393
+ optimisticMoneyRequestEntities : OptimisticMoneyRequestEntitiesWithTransactionThreadFlag ,
7394
+ ) : [ OptimisticCreatedReportAction , OptimisticCreatedReportAction , OptimisticIOUReportAction , OptimisticChatReport | undefined , OptimisticCreatedReportAction | null ] ;
7383
7395
function buildOptimisticMoneyRequestEntities ( {
7384
7396
iouReport,
7385
7397
type,
@@ -7393,10 +7405,17 @@ function buildOptimisticMoneyRequestEntities({
7393
7405
isSettlingUp = false ,
7394
7406
isSendMoneyFlow = false ,
7395
7407
isOwnPolicyExpenseChat = false ,
7408
+ shouldGenerateOptimisticTransactionThread = true ,
7396
7409
isPersonalTrackingExpense,
7397
7410
existingTransactionThreadReportID,
7398
7411
linkedTrackedExpenseReportAction,
7399
- } : OptimisticMoneyRequestEntities ) : [ OptimisticCreatedReportAction , OptimisticCreatedReportAction , OptimisticIOUReportAction , OptimisticChatReport , OptimisticCreatedReportAction | null ] {
7412
+ } : OptimisticMoneyRequestEntities ) : [
7413
+ OptimisticCreatedReportAction ,
7414
+ OptimisticCreatedReportAction ,
7415
+ OptimisticIOUReportAction ,
7416
+ OptimisticChatReport | undefined ,
7417
+ OptimisticCreatedReportAction | null ,
7418
+ ] {
7400
7419
const createdActionForChat = buildOptimisticCreatedReportAction ( payeeEmail ) ;
7401
7420
7402
7421
// The `CREATED` action must be optimistically generated before the IOU action so that it won't appear after the IOU action in the chat.
@@ -7421,11 +7440,11 @@ function buildOptimisticMoneyRequestEntities({
7421
7440
} ) ;
7422
7441
7423
7442
// Create optimistic transactionThread and the `CREATED` action for it, if existingTransactionThreadReportID is undefined
7424
- const transactionThread = buildTransactionThread ( iouAction , iouReport , existingTransactionThreadReportID ) ;
7425
- const createdActionForTransactionThread = existingTransactionThreadReportID ? null : buildOptimisticCreatedReportAction ( payeeEmail ) ;
7443
+ const transactionThread = shouldGenerateOptimisticTransactionThread ? buildTransactionThread ( iouAction , iouReport , existingTransactionThreadReportID ) : undefined ;
7444
+ const createdActionForTransactionThread = ! ! existingTransactionThreadReportID || ! shouldGenerateOptimisticTransactionThread ? null : buildOptimisticCreatedReportAction ( payeeEmail ) ;
7426
7445
7427
7446
// The IOU action and the transactionThread are co-dependent as parent-child, so we need to link them together
7428
- iouAction . childReportID = existingTransactionThreadReportID ?? transactionThread . reportID ;
7447
+ iouAction . childReportID = existingTransactionThreadReportID ?? transactionThread ? .reportID ;
7429
7448
7430
7449
return [ createdActionForChat , createdActionForIOUReport , iouAction , transactionThread , createdActionForTransactionThread ] ;
7431
7450
}
@@ -9214,12 +9233,12 @@ function getAllAncestorReportActionIDs(report: Report | null | undefined, includ
9214
9233
9215
9234
/**
9216
9235
* Get optimistic data of parent report action
9217
- * @param reportID The reportID of the report that is updated
9236
+ * @param reportOrID The reportID of the report that is updated or the optimistic report on its own
9218
9237
* @param lastVisibleActionCreated Last visible action created of the child report
9219
9238
* @param type The type of action in the child report
9220
9239
*/
9221
- function getOptimisticDataForParentReportAction ( reportID : string | undefined , lastVisibleActionCreated : string , type : string ) : Array < OnyxUpdate | null > {
9222
- const report = getReportOrDraftReport ( reportID ) ;
9240
+ function getOptimisticDataForParentReportAction ( reportOrID : Report | string | undefined , lastVisibleActionCreated : string , type : string ) : Array < OnyxUpdate | null > {
9241
+ const report = typeof reportOrID === 'string' ? getReportOrDraftReport ( reportOrID ) : reportOrID ;
9223
9242
9224
9243
if ( ! report || isEmptyObject ( report ) ) {
9225
9244
return [ ] ;
0 commit comments