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

Reopen Task #18986

Merged
merged 11 commits into from
May 16, 2023
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
1 change: 1 addition & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ const CONST = {
RENAMED: 'RENAMED',
CHRONOSOOOLIST: 'CHRONOSOOOLIST',
TASKCOMPLETED: 'TASKCOMPLETED',
TASKREOPENED: 'TASKREOPENED',
POLICYCHANGELOG: {
ADD_APPROVER_RULE: 'POLICYCHANGELOG_ADD_APPROVER_RULE',
ADD_CATEGORY: 'POLICYCHANGELOG_ADD_CATEGORY',
Expand Down
13 changes: 12 additions & 1 deletion src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,18 @@ const TaskAction = (props) => {
const taskReportID = props.taskReportID;
const taskReportName = props.taskReport.reportName || '';

const messageLinkText = props.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED ? props.translate('task.messages.completed') : props.translate('newTaskPage.task');
let messageLinkText = '';
switch (props.actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
messageLinkText = props.translate('task.messages.completed');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKREOPENED:
messageLinkText = props.translate('task.messages.reopened');
break;
default:
messageLinkText = props.translate('newTaskPage.task');
}

return (
<Pressable
onPress={() => Navigation.navigate(ROUTES.getReportRoute(taskReportID))}
Expand Down
5 changes: 3 additions & 2 deletions src/components/ReportActionItem/TaskPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ const TaskPreview = (props) => {
isChecked={isTaskCompleted}
onPress={() => {
if (isTaskCompleted) {
return;
TaskUtils.reopenTask(props.taskReportID, parentReportID, taskTitle);
} else {
TaskUtils.completeTask(props.taskReportID, parentReportID, taskTitle);
}
TaskUtils.completeTask(props.taskReportID, parentReportID, taskTitle);
}}
/>
<Text>{taskTitle}</Text>
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ export default {
completed: 'Completed',
messages: {
completed: 'Completed task',
reopened: 'Reopened task',
},
},
statementPage: {
Expand Down
3 changes: 2 additions & 1 deletion src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,8 @@ export default {
task: {
completed: 'Completada',
messages: {
completed: 'tarea completada',
completed: 'Tarea completada',
reopened: 'Tarea reabrir',
},
},
statementPage: {
Expand Down
63 changes: 63 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,68 @@ function completeTask(taskReportID, parentReportID, taskTitle) {
);
}

/**
* Reopens a closed task
* @param {string} taskReportID ReportID of the task
* @param {string} parentReportID ReportID of the linked parent report of the task so we can add the action
* @param {string} taskTitle Title of the task
*/
function reopenTask(taskReportID, parentReportID, taskTitle) {
const message = `Reopened task: ${taskTitle}`;
const reopenedTaskReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKREOPENED, message);

const optimisticData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.OPEN,
statusNum: CONST.REPORT.STATUS.OPEN,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${parentReportID}`,
value: {
lastVisibleActionCreated: reopenedTaskReportAction.created,
lastMessageText: message,
lastActorEmail: reopenedTaskReportAction.actorEmail,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
value: {[reopenedTaskReportAction.reportActionID]: reopenedTaskReportAction},
},
];

const successData = [];
const failureData = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
value: {
stateNum: CONST.REPORT.STATE_NUM.SUBMITTED,
statusNum: CONST.REPORT.STATUS.APPROVED,
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
value: {[reopenedTaskReportAction.reportActionID]: {pendingAction: null}},
},
];

API.write(
'ReopenTask',
{
taskReportID,
reopenedTaskReportActionID: reopenedTaskReportAction.reportActionID,
},
{optimisticData, successData, failureData},
);
}

/**
* @function editTask
* @param {object} report
Expand Down Expand Up @@ -450,6 +512,7 @@ export {
setAssigneeValue,
setShareDestinationValue,
clearOutTaskInfo,
reopenTask,
completeTask,
clearOutTaskInfoAndNavigate,
getAssignee,
Expand Down
4 changes: 1 addition & 3 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ const HeaderView = (props) => {
threeDotMenuItems.push({
icon: Expensicons.Checkmark,
text: props.translate('newTaskPage.markAsIncomplete'),

// Implementing in https://github.com/Expensify/App/issues/16858
onSelected: () => {},
onSelected: () => TaskUtils.reopenTask(props.report.reportID, props.report.parentReportID, title),
});
}

Expand Down