From 1e537f3e21e0cb8f59d4623c2d31ef44e3c9ed6c Mon Sep 17 00:00:00 2001 From: DylanDylann Date: Mon, 11 Sep 2023 15:51:27 +0700 Subject: [PATCH] fix move the util function to action folder --- src/components/ReportActionItem/TaskAction.js | 4 +-- src/libs/ReportActionsUtils.js | 26 ------------------- src/libs/actions/Task.js | 26 +++++++++++++++++++ .../report/ContextMenu/ContextMenuActions.js | 3 ++- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/components/ReportActionItem/TaskAction.js b/src/components/ReportActionItem/TaskAction.js index 6cd4add29c01..60c5736a0374 100644 --- a/src/components/ReportActionItem/TaskAction.js +++ b/src/components/ReportActionItem/TaskAction.js @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import withLocalize, {withLocalizePropTypes} from '../withLocalize'; import Text from '../Text'; import styles from '../../styles/styles'; -import * as ReportActionUtils from '../../libs/ReportActionsUtils'; +import * as Task from '../../libs/actions/Task'; const propTypes = { /** Name of the reportAction action */ @@ -21,7 +21,7 @@ function TaskAction(props) { return ( <> - {ReportActionUtils.getTaskReportActionMessage(props.actionName, props.taskReportID)} + {Task.getTaskReportActionMessage(props.actionName, props.taskReportID)} ); diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index bab587457b94..9cbc414bf582 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -9,7 +9,6 @@ import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; import Log from './Log'; import isReportMessageAttachment from './isReportMessageAttachment'; -import * as Localize from './Localize'; const allReports = {}; Onyx.connect({ @@ -613,30 +612,6 @@ function getAllReportActions(reportID) { return lodashGet(allReportActions, 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} ${allReports[reportID].reportName}`; -} - export { getSortedReportActions, getLastVisibleAction, @@ -674,5 +649,4 @@ export { isSplitBillAction, isTaskAction, getAllReportActions, - getTaskReportActionMessage, }; diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index d66cc243acf4..8a56f34aee3a 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,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, @@ -915,4 +940,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 5745d01a8bfe..369967788932 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. @@ -186,7 +187,7 @@ export default [ const isTaskAction = ReportActionsUtils.isTaskAction(reportAction); const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction); const message = _.last(lodashGet(reportAction, 'message', [{}])); - const messageHtml = isTaskAction ? ReportActionsUtils.getTaskReportActionMessage(reportAction.actionName, reportID) : 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) {