Skip to content

Commit

Permalink
Merge pull request #48734 from bernhardoj/fix/46662-main-chat-isnt-re…
Browse files Browse the repository at this point in the history
…moved-when-dismissing-error

Fix failed to create main chat isn't cleared when dismiss transaction create error
  • Loading branch information
yuwenmemon authored Oct 3, 2024
2 parents 188789a + ed4d341 commit 5e39861
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import useViolations from '@hooks/useViolations';
import type {ViolationField} from '@hooks/useViolations';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
import * as ErrorUtils from '@libs/ErrorUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import {isTaxTrackingEnabled} from '@libs/PolicyUtils';
Expand Down Expand Up @@ -70,18 +69,6 @@ const receiptImageViolationNames: OnyxTypes.ViolationName[] = [

const receiptFieldViolationNames: OnyxTypes.ViolationName[] = [CONST.VIOLATIONS.MODIFIED_AMOUNT, CONST.VIOLATIONS.MODIFIED_DATE];

const deleteTransaction = (parentReport: OnyxEntry<OnyxTypes.Report>, parentReportAction: OnyxEntry<OnyxTypes.ReportAction>) => {
if (!parentReportAction) {
return;
}
const iouTransactionID = ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction)?.IOUTransactionID ?? '-1' : '-1';
if (ReportActionsUtils.isTrackExpenseAction(parentReportAction)) {
IOU.deleteTrackExpense(parentReport?.reportID ?? '-1', iouTransactionID, parentReportAction, true);
return;
}
IOU.deleteMoneyRequest(iouTransactionID, parentReportAction, true);
};

const getTransactionID = (report: OnyxEntry<OnyxTypes.Report>, parentReportActions: OnyxEntry<OnyxTypes.ReportActions>) => {
const parentReportAction = parentReportActions?.[report?.parentReportActionID ?? '-1'];
const originalMessage = parentReportAction && ReportActionsUtils.isMoneyRequestAction(parentReportAction) ? ReportActionsUtils.getOriginalMessage(parentReportAction) : undefined;
Expand Down Expand Up @@ -494,20 +481,15 @@ function MoneyRequestView({report, shouldShowAnimatedBackground, readonly = fals
return;
}

const isCreateChatErrored = !!report?.errorFields?.createChat;
if ((isCreateChatErrored || !!report?.isOptimisticReport) && parentReportAction) {
const urlToNavigateBack = IOU.cleanUpMoneyRequest(transaction?.transactionID ?? linkedTransactionID, parentReportAction, true);
Navigation.goBack(urlToNavigateBack);
return;
}

if (transaction?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD) {
if (chatReport?.reportID && ReportUtils.getAddWorkspaceRoomOrChatReportErrors(chatReport)) {
Report.navigateToConciergeChatAndDeleteReport(chatReport.reportID, true, true);
return;
}
if (Object.values(transaction?.errors ?? {})?.find((error) => ErrorUtils.isReceiptError(error))) {
deleteTransaction(parentReport, parentReportAction);
if (parentReportAction) {
const urlToNavigateBack = IOU.cleanUpMoneyRequest(transaction?.transactionID ?? linkedTransactionID, parentReportAction, true);
Navigation.goBack(urlToNavigateBack);
return;
}
}
Transaction.clearError(transaction?.transactionID ?? linkedTransactionID);
Expand Down

0 comments on commit 5e39861

Please sign in to comment.