@@ -1798,6 +1798,8 @@ function openReport(params: OpenReportActionParams) {
17981798
17991799 // If we are creating a new report, we need to add the optimistic report data and a report action
18001800 if ( isCreatingNewReport ) {
1801+ const shouldKeepPersonalDetailsOnFailure = shouldAddPendingFields && ! isNewThread && ! transaction && ! newReportObject . parentReportID ;
1802+
18011803 // Change the method to set for new reports because it doesn't exist yet, is faster,
18021804 // and we need the data to be available when we navigate to the chat page
18031805 const optimisticDataItem = optimisticData . at ( 0 ) ;
@@ -1899,11 +1901,13 @@ function openReport(params: OpenReportActionParams) {
18991901 key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
19001902 value : optimisticPersonalDetails ,
19011903 } ) ;
1902- failureData . push ( {
1903- onyxMethod : Onyx . METHOD . MERGE ,
1904- key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
1905- value : settledPersonalDetails ,
1906- } ) ;
1904+ if ( ! shouldKeepPersonalDetailsOnFailure ) {
1905+ failureData . push ( {
1906+ onyxMethod : Onyx . METHOD . MERGE ,
1907+ key : ONYXKEYS . PERSONAL_DETAILS_LIST ,
1908+ value : settledPersonalDetails ,
1909+ } ) ;
1910+ }
19071911
19081912 if ( ! isNewThread ) {
19091913 failureData . push ( {
@@ -4589,6 +4593,23 @@ function navigateToConciergeChatAndDeleteReport(
45894593 ) ;
45904594}
45914595
4596+ function cleanUpOptimisticPersonalDetailsForFailedChat ( report : OnyxEntry < Report > , currentUserAccountID : number ) {
4597+ const personalDetailsToRemove : PersonalDetailsList = { } ;
4598+
4599+ for ( const accountID of Object . keys ( report ?. participants ?? { } ) . map ( Number ) ) {
4600+ if ( accountID === currentUserAccountID || ! allPersonalDetails ?. [ accountID ] ?. isOptimisticPersonalDetail ) {
4601+ continue ;
4602+ }
4603+ personalDetailsToRemove [ accountID ] = null ;
4604+ }
4605+
4606+ if ( isEmptyObject ( personalDetailsToRemove ) ) {
4607+ return ;
4608+ }
4609+
4610+ Onyx . merge ( ONYXKEYS . PERSONAL_DETAILS_LIST , personalDetailsToRemove ) ;
4611+ }
4612+
45924613function clearCreateChatError (
45934614 report : OnyxEntry < Report > ,
45944615 conciergeReportID : string | undefined ,
@@ -4607,6 +4628,10 @@ function clearCreateChatError(
46074628 return ;
46084629 }
46094630
4631+ if ( report ?. errorFields ?. createChat && isOptimisticReport ) {
4632+ cleanUpOptimisticPersonalDetailsForFailedChat ( report , currentUserAccountID ) ;
4633+ }
4634+
46104635 navigateToConciergeChatAndDeleteReport (
46114636 report ?. reportID ,
46124637 conciergeReportID ,
0 commit comments