Skip to content

Commit

Permalink
include task title route
Browse files Browse the repository at this point in the history
  • Loading branch information
tienifr committed Jul 10, 2024
1 parent b6cc4bd commit 9b7af88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/components/ReportActionItem/TaskView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -97,10 +98,7 @@ function TaskView({report, ...props}: TaskViewProps) {
<Checkbox
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 (isCompleted) {
Expand Down
5 changes: 2 additions & 3 deletions src/components/TaskHeaderActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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)) {
Expand Down
11 changes: 10 additions & 1 deletion src/libs/TaskUtils.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand Down Expand Up @@ -42,4 +51,4 @@ function getTaskCreatedMessage(reportAction: OnyxEntry<ReportAction>) {
return taskTitle ? Localize.translateLocal('task.messages.created', {title: taskTitle}) : '';
}

export {getTaskReportActionMessage, getTaskTitle, getTaskCreatedMessage};
export {isActiveTaskEditRoute, getTaskReportActionMessage, getTaskTitle, getTaskCreatedMessage};

0 comments on commit 9b7af88

Please sign in to comment.