Skip to content

Commit

Permalink
Merge pull request #29730 from Expensify/jack-allowNewAssigneeTask
Browse files Browse the repository at this point in the history
Allow assigning task to new accounts
  • Loading branch information
rlinoz authored Jan 3, 2024
2 parents 446ceb1 + 3461f6b commit fb0b1d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,19 @@ function isTaskAction(reportAction: OnyxEntry<ReportAction>): boolean {
);
}

/**
* When we delete certain reports, we want to check whether there are any visible actions left to display.
* If there are no visible actions left (including system messages), we can hide the report from view entirely
*/
function doesReportHaveVisibleActions(reportID: string, actionsToMerge: ReportActions = {}): boolean {
const reportActions = Object.values(OnyxUtils.fastMerge(allReportActions?.[reportID] ?? {}, actionsToMerge));
const visibleReportActions = Object.values(reportActions ?? {}).filter((action) => shouldReportActionBeVisibleAsLastAction(action));

// Exclude the task system message and the created message
const visibleReportActionsWithoutTaskSystemMessage = visibleReportActions.filter((action) => !isTaskAction(action) && !isCreatedAction(action));
return visibleReportActionsWithoutTaskSystemMessage.length > 0;
}

function getAllReportActions(reportID: string): ReportActions {
return allReportActions?.[reportID] ?? {};
}
Expand Down Expand Up @@ -811,6 +824,7 @@ export {
isSentMoneyReportAction,
isSplitBillAction,
isTaskAction,
doesReportHaveVisibleActions,
isThreadParentMessage,
isTransactionThread,
isWhisperAction,
Expand Down
11 changes: 9 additions & 2 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,14 +713,17 @@ function getShareDestination(reportID, reports, personalDetails) {
* @param {number} originalStateNum
* @param {number} originalStatusNum
*/
function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) {
function deleteTask(taskReportID, taskTitle, originalStateNum, originalStatusNum) {
const message = `deleted task: ${taskTitle}`;
const optimisticCancelReportAction = ReportUtils.buildOptimisticTaskReportAction(taskReportID, CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED, message);
const optimisticReportActionID = optimisticCancelReportAction.reportActionID;
const taskReport = ReportUtils.getReport(taskReportID);
const parentReportAction = ReportActionsUtils.getParentReportAction(taskReport);
const parentReport = ReportUtils.getParentReport(taskReport);

// If the task report is the last visible action in the parent report, we should navigate back to the parent report
const shouldDeleteTaskReport = !ReportActionsUtils.doesReportHaveVisibleActions(taskReportID);

const optimisticReportActions = {
[parentReportAction.reportActionID]: {
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
Expand Down Expand Up @@ -822,6 +825,10 @@ function cancelTask(taskReportID, taskTitle, originalStateNum, originalStatusNum
];

API.write('CancelTask', {cancelledTaskReportActionID: optimisticReportActionID, taskReportID}, {optimisticData, successData, failureData});

if (shouldDeleteTaskReport) {
Navigation.goBack(ROUTES.REPORT_WITH_ID.getRoute(parentReport.reportID));
}
}

/**
Expand Down Expand Up @@ -928,7 +935,7 @@ export {
clearOutTaskInfoAndNavigate,
getAssignee,
getShareDestination,
cancelTask,
deleteTask,
dismissModalAndClearOutTaskInfo,
getTaskAssigneeAccountID,
clearTaskErrors,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ function HeaderView(props) {
if (props.report.stateNum !== CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum !== CONST.REPORT.STATUS.CLOSED && canModifyTask) {
threeDotMenuItems.push({
icon: Expensicons.Trashcan,
text: translate('common.cancel'),
onSelected: Session.checkIfActionIsAllowed(() => Task.cancelTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum)),
text: translate('common.delete'),
onSelected: Session.checkIfActionIsAllowed(() => Task.deleteTask(props.report.reportID, props.report.reportName, props.report.stateNum, props.report.statusNum)),
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskAssigneeSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function TaskAssigneeSelectorModal(props) {
false,
{},
[],
false,
true,
);

setHeaderMessage(OptionsListUtils.getHeaderMessage(recentReports?.length + personalDetails?.length !== 0 || currentUserOption, Boolean(userToInvite), searchValue));
Expand Down

0 comments on commit fb0b1d1

Please sign in to comment.