diff --git a/src/components/ReportActionItem/TaskAction.js b/src/components/ReportActionItem/TaskAction.js index c0b60ad996db..9d32fa7a1e77 100644 --- a/src/components/ReportActionItem/TaskAction.js +++ b/src/components/ReportActionItem/TaskAction.js @@ -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 */ @@ -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 ( <> - {`${taskStatusText} ${taskReportName}`} + {Task.getTaskReportActionMessage(props.actionName, props.taskReportID, false)} ); } 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); diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index d66cc243acf4..c34537ff9f72 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -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; @@ -894,6 +895,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, @@ -915,4 +945,5 @@ export { getTaskAssigneeAccountID, clearEditTaskErrors, canModifyTask, + getTaskReportActionMessage, }; diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index bac79e1863e5..78115bb4c084 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -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. @@ -184,10 +185,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 = _.has(reportAction, 'isAttachment') ? reportAction.isAttachment : ReportUtils.isReportMessageAttachment(message); if (!isAttachment) {