Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dismissing the error for corrupted PDF scan request does not delete the expense #43346

Merged
merged 8 commits into from
Jun 21, 2024
16 changes: 16 additions & 0 deletions src/components/ReportActionItem/MoneyRequestView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as CardUtils from '@libs/CardUtils';
import * as CurrencyUtils from '@libs/CurrencyUtils';
import type {MileageRate} from '@libs/DistanceRequestUtils';
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 @@ -276,6 +277,18 @@ function MoneyRequestView({
[transactionAmount, isSettled, isCancelled, isPolicyExpenseChat, isEmptyMerchant, transactionDate, hasErrors, hasViolations, translate, getViolationsForField],
);

const deleteTransaction = useCallback(() => {
if (!parentReportAction) {
return;
}
const iouTransactionID = parentReportAction.actionName === CONST.REPORT.ACTIONS.TYPE.IOU ? parentReportAction.originalMessage?.IOUTransactionID ?? '' : '';
if (ReportActionsUtils.isTrackExpenseAction(parentReportAction)) {
IOU.deleteTrackExpense(parentReport?.reportID ?? '', iouTransactionID, parentReportAction, true);
return;
}
IOU.deleteMoneyRequest(iouTransactionID, parentReportAction, true);
}, [parentReport?.reportID, parentReportAction]);

const distanceRequestFields = canUseP2PDistanceRequests ? (
<>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
Expand Down Expand Up @@ -385,6 +398,9 @@ function MoneyRequestView({
if (!transaction?.transactionID) {
return;
}
if (Object.values(transaction?.errors ?? {})?.find((error) => ErrorUtils.isReceiptError(error))) {
deleteTransaction();
}
Transaction.clearError(transaction.transactionID);
ReportActions.clearAllRelatedReportActionErrors(report.reportID, parentReportAction);
}}
Expand Down
Loading