Skip to content

Commit

Permalink
fix change params passed to util function
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDylann committed Sep 11, 2023
1 parent 02f6e74 commit d6e5b78
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 36 deletions.
7 changes: 5 additions & 2 deletions src/components/ReportActionItem/TaskAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import compose from '../../libs/compose';
import ONYXKEYS from '../../ONYXKEYS';
import Text from '../Text';
import styles from '../../styles/styles';
import getTaskReportActionMessage from '../../libs/getTaskReportActionMessage';
import * as ReportActionUtils from '../../libs/ReportActionsUtils';

const propTypes = {
/** Name of the reportAction action */
actionName: PropTypes.string.isRequired,

/** The ID of the associated taskReport */
// eslint-disable-next-line react/no-unused-prop-types -- This is used in the withOnyx HOC
taskReportID: PropTypes.string.isRequired,
Expand All @@ -36,7 +39,7 @@ function TaskAction(props) {
return (
<>
<View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{getTaskReportActionMessage(props.reportAction, props.translate)}</Text>
<Text style={[styles.chatItemMessage, styles.colorMuted]}>{ReportActionUtils.getTaskReportActionMessage(props.actionName, props.taskReportID)}</Text>
</View>
</>
);
Expand Down
26 changes: 26 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ 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 @@ -612,6 +613,30 @@ 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 @@ -649,4 +674,5 @@ export {
isSplitBillAction,
isTaskAction,
getAllReportActions,
getTaskReportActionMessage,
};
29 changes: 0 additions & 29 deletions src/libs/getTaskReportActionMessage.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ function BaseReportActionContextMenu(props) {
close: () => setShouldKeepOpen(false),
openContextMenu: () => setShouldKeepOpen(true),
interceptAnonymousUser,
translate: props.translate,
};

if (contextAction.renderContent) {
Expand Down
5 changes: 2 additions & 3 deletions src/pages/home/report/ContextMenu/ContextMenuActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import QuickEmojiReactions from '../../../../components/Reactions/QuickEmojiReac
import MiniQuickEmojiReactions from '../../../../components/Reactions/MiniQuickEmojiReactions';
import Navigation from '../../../../libs/Navigation/Navigation';
import ROUTES from '../../../../ROUTES';
import getTaskReportActionMessage from '../../../../libs/getTaskReportActionMessage';

/**
* Gets the HTML version of the message in an action.
Expand Down Expand Up @@ -183,11 +182,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, translate}) => {
onPress: (closePopover, {reportAction, selection, reportID}) => {
const isTaskAction = ReportActionsUtils.isTaskAction(reportAction);
const isReportPreviewAction = ReportActionsUtils.isReportPreviewAction(reportAction);
const message = _.last(lodashGet(reportAction, 'message', [{}]));
const messageHtml = isTaskAction ? getTaskReportActionMessage(reportAction, translate) : lodashGet(message, 'html', '');
const messageHtml = isTaskAction ? ReportActionsUtils.getTaskReportActionMessage(reportAction.actionName, reportID) : lodashGet(message, 'html', '');

const isAttachment = _.has(reportAction, 'isAttachment') ? reportAction.isAttachment : ReportUtils.isReportMessageAttachment(message);
if (!isAttachment) {
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ function ReportActionItem(props) {
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKCANCELLED ||
props.action.actionName === CONST.REPORT.ACTIONS.TYPE.TASKREOPENED
) {
children = <TaskAction reportAction={props.action} />;
children = (
<TaskAction
taskReportID={props.action.originalMessage.taskReportID.toString()}
actionName={props.action.actionName}
/>
);
} else if (ReportActionsUtils.isCreatedTaskReportAction(props.action)) {
children = (
<TaskPreview
Expand Down

0 comments on commit d6e5b78

Please sign in to comment.