Skip to content

Commit 2b07d49

Browse files
committed
fix: preserve participant email after failed chat creation
1 parent f1cb80b commit 2b07d49

1 file changed

Lines changed: 44 additions & 18 deletions

File tree

src/libs/actions/Report/index.ts

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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,29 +1901,32 @@ 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-
});
1907-
1908-
if (!isNewThread) {
1904+
if (!shouldKeepPersonalDetailsOnFailure) {
19091905
failureData.push({
19101906
onyxMethod: Onyx.METHOD.MERGE,
1911-
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1912-
value: {
1913-
errorFields: {
1914-
createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'),
1915-
},
1916-
},
1907+
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
1908+
value: settledPersonalDetails,
19171909
});
19181910
}
19191911

1920-
failureData.push({
1921-
onyxMethod: Onyx.METHOD.MERGE,
1922-
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
1923-
value: {[optimisticCreatedAction.reportActionID]: {pendingAction: null}},
1924-
});
1912+
if (shouldKeepPersonalDetailsOnFailure) {
1913+
failureData.push(
1914+
{
1915+
onyxMethod: Onyx.METHOD.MERGE,
1916+
key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
1917+
value: {
1918+
errorFields: {
1919+
createChat: getMicroSecondOnyxErrorWithTranslationKey('report.genericCreateReportFailureMessage'),
1920+
},
1921+
},
1922+
},
1923+
{
1924+
onyxMethod: Onyx.METHOD.MERGE,
1925+
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
1926+
value: {[optimisticCreatedAction.reportActionID]: {pendingAction: null}},
1927+
},
1928+
);
1929+
}
19251930

19261931
// Add the createdReportActionID parameter to the API call
19271932
parameters.createdReportActionID = optimisticCreatedAction.reportActionID;
@@ -4585,6 +4590,23 @@ function navigateToConciergeChatAndDeleteReport(
45854590
);
45864591
}
45874592

4593+
function cleanUpOptimisticPersonalDetailsForFailedChat(report: OnyxEntry<Report>, currentUserAccountID: number) {
4594+
const personalDetailsToRemove: PersonalDetailsList = {};
4595+
4596+
for (const accountID of Object.keys(report?.participants ?? {}).map(Number)) {
4597+
if (accountID === currentUserAccountID || !allPersonalDetails?.[accountID]?.isOptimisticPersonalDetail) {
4598+
continue;
4599+
}
4600+
personalDetailsToRemove[accountID] = null;
4601+
}
4602+
4603+
if (isEmptyObject(personalDetailsToRemove)) {
4604+
return;
4605+
}
4606+
4607+
Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, personalDetailsToRemove);
4608+
}
4609+
45884610
function clearCreateChatError(
45894611
report: OnyxEntry<Report>,
45904612
conciergeReportID: string | undefined,
@@ -4603,6 +4625,10 @@ function clearCreateChatError(
46034625
return;
46044626
}
46054627

4628+
if (report?.errorFields?.createChat && isOptimisticReport) {
4629+
cleanUpOptimisticPersonalDetailsForFailedChat(report, currentUserAccountID);
4630+
}
4631+
46064632
navigateToConciergeChatAndDeleteReport(
46074633
report?.reportID,
46084634
conciergeReportID,

0 commit comments

Comments
 (0)