From 9b7af888d3e6ff12ee1e043a69932de9aad3ddd7 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 10 Jul 2024 19:17:07 +0700 Subject: [PATCH] include task title route --- src/components/ReportActionItem/TaskView.tsx | 6 ++---- src/components/TaskHeaderActionButton.tsx | 5 ++--- src/libs/TaskUtils.ts | 11 ++++++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/ReportActionItem/TaskView.tsx b/src/components/ReportActionItem/TaskView.tsx index 1ca3bcdf7e0e..941e7cd5c610 100644 --- a/src/components/ReportActionItem/TaskView.tsx +++ b/src/components/ReportActionItem/TaskView.tsx @@ -22,6 +22,7 @@ import getButtonState from '@libs/getButtonState'; import Navigation from '@libs/Navigation/Navigation'; import * as OptionsListUtils from '@libs/OptionsListUtils'; import * as ReportUtils from '@libs/ReportUtils'; +import * as TaskUtils from '@libs/TaskUtils'; import * as Session from '@userActions/Session'; import * as Task from '@userActions/Task'; import CONST from '@src/CONST'; @@ -97,10 +98,7 @@ function TaskView({report, ...props}: TaskViewProps) { { // If we're already navigating to these task editing pages, early return not to mark as completed, otherwise we would have not found page. - if ( - Navigation.isActiveRoute(ROUTES.TASK_ASSIGNEE.getRoute(report.reportID)) || - Navigation.isActiveRoute(ROUTES.REPORT_DESCRIPTION.getRoute(report.reportID)) - ) { + if (TaskUtils.isActiveTaskEditRoute(report.reportID)) { return; } if (isCompleted) { diff --git a/src/components/TaskHeaderActionButton.tsx b/src/components/TaskHeaderActionButton.tsx index 963c17073758..5e563ea99763 100644 --- a/src/components/TaskHeaderActionButton.tsx +++ b/src/components/TaskHeaderActionButton.tsx @@ -4,12 +4,11 @@ import type {OnyxEntry} from 'react-native-onyx'; import {withOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; -import Navigation from '@libs/Navigation/Navigation'; import * as ReportUtils from '@libs/ReportUtils'; +import * as TaskUtils from '@libs/TaskUtils'; import * as Session from '@userActions/Session'; import * as Task from '@userActions/Task'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import Button from './Button'; @@ -40,7 +39,7 @@ function TaskHeaderActionButton({report, session}: TaskHeaderActionButtonProps) text={translate(ReportUtils.isCompletedTaskReport(report) ? 'task.markAsIncomplete' : 'task.markAsComplete')} onPress={Session.checkIfActionIsAllowed(() => { // If we're already navigating to these task editing pages, early return not to mark as completed, otherwise we would have not found page. - if (Navigation.isActiveRoute(ROUTES.TASK_ASSIGNEE.getRoute(report.reportID)) || Navigation.isActiveRoute(ROUTES.REPORT_DESCRIPTION.getRoute(report.reportID))) { + if (TaskUtils.isActiveTaskEditRoute(report.reportID)) { return; } if (ReportUtils.isCompletedTaskReport(report)) { diff --git a/src/libs/TaskUtils.ts b/src/libs/TaskUtils.ts index bd0bd10cd83e..06745a49217b 100644 --- a/src/libs/TaskUtils.ts +++ b/src/libs/TaskUtils.ts @@ -1,12 +1,21 @@ import type {OnyxEntry} from 'react-native-onyx'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; +import ROUTES from '@src/ROUTES'; import type {Message} from '@src/types/onyx/ReportAction'; import type ReportAction from '@src/types/onyx/ReportAction'; import * as Localize from './Localize'; +import Navigation from './Navigation/Navigation'; import {getReportActionHtml, getReportActionText} from './ReportActionsUtils'; import * as ReportConnection from './ReportConnection'; +/** + * Check if the active route belongs to task edit flow. + */ +function isActiveTaskEditRoute(reportID: string): boolean { + return [ROUTES.TASK_TITLE, ROUTES.TASK_ASSIGNEE, ROUTES.REPORT_DESCRIPTION].map((route) => route.getRoute(reportID)).some(Navigation.isActiveRoute); +} + /** * Given the Task reportAction name, return the appropriate message to be displayed and copied to clipboard. */ @@ -42,4 +51,4 @@ function getTaskCreatedMessage(reportAction: OnyxEntry) { return taskTitle ? Localize.translateLocal('task.messages.created', {title: taskTitle}) : ''; } -export {getTaskReportActionMessage, getTaskTitle, getTaskCreatedMessage}; +export {isActiveTaskEditRoute, getTaskReportActionMessage, getTaskTitle, getTaskCreatedMessage};