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/26753: Colon added to completed reopened task messages when copy pasting #27119

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)}</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);
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
26 changes: 26 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';
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved

let currentUserEmail;
let currentUserAccountID;
Expand Down Expand Up @@ -894,6 +895,30 @@ function clearEditTaskErrors(reportID) {
});
}

/**
* @param {string} actionName
* @param {string} reportID
* @returns {string}
*/
function getTaskReportActionMessage(actionName, reportID) {
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} ${ReportUtils.getReport(reportID).reportName}`;
}

export {
createTaskAndNavigate,
editTaskAndNavigate,
Expand All @@ -915,4 +940,5 @@ export {
getTaskAssigneeAccountID,
clearEditTaskErrors,
canModifyTask,
getTaskReportActionMessage,
};
6 changes: 3 additions & 3 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,12 +183,11 @@ export default [
// If return value is true, we switch the `text` and `icon` on
// `ContextMenuItem` with `successText` and `successIcon` which will fallback to
// the `text` and `icon`
onPress: (closePopover, {reportAction, selection}) => {
onPress: (closePopover, {reportAction, selection, reportID}) => {
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const isTaskAction = ReportActionsUtils.isTaskAction(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 messageHtml = isTaskAction ? Task.getTaskReportActionMessage(reportAction.actionName, reportID) : lodashGet(message, 'html', '');

const isAttachment = _.has(reportAction, 'isAttachment') ? reportAction.isAttachment : ReportUtils.isReportMessageAttachment(message);
if (!isAttachment) {
Expand Down
Loading