Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tapping assignee and mark as complete quickly navigates to not found page #41667

Merged
merged 12 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're already navigating to these task editing pages, early return not to mark as completed, otherwise we would have not found page.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tienifr I mean comment in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Updated.

}
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};
Loading