From 5f6cae1ac5a3fd6714756cb1ebc39fc6df3b66ea Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 3 Jul 2024 23:10:46 +0800 Subject: [PATCH 1/6] fix inconsistency behavior when deleting expense --- src/pages/ReportDetailsPage.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index b04e56f288e9..7f0629f50909 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -553,9 +553,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); + } + + if (!navigateBackToAfterDelete.current) { + Navigation.dismissModal(); } }, [caseID, iouTransactionID, moneyRequestReport?.reportID, report, requestParentReportAction]); return ( From c3da03e5b25774f8a3621bcce00d3d1609655e56 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 3 Jul 2024 23:49:08 +0800 Subject: [PATCH 2/6] dismiss the modal after deleting transaction --- src/pages/ReportDetailsPage.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 7f0629f50909..c115955c93d7 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -537,6 +537,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD ); + const isTransactionDeleted = useRef(false); const navigateBackToAfterDelete = useRef(); const deleteTransaction = useCallback(() => { @@ -558,9 +559,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD navigateBackToAfterDelete.current = IOU.deleteMoneyRequest(iouTransactionID, requestParentReportAction, isSingleTransactionView); } - if (!navigateBackToAfterDelete.current) { - Navigation.dismissModal(); - } + isTransactionDeleted.current = true; }, [caseID, iouTransactionID, moneyRequestReport?.reportID, report, requestParentReportAction]); return ( @@ -637,7 +636,13 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD isVisible={isDeleteModalVisible} onConfirm={deleteTransaction} onCancel={() => setIsDeleteModalVisible(false)} - onModalHide={() => ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current)} + onModalHide={() => { + if (isTransactionDeleted.current && !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')} From aac8461e9fb0f0793a3a5ec3fb4ca0014bb98fdf Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 4 Jul 2024 00:06:59 +0800 Subject: [PATCH 3/6] add missing deps --- src/pages/ReportDetailsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index c115955c93d7..13da8bb0d479 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -560,7 +560,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD } isTransactionDeleted.current = true; - }, [caseID, iouTransactionID, moneyRequestReport?.reportID, report, requestParentReportAction]); + }, [caseID, iouTransactionID, moneyRequestReport?.reportID, report, requestParentReportAction, isSingleTransactionView]); return ( From 7999cf5e2f92cf650191c900b9d8aeb94787bead Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 4 Jul 2024 11:08:32 +0800 Subject: [PATCH 4/6] prettier --- src/pages/ReportDetailsPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 13da8bb0d479..dfd07497e888 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -640,7 +640,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD if (isTransactionDeleted.current && !navigateBackToAfterDelete.current) { Navigation.dismissModal(); } else { - ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current) + ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current); } }} prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation')} From 089c0fa254aae4fbd86460aabf1d4df5729d6f6b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 13 Jul 2024 10:45:10 +0800 Subject: [PATCH 5/6] add comment and restructure code to make it easier to read --- src/pages/ReportDetailsPage.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 4f88efa2d334..031f2f9ebbdf 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -637,7 +637,9 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD ); + // A flag to indicate whether the user choose to delete the transaction or not const isTransactionDeleted = useRef(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(); const deleteTransaction = useCallback(() => { @@ -750,10 +752,13 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD onConfirm={deleteTransaction} onCancel={() => setIsDeleteModalVisible(false)} onModalHide={() => { - if (isTransactionDeleted.current && !navigateBackToAfterDelete.current) { - Navigation.dismissModal(); - } else { - ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current); + // We use isTransactionDeleted to know if the modal hides because the user deletes the transaction. + if (isTransactionDeleted.current) { + if (!navigateBackToAfterDelete.current) { + Navigation.dismissModal(); + } else { + ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current); + } } }} prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation')} From 90fe533b8830d223f6478837edc26dab93381af1 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Sat, 13 Jul 2024 11:33:34 +0800 Subject: [PATCH 6/6] lint --- src/pages/ReportDetailsPage.tsx | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 031f2f9ebbdf..288f6c241be3 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -753,12 +753,14 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD onCancel={() => setIsDeleteModalVisible(false)} onModalHide={() => { // We use isTransactionDeleted to know if the modal hides because the user deletes the transaction. - if (isTransactionDeleted.current) { - if (!navigateBackToAfterDelete.current) { - Navigation.dismissModal(); - } else { - ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current); - } + if (!isTransactionDeleted.current) { + return; + } + + if (!navigateBackToAfterDelete.current) { + Navigation.dismissModal(); + } else { + ReportUtils.navigateBackAfterDeleteTransaction(navigateBackToAfterDelete.current); } }} prompt={caseID === CASES.DEFAULT ? translate('task.deleteConfirmation') : translate('iou.deleteConfirmation')}