Skip to content

Commit

Permalink
fix move the util function to action folder
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDylann committed Sep 11, 2023
1 parent 9780eb9 commit 1e537f3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -21,7 +21,7 @@ function TaskAction(props) {
return (
<>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{ReportActionUtils.getTaskReportActionMessage(props.actionName, props.taskReportID)}</Text>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{Task.getTaskReportActionMessage(props.actionName, props.taskReportID)}</Text>
</View>
</>
);
Expand Down
26 changes: 0 additions & 26 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -674,5 +649,4 @@ export {
isSplitBillAction,
isTaskAction,
getAllReportActions,
getTaskReportActionMessage,
};
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';

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,
};
3 changes: 2 additions & 1 deletion 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 @@ -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) {
Expand Down

0 comments on commit 1e537f3

Please sign in to comment.