Skip to content

Commit

Permalink
Merge pull request #44777 from bernhardoj/fix/44336-inconsistency-beh…
Browse files Browse the repository at this point in the history
…avior-when-delete-expense

Fix inconsistency in dismissing report details RHP when deleting expense with comments
  • Loading branch information
jasperhuangg authored Jul 15, 2024
2 parents 73ddc4f + 90fe533 commit 757bfb9
Showing 1 changed file with 20 additions and 4 deletions.
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

0 comments on commit 757bfb9

Please sign in to comment.