From ab4a38d1910d73a699b85aeacd430f9e10092a9b Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 18 Mar 2025 15:30:13 +0300 Subject: [PATCH 1/3] implemented clearing createChat error --- src/libs/actions/Report.ts | 13 ++++++++ .../home/report/ReportActionItemCreated.tsx | 4 +-- tests/actions/ReportTest.ts | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 660926815b25..71324535e956 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2716,6 +2716,18 @@ function navigateToConciergeChatAndDeleteReport(reportID: string | undefined, sh }); } +function clearCreateChatError(report: OnyxEntry) { + const metaData = getReportMetadata(report?.reportID); + // If the meta data do not exist we assume the report is optimistic so that + // we don't avoid deletion of the report because of lack of meta data information. + const isOptimisticReport = !metaData || metaData.isOptimisticReport; + if (report?.errorFields?.createChat && !isOptimisticReport) { + clearReportFieldKeyErrors(report.reportID, 'createChat'); + return; + } + navigateToConciergeChatAndDeleteReport(report?.reportID, undefined, true); +} + /** * @param policyRoomReport The policy room report * @param policyRoomName The updated name for the policy room @@ -5122,6 +5134,7 @@ export { navigateToAndOpenReportWithAccountIDs, navigateToConciergeChat, navigateToConciergeChatAndDeleteReport, + clearCreateChatError, notifyNewAction, openLastOpenedPublicRoom, openReport, diff --git a/src/pages/home/report/ReportActionItemCreated.tsx b/src/pages/home/report/ReportActionItemCreated.tsx index b5584c00087b..d55c04359589 100644 --- a/src/pages/home/report/ReportActionItemCreated.tsx +++ b/src/pages/home/report/ReportActionItemCreated.tsx @@ -10,7 +10,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; import {getIcons, isChatReport, isCurrentUserInvoiceReceiver, isInvoiceRoom, navigateToDetailsPage, shouldDisableDetailPage as shouldDisableDetailPageReportUtils} from '@libs/ReportUtils'; -import {navigateToConciergeChatAndDeleteReport} from '@userActions/Report'; +import {clearCreateChatError} from '@userActions/Report'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground'; @@ -49,7 +49,7 @@ function ReportActionItemCreated({reportID, policyID}: ReportActionItemCreatedPr pendingAction={report?.pendingFields?.addWorkspaceRoom ?? report?.pendingFields?.createChat} errors={report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat} errorRowStyles={[styles.ml10, styles.mr2]} - onClose={() => navigateToConciergeChatAndDeleteReport(report?.reportID ?? reportID, undefined, true)} + onClose={() => clearCreateChatError(report)} > diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index d18213bd8f54..48bccb0dbf74 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -164,6 +164,36 @@ describe('actions/Report', () => { }); }); + it('clearCreateChatError should not delete the report if it is not optimistic report', () => { + const REPORT: OnyxTypes.Report = {...createRandomReport(1), errorFields: {createChat: {error: 'error'}}}; + const REPORT_METADATA: OnyxTypes.ReportMetadata = {isOptimisticReport: false}; + + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${REPORT.reportID}`, REPORT); + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${REPORT.reportID}`, REPORT_METADATA); + + return waitForBatchedUpdates() + .then(() => { + Report.clearCreateChatError(REPORT); + return waitForBatchedUpdates(); + }) + .then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT}${REPORT.reportID}`, + callback: (report) => { + Onyx.disconnect(connection); + resolve(); + + // The report should exist but the create chat error field should be cleared. + expect(report?.reportID).toBeDefined(); + expect(report?.errorFields?.createChat).toBeUndefined(); + }, + }); + }), + ); + }); + it('should update pins in Onyx when togglePinned is called', () => { const TEST_USER_ACCOUNT_ID = 1; const TEST_USER_LOGIN = 'test@test.com'; From 2685117ef41fdb0f618e2a0d3259ec5df592e84f Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 18 Mar 2025 16:53:42 +0300 Subject: [PATCH 2/3] add missing meta data --- src/libs/ReportUtils.ts | 14 ++++ src/libs/actions/IOU.ts | 135 +++++++++++++++++++++++++++++++++++++ src/libs/actions/Report.ts | 14 ++++ 3 files changed, 163 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c847a92554a5..c28525fef4b0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -8184,6 +8184,13 @@ function getTaskAssigneeChatOnyxData( }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${assigneeChatReportID}`, + value: { + isOptimisticReport: true, + }, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${assigneeChatReportID}`, @@ -8210,6 +8217,13 @@ function getTaskAssigneeChatOnyxData( isOptimisticReport: false, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${assigneeChatReportID}`, + value: { + isOptimisticReport: false, + }, + }, ); failureData.push( diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 29af8d20a820..6c490c6ce56c 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1202,8 +1202,35 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionThreadReport?.reportID}`, + value: { + isOptimisticReport: true, + }, + }, ); + if (isNewChatReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chat.report?.reportID}`, + value: { + isOptimisticReport: true, + }, + }); + } + + if (shouldCreateNewMoneyRequestReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${iou.report?.reportID}`, + value: { + isOptimisticReport: true, + }, + }); + } + if (!isEmptyObject(transactionThreadCreatedReportAction)) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -1610,6 +1637,13 @@ function buildOnyxDataForInvoice(invoiceParams: BuildOnyxDataForInvoiceParams): }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${iou.report?.reportID}`, + value: { + isOptimisticReport: true, + }, + }, { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transactionParams.transaction.transactionID}`, @@ -1644,6 +1678,13 @@ function buildOnyxDataForInvoice(invoiceParams: BuildOnyxDataForInvoiceParams): key: `${ONYXKEYS.COLLECTION.REPORT}${transactionParams.threadReport.reportID}`, value: transactionParams.threadReport, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionParams.threadReport?.reportID}`, + value: { + isOptimisticReport: true, + }, + }, ]; if (transactionParams.threadCreatedReportAction?.reportActionID) { @@ -1670,6 +1711,16 @@ function buildOnyxDataForInvoice(invoiceParams: BuildOnyxDataForInvoiceParams): ...(chat.isNewReport ? {pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}} : {}), }, }); + + if (chat.isNewReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chat.report?.reportID}`, + value: { + isOptimisticReport: true, + }, + }); + } } if (optimisticDataParams.policyRecentlyUsedCategories.length) { @@ -2112,6 +2163,15 @@ function buildOnyxDataForTrackExpense({ }, }, ); + if (shouldCreateNewMoneyRequestReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${iouReport.reportID}`, + value: { + isOptimisticReport: true, + }, + }); + } } else { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -2136,6 +2196,13 @@ function buildOnyxDataForTrackExpense({ pendingFields: {createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD}, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionThreadReport?.reportID}`, + value: { + isOptimisticReport: true, + }, + }, ); if (!isEmptyObject(transactionThreadCreatedReportAction)) { @@ -2184,6 +2251,15 @@ function buildOnyxDataForTrackExpense({ }, }, ); + if (shouldCreateNewMoneyRequestReport) { + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${iouReport.reportID}`, + value: { + isOptimisticReport: false, + }, + }); + } } else { successData.push({ onyxMethod: Onyx.METHOD.MERGE, @@ -5334,6 +5410,17 @@ function createSplitsAndOnyxData({ value: splitTransaction, }, ]; + + if (!existingSplitChatReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${splitChatReport.reportID}`, + value: { + isOptimisticReport: true, + }, + }); + } + const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -5350,6 +5437,16 @@ function createSplitsAndOnyxData({ }, ]; + if (!existingSplitChatReport) { + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${splitChatReport.reportID}`, + value: { + isOptimisticReport: false, + }, + }); + } + const redundantParticipants: Record = {}; if (!existingSplitChatReport) { successData.push({ @@ -5929,6 +6026,16 @@ function startSplitBill({ }, ]; + if (!existingSplitChatReport) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${splitChatReport.reportID}`, + value: { + isOptimisticReport: true, + }, + }); + } + const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -5945,6 +6052,16 @@ function startSplitBill({ }, ]; + if (!existingSplitChatReport) { + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${splitChatReport.reportID}`, + value: { + isOptimisticReport: false, + }, + }); + } + const redundantParticipants: Record = {}; if (!existingSplitChatReport) { successData.push({ @@ -7472,6 +7589,23 @@ function getSendMoneyParams( } : undefined; + const optimisticMetaData: OnyxUpdate[] = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${chatReport.reportID}`, + value: { + isOptimisticReport: true, + }, + }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${optimisticTransactionThread.reportID}`, + value: { + isOptimisticReport: true, + }, + }, + ]; + const successData: OnyxUpdate[] = []; // Add optimistic personal details for recipient @@ -7656,6 +7790,7 @@ function getSendMoneyParams( optimisticIOUReportActionsData, optimisticTransactionData, optimisticTransactionThreadData, + ...optimisticMetaData, ]; if (optimisticTransactionThreadReportActionsData) { diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 71324535e956..0b0e1730540e 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4294,6 +4294,13 @@ function prepareOnboardingOnyxData( }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${selfDMReport.reportID}`, + value: { + isOptimisticReport: true, + }, + }, { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`, @@ -4313,6 +4320,13 @@ function prepareOnboardingOnyxData( }, }, }, + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${selfDMReport.reportID}`, + value: { + isOptimisticReport: false, + }, + }, { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`, From 1ab65ac58513573debaa7029e1a974d0ba0af80b Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 18 Mar 2025 17:07:44 +0300 Subject: [PATCH 3/3] minor update --- src/libs/actions/Report.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 0b0e1730540e..651b8cae5015 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2718,13 +2718,12 @@ function navigateToConciergeChatAndDeleteReport(reportID: string | undefined, sh function clearCreateChatError(report: OnyxEntry) { const metaData = getReportMetadata(report?.reportID); - // If the meta data do not exist we assume the report is optimistic so that - // we don't avoid deletion of the report because of lack of meta data information. - const isOptimisticReport = !metaData || metaData.isOptimisticReport; + const isOptimisticReport = metaData?.isOptimisticReport; if (report?.errorFields?.createChat && !isOptimisticReport) { clearReportFieldKeyErrors(report.reportID, 'createChat'); return; } + navigateToConciergeChatAndDeleteReport(report?.reportID, undefined, true); }