Skip to content

Commit

Permalink
Merge pull request #18986 from Expensify/jack-reopenTask
Browse files Browse the repository at this point in the history
  • Loading branch information
thienlnam authored May 16, 2023
2 parents 896ad77 + d251156 commit 1bf45c7
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 7 deletions.
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

0 comments on commit 1bf45c7

Please sign in to comment.