Skip to content

Commit

Permalink
add comment and restructure code to make it easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jul 13, 2024
1 parent c5c0799 commit 089c0fa
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +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 Down Expand Up @@ -750,10 +752,13 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
onConfirm={deleteTransaction}
onCancel={() => setIsDeleteModalVisible(false)}
onModalHide={() => {

Check failure on line 754 in src/pages/ReportDetailsPage.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Prefer an early return to a conditionally-wrapped function body
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')}
Expand Down

0 comments on commit 089c0fa

Please sign in to comment.