Skip to content

Commit

Permalink
Merge pull request #27119 from DylanDylann/fix/26753-assign-task-colo…
Browse files Browse the repository at this point in the history
…n-added-to-completed-task-when-copy

Fix/26753: Colon added to completed reopened task messages when copy pasting
  • Loading branch information
luacmartins authored Sep 19, 2023
2 parents e23c181 + 935e720 commit 76b6914
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 48 deletions.
49 changes: 3 additions & 46 deletions src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import React from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import Text from '../Text';
import styles from '../../styles/styles';
import CONST from '../../CONST';
import * as Task from '../../libs/actions/Task';

const propTypes = {
/** Name of the reportAction action */
Expand All @@ -17,60 +14,20 @@ const propTypes = {
// eslint-disable-next-line react/no-unused-prop-types -- This is used in the withOnyx HOC
taskReportID: PropTypes.string.isRequired,

/* Onyx Props */
taskReport: PropTypes.shape({
/** Title of the task */
reportName: PropTypes.string,

/** AccountID of the manager in this iou report */
managerID: PropTypes.number,

/** AccountID of the creator of this iou report */
ownerAccountID: PropTypes.number,
}),

...withLocalizePropTypes,
};

const defaultProps = {
taskReport: {},
};
function TaskAction(props) {
const taskReportName = props.taskReport.reportName || '';

let taskStatusText = '';
switch (props.actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
taskStatusText = props.translate('task.messages.completed');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED:
taskStatusText = props.translate('task.messages.canceled');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKREOPENED:
taskStatusText = props.translate('task.messages.reopened');
break;
default:
taskStatusText = props.translate('task.task');
}

return (
<>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{`${taskStatusText} ${taskReportName}`}</Text>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{Task.getTaskReportActionMessage(props.actionName, props.taskReportID, false)}</Text>
</View>
</>
);
}

TaskAction.propTypes = propTypes;
TaskAction.defaultProps = defaultProps;
TaskAction.displayName = 'TaskAction';

export default compose(
withLocalize,
withOnyx({
taskReport: {
key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
},
}),
)(TaskAction);
export default withLocalize(TaskAction);
31 changes: 31 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import * as ErrorUtils from '../ErrorUtils';
import * as ReportActionsUtils from '../ReportActionsUtils';
import * as Expensicons from '../../components/Icon/Expensicons';
import * as LocalePhoneNumber from '../LocalePhoneNumber';
import * as Localize from '../Localize';

let currentUserEmail;
let currentUserAccountID;
Expand Down Expand Up @@ -913,6 +914,35 @@ function clearEditTaskErrors(reportID) {
});
}

/**
* @param {string} actionName
* @param {string} reportID
* @param {boolean} isCreateTaskAction
* @returns {string}
*/
function getTaskReportActionMessage(actionName, reportID, isCreateTaskAction) {
const report = ReportUtils.getReport(reportID);
if (isCreateTaskAction) {
return `Created a task: ${report.reportName}`;
}
let taskStatusText = '';
switch (actionName) {
case CONST.REPORT.ACTIONS.TYPE.TASKCOMPLETED:
taskStatusText = Localize.translateLocal('task.messages.completed');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED:
taskStatusText = Localize.translateLocal('task.messages.canceled');
break;
case CONST.REPORT.ACTIONS.TYPE.TASKREOPENED:
taskStatusText = Localize.translateLocal('task.messages.reopened');
break;
default:
taskStatusText = Localize.translateLocal('task.task');
}

return `${taskStatusText} ${report.reportName}`;
}

export {
createTaskAndNavigate,
editTaskAndNavigate,
Expand All @@ -934,4 +964,5 @@ export {
getTaskAssigneeAccountID,
clearEditTaskErrors,
canModifyTask,
getTaskReportActionMessage,
};
6 changes: 4 additions & 2 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import QuickEmojiReactions from '../../../../components/Reactions/QuickEmojiReac
import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickEmojiReactions';
import Navigation from '../../../../libs/Navigation/Navigation';
import ROUTES from '../../../../ROUTES';
import * as Task from '../../../../libs/actions/Task';

/**
* Gets the HTML version of the message in an action.
Expand Down Expand Up @@ -182,10 +183,11 @@ export default [
// the `text` and `icon`
onPress: (closePopover, {reportAction, selection}) => {
const isTaskAction = ReportActionsUtils.isTaskAction(reportAction);
const isCreateTaskAction = ReportActionsUtils.isCreatedTaskReportAction(reportAction);
const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction);
const message = _.last(lodashGet(reportAction, 'message', [{}]));
const originalMessage = _.get(reportAction, 'originalMessage', {});
const messageHtml = isTaskAction ? lodashGet(originalMessage, 'html', '') : lodashGet(message, 'html', '');
const reportID = lodashGet(reportAction, 'originalMessage.taskReportID', '').toString();
const messageHtml = isTaskAction || isCreateTaskAction ? Task.getTaskReportActionMessage(reportAction.actionName, reportID, isCreateTaskAction) : lodashGet(message, 'html', '');

const isAttachment = ReportActionsUtils.isReportActionAttachment(reportAction);
if (!isAttachment) {
Expand Down

0 comments on commit 76b6914

Please sign in to comment.