@@ -52,8 +52,9 @@ import type {ErrorFields, Errors, Icon, PendingAction} from '@src/types/onyx/Ony
52
52
import type { OriginalMessageChangeLog , PaymentMethodType } from '@src/types/onyx/OriginalMessage' ;
53
53
import type { Status } from '@src/types/onyx/PersonalDetails' ;
54
54
import type { ConnectionName } from '@src/types/onyx/Policy' ;
55
- import type { NotificationPreference , Participants , PendingChatMember , Participant as ReportParticipant } from '@src/types/onyx/Report' ;
55
+ import type { NotificationPreference , Participants , Participant as ReportParticipant } from '@src/types/onyx/Report' ;
56
56
import type { Message , OldDotReportAction , ReportActions } from '@src/types/onyx/ReportAction' ;
57
+ import type { PendingChatMember } from '@src/types/onyx/ReportMetadata' ;
57
58
import type { SearchPolicy , SearchReport , SearchTransaction } from '@src/types/onyx/SearchResults' ;
58
59
import type { Comment , TransactionChanges , WaypointCollection } from '@src/types/onyx/Transaction' ;
59
60
import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
@@ -384,6 +385,7 @@ type OptimisticWorkspaceChats = {
384
385
expenseChatData : OptimisticChatReport ;
385
386
expenseReportActionData : Record < string , OptimisticCreatedReportAction > ;
386
387
expenseCreatedReportActionID : string ;
388
+ pendingChatMembers : PendingChatMember [ ] ;
387
389
} ;
388
390
389
391
type OptimisticModifiedExpenseReportAction = Pick <
@@ -701,6 +703,7 @@ Onyx.connect({
701
703
} ) ;
702
704
703
705
let allReportMetadata : OnyxCollection < ReportMetadata > ;
706
+ const allReportMetadataKeyValue : Record < string , ReportMetadata > = { } ;
704
707
Onyx . connect ( {
705
708
key : ONYXKEYS . COLLECTION . REPORT_METADATA ,
706
709
waitForCollectionCallback : true ,
@@ -709,6 +712,15 @@ Onyx.connect({
709
712
return ;
710
713
}
711
714
allReportMetadata = value ;
715
+
716
+ Object . entries ( value ) . forEach ( ( [ reportID , reportMetadata ] ) => {
717
+ if ( ! reportMetadata ) {
718
+ return ;
719
+ }
720
+
721
+ const [ , id ] = reportID . split ( '_' ) ;
722
+ allReportMetadataKeyValue [ id ] = reportMetadata ;
723
+ } ) ;
712
724
} ,
713
725
} ) ;
714
726
@@ -1759,7 +1771,11 @@ function isPayAtEndExpenseReport(reportID: string, transactions: Transaction[] |
1759
1771
/**
1760
1772
* Checks if a report is a transaction thread associated with a report that has only one transaction
1761
1773
*/
1762
- function isOneTransactionThread ( reportID : string , parentReportID : string , threadParentReportAction : OnyxEntry < ReportAction > ) : boolean {
1774
+ function isOneTransactionThread ( reportID : string | undefined , parentReportID : string | undefined , threadParentReportAction : OnyxEntry < ReportAction > ) : boolean {
1775
+ if ( ! reportID || ! parentReportID ) {
1776
+ return false ;
1777
+ }
1778
+
1763
1779
const parentReportActions = allReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ parentReportID } ` ] ?? ( [ ] as ReportAction [ ] ) ;
1764
1780
const transactionThreadReportID = ReportActionsUtils . getOneTransactionThreadReportID ( parentReportID , parentReportActions ) ;
1765
1781
return reportID === transactionThreadReportID && ! ReportActionsUtils . isSentMoneyReportAction ( threadParentReportAction ) ;
@@ -2213,6 +2229,7 @@ function getDisplayNameForParticipant(
2213
2229
2214
2230
function getParticipantsAccountIDsForDisplay ( report : OnyxEntry < Report > , shouldExcludeHidden = false , shouldExcludeDeleted = false , shouldForceExcludeCurrentUser = false ) : number [ ] {
2215
2231
const reportParticipants = report ?. participants ?? { } ;
2232
+ const reportMetadata = getReportMetadata ( report ?. reportID ) ;
2216
2233
let participantsEntries = Object . entries ( reportParticipants ) ;
2217
2234
2218
2235
// We should not show participants that have an optimistic entry with the same login in the personal details
@@ -2252,7 +2269,7 @@ function getParticipantsAccountIDsForDisplay(report: OnyxEntry<Report>, shouldEx
2252
2269
2253
2270
if (
2254
2271
shouldExcludeDeleted &&
2255
- report ?. pendingChatMembers ?. findLast ( ( member ) => Number ( member . accountID ) === accountID ) ?. pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE
2272
+ reportMetadata ?. pendingChatMembers ?. findLast ( ( member ) => Number ( member . accountID ) === accountID ) ?. pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE
2256
2273
) {
2257
2274
return false ;
2258
2275
}
@@ -2313,8 +2330,10 @@ function getGroupChatName(participants?: SelectedParticipant[], shouldApplyLimit
2313
2330
return report . reportName ;
2314
2331
}
2315
2332
2333
+ const reportMetadata = getReportMetadata ( report ?. reportID ) ;
2334
+
2316
2335
const pendingMemberAccountIDs = new Set (
2317
- report ?. pendingChatMembers ?. filter ( ( member ) => member . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) . map ( ( member ) => member . accountID ) ,
2336
+ reportMetadata ?. pendingChatMembers ?. filter ( ( member ) => member . pendingAction === CONST . RED_BRICK_ROAD_PENDING_ACTION . DELETE ) . map ( ( member ) => member . accountID ) ,
2318
2337
) ;
2319
2338
let participantAccountIDs =
2320
2339
participants ?. map ( ( participant ) => participant . accountID ) ??
@@ -3017,7 +3036,11 @@ function getTitleReportField(reportFields: Record<string, PolicyReportField>) {
3017
3036
/**
3018
3037
* Get the key for a report field
3019
3038
*/
3020
- function getReportFieldKey ( reportFieldId : string ) {
3039
+ function getReportFieldKey ( reportFieldId : string | undefined ) {
3040
+ if ( ! reportFieldId ) {
3041
+ return '' ;
3042
+ }
3043
+
3021
3044
// We don't need to add `expensify_` prefix to the title field key, because backend stored title under a unique key `text_title`,
3022
3045
// and all the other report field keys are stored under `expensify_FIELD_ID`.
3023
3046
if ( reportFieldId === CONST . REPORT_FIELD_TITLE_FIELD_ID ) {
@@ -6071,7 +6094,6 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp
6071
6094
false ,
6072
6095
policyName ,
6073
6096
) ,
6074
- pendingChatMembers,
6075
6097
} ;
6076
6098
const adminsChatReportID = adminsChatData . reportID ;
6077
6099
const adminsCreatedAction = buildOptimisticCreatedReportAction ( CONST . POLICY . OWNER_EMAIL_FAKE ) ;
@@ -6111,6 +6133,7 @@ function buildOptimisticWorkspaceChats(policyID: string, policyName: string, exp
6111
6133
expenseChatData,
6112
6134
expenseReportActionData,
6113
6135
expenseCreatedReportActionID : expenseReportCreatedAction . reportActionID ,
6136
+ pendingChatMembers,
6114
6137
} ;
6115
6138
}
6116
6139
@@ -8225,7 +8248,16 @@ function createDraftWorkspaceAndNavigateToConfirmationScreen(transactionID: stri
8225
8248
}
8226
8249
}
8227
8250
8228
- function createDraftTransactionAndNavigateToParticipantSelector ( transactionID : string , reportID : string , actionName : IOUAction , reportActionID : string ) : void {
8251
+ function createDraftTransactionAndNavigateToParticipantSelector (
8252
+ transactionID : string | undefined ,
8253
+ reportID : string | undefined ,
8254
+ actionName : IOUAction ,
8255
+ reportActionID : string | undefined ,
8256
+ ) : void {
8257
+ if ( ! transactionID || ! reportID || ! reportActionID ) {
8258
+ return ;
8259
+ }
8260
+
8229
8261
const transaction = allTransactions ?. [ `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ] ?? ( { } as Transaction ) ;
8230
8262
const reportActions = allReportActions ?. [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS } ${ reportID } ` ] ?? ( [ ] as ReportAction [ ] ) ;
8231
8263
@@ -8538,7 +8570,7 @@ function hasInvoiceReports() {
8538
8570
}
8539
8571
8540
8572
function getReportMetadata ( reportID ?: string ) {
8541
- return allReportMetadata ?. [ ` ${ ONYXKEYS . COLLECTION . REPORT_METADATA } ${ reportID } ` ] ;
8573
+ return allReportMetadataKeyValue [ reportID ?? '-1' ] ;
8542
8574
}
8543
8575
8544
8576
export {
0 commit comments