Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8290,6 +8290,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}`,
Expand All @@ -8316,6 +8323,13 @@ function getTaskAssigneeChatOnyxData(
isOptimisticReport: false,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${assigneeChatReportID}`,
value: {
isOptimisticReport: false,
},
},
);

failureData.push(
Expand Down
135 changes: 135 additions & 0 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,8 +1274,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,
Expand Down Expand Up @@ -1703,6 +1730,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}`,
Expand Down Expand Up @@ -1737,6 +1771,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) {
Expand All @@ -1763,6 +1804,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) {
Expand Down Expand Up @@ -2207,6 +2258,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,
Expand All @@ -2231,6 +2291,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)) {
Expand Down Expand Up @@ -2279,6 +2346,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,
Expand Down Expand Up @@ -5503,6 +5579,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,
Expand All @@ -5519,6 +5606,16 @@ function createSplitsAndOnyxData({
},
];

if (!existingSplitChatReport) {
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${splitChatReport.reportID}`,
value: {
isOptimisticReport: false,
},
});
}

const redundantParticipants: Record<number, null> = {};
if (!existingSplitChatReport) {
successData.push({
Expand Down Expand Up @@ -6089,6 +6186,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,
Expand All @@ -6105,6 +6212,16 @@ function startSplitBill({
},
];

if (!existingSplitChatReport) {
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${splitChatReport.reportID}`,
value: {
isOptimisticReport: false,
},
});
}

const redundantParticipants: Record<number, null> = {};
if (!existingSplitChatReport) {
successData.push({
Expand Down Expand Up @@ -7647,6 +7764,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
Expand Down Expand Up @@ -7831,6 +7965,7 @@ function getSendMoneyParams(
optimisticIOUReportActionsData,
optimisticTransactionData,
optimisticTransactionThreadData,
...optimisticMetaData,
];

if (optimisticTransactionThreadReportActionsData) {
Expand Down
26 changes: 26 additions & 0 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2832,6 +2832,17 @@ function navigateToConciergeChatAndDeleteReport(reportID: string | undefined, sh
});
}

function clearCreateChatError(report: OnyxEntry<Report>) {
const metaData = getReportMetadata(report?.reportID);
const isOptimisticReport = 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
Expand Down Expand Up @@ -4390,6 +4401,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}`,
Expand All @@ -4409,6 +4427,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}`,
Expand Down Expand Up @@ -5678,6 +5703,7 @@ export {
navigateToAndOpenReportWithAccountIDs,
navigateToConciergeChat,
navigateToConciergeChatAndDeleteReport,
clearCreateChatError,
notifyNewAction,
openLastOpenedPublicRoom,
openReport,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/report/ReportActionItemCreated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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)}
>
<View style={[styles.pRelative]}>
<AnimatedEmptyStateBackground />
Expand Down
30 changes: 30 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,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<void>((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';
Expand Down