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 @@ -23,6 +23,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 @@ -282,6 +283,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 ?? '-1' : '-1';
if (ReportActionsUtils.isTrackExpenseAction(parentReportAction)) {
IOU.deleteTrackExpense(parentReport?.reportID ?? '-1', iouTransactionID, parentReportAction, true);
return;
}
IOU.deleteMoneyRequest(iouTransactionID, parentReportAction, true);
}, [parentReport?.reportID, parentReportAction]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no point in using useCallback here since you are not passing down this function to another component and you are not using it in another function wrapped in useCallback.

Can you instead define this function outside of the component and receive as parameters parentReport and parentReportAction 🙏 ?

Then later you call it with deleteTransaction(parentReport, parentReportAction)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aldo-expensify please check again


const distanceRequestFields = canUseP2PDistanceRequests ? (
<>
<OfflineWithFeedback pendingAction={getPendingFieldAction('waypoints')}>
Expand Down Expand Up @@ -391,6 +404,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