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 inconsistency in dismissing report details RHP when deleting expense with comments #44777

24 changes: 20 additions & 4 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 637,9 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
</OfflineWithFeedback>
);

// A flag to indicate whether the user choose to delete the transaction or not
const isTransactionDeleted = useRef<boolean>(false);
// Where to go back after deleting the transaction and its report. It's empty if the transaction report isn't deleted.
const navigateBackToAfterDelete = useRef<Route>();

const deleteTransaction = useCallback(() => {
Expand All @@ -653,11 656,13 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
}

if (ReportActionsUtils.isTrackExpenseAction(requestParentReportAction)) {
navigateBackToAfterDelete.current = IOU.deleteTrackExpense(moneyRequestReport?.reportID ?? '', iouTransactionID, requestParentReportAction, true);
navigateBackToAfterDelete.current = IOU.deleteTrackExpense(moneyRequestReport?.reportID ?? '', iouTransactionID, requestParentReportAction, isSingleTransactionView);
} else {
navigateBackToAfterDelete.current = IOU.deleteMoneyRequest(iouTransactionID, requestParentReportAction, true);
navigateBackToAfterDelete.current = IOU.deleteMoneyRequest(iouTransactionID, requestParentReportAction, isSingleTransactionView);
}
}, [caseID, iouTransactionID, moneyRequestReport?.reportID, report, requestParentReportAction]);

isTransactionDeleted.current = true;
}, [caseID, iouTransactionID, moneyRequestReport?.reportID, report, requestParentReportAction, isSingleTransactionView]);
return (
<ScreenWrapper testID={ReportDetailsPage.displayName}>
<FullPageNotFoundView shouldShow={isEmptyObject(report)}>
Expand Down Expand Up @@ -746,7 751,18 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
isVisible={isDeleteModalVisible}
onConfirm={deleteTransaction}
onCancel={() => setIsDeleteModalVisible(false)}
onModalHide={() => ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current)}
onModalHide={() => {
// We use isTransactionDeleted to know if the modal hides because the user deletes the transaction.
if (!isTransactionDeleted.current) {
return;
}

if (!navigateBackToAfterDelete.current) {
Navigation.dismissModal();
} else {
ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current);
}
}}
prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation')}
confirmText={translate('common.delete')}
cancelText={translate('common.cancel')}
Expand Down
Loading