Skip to content

Commit

Permalink
Merge pull request #41667 from tienifr/fix/38577-regression
Browse files Browse the repository at this point in the history
fix: tapping assignee and mark as complete quickly navigates to not found page
  • Loading branch information
rlinoz authored Jul 10, 2024
2 parents 97b3831 + 9b7af88 commit def0da8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 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 @@ -96,6 +97,10 @@ function TaskView({report, ...props}: TaskViewProps) {
<View style={[styles.flexRow, styles.flex1]}>
<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 (TaskUtils.isActiveTaskEditRoute(report.reportID)) {
return;
}
if (isCompleted) {
Task.reopenTask(report);
} else {
Expand Down
13 changes: 12 additions & 1 deletion src/components/TaskHeaderActionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
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';
Expand Down Expand Up @@ -36,7 +37,17 @@ function TaskHeaderActionButton({report, session}: TaskHeaderActionButtonProps)
isDisabled={!Task.canModifyTask(report, session?.accountID ?? -1)}
medium
text={translate(ReportUtils.isCompletedTaskReport(report) ? 'task.markAsIncomplete' : 'task.markAsComplete')}
onPress={Session.checkIfActionIsAllowed(() => (ReportUtils.isCompletedTaskReport(report) ? Task.reopenTask(report) : Task.completeTask(report)))}
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 (TaskUtils.isActiveTaskEditRoute(report.reportID)) {
return;
}
if (ReportUtils.isCompletedTaskReport(report)) {
Task.reopenTask(report);
} else {
Task.completeTask(report);
}
})}
style={styles.flex1}
/>
</View>
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 def0da8

Please sign in to comment.