Skip to content

Commit 6132ceb

Browse files
committed
refactor: add SimpleMessageContent
1 parent 0832532 commit 6132ceb

2 files changed

Lines changed: 113 additions & 44 deletions

File tree

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import {getCleanedTagName, hasDynamicExternalWorkflow, isPolicyAdmin, isPolicyMe
8080
import {containsActionableFollowUps, parseFollowupsFromHtml} from '@libs/ReportActionFollowupUtils';
8181
import {
8282
extractLinksFromMessageHtml,
83-
getActionableCard3DSTransactionApprovalMessage,
8483
getActionableCardFraudAlertMessage,
8584
getActionableMentionWhisperMessage,
8685
getAddedApprovalRuleMessage,
@@ -99,8 +98,6 @@ import {
9998
getDefaultApproverUpdateMessage,
10099
getDeletedApprovalRuleMessage,
101100
getDeletedBudgetMessage,
102-
getDemotedFromWorkspaceMessage,
103-
getDismissedViolationMessageText,
104101
getForeignCurrencyDefaultTaxUpdateMessage,
105102
getForwardsToUpdateMessage,
106103
getIntegrationSyncFailedMessage,
@@ -123,7 +120,6 @@ import {
123120
getReimburserUpdateMessage,
124121
getRemovedCardFeedMessage,
125122
getRemovedConnectionMessage,
126-
getRemovedFromApprovalChainMessage,
127123
getRenamedAction,
128124
getRenamedCardFeedMessage,
129125
getReportActionHtml,
@@ -198,7 +194,6 @@ import {
198194
isPendingRemove,
199195
isReimbursementDeQueuedOrCanceledAction,
200196
isReimbursementQueuedAction,
201-
isRejectedAction,
202197
isRenamedAction,
203198
isResolvedConciergeCategoryOptions,
204199
isResolvedConciergeDescriptionOptions,
@@ -208,7 +203,6 @@ import {
208203
isTaskAction,
209204
isTrackExpenseAction as isTrackExpenseActionReportActionsUtils,
210205
isTripPreview,
211-
isUnapprovedAction,
212206
isWhisperActionTargetedToOthers,
213207
useTableReportViewActionRenderConditionals,
214208
} from '@libs/ReportActionsUtils';
@@ -217,10 +211,8 @@ import {
217211
canWriteInReport,
218212
chatIncludesConcierge,
219213
getChatListItemReportName,
220-
getDeletedTransactionMessage,
221214
getDisplayNamesWithTooltips,
222215
getMovedActionMessage,
223-
getPolicyChangeMessage,
224216
getWhisperDisplayNames,
225217
getWorkspaceNameUpdatedMessage,
226218
isArchivedNonExpenseReport,
@@ -258,6 +250,7 @@ import type * as OnyxTypes from '@src/types/onyx';
258250
import type {Errors} from '@src/types/onyx/OnyxCommon';
259251
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
260252
import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
253+
import SimpleMessageContent, {isSimpleMessageAction} from './actionContents/SimpleMessageContent';
261254
import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions';
262255
import MiniReportActionContextMenu from './ContextMenu/MiniReportActionContextMenu';
263256
import type {ContextMenuAnchor} from './ContextMenu/ReportActionContextMenu';
@@ -1453,8 +1446,8 @@ function PureReportActionItem({
14531446
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED)) {
14541447
const isFromNewDot = getOriginalMessage(action)?.isNewDot ?? false;
14551448
children = isFromNewDot ? emptyHTML : <ReportActionItemBasicMessage message={getMarkedReimbursedMessage(translate, action)} />;
1456-
} else if (isUnapprovedAction(action)) {
1457-
children = <ReportActionItemBasicMessage message={translate('iou.unapproved')} />;
1449+
} else if (isSimpleMessageAction(action)) {
1450+
children = <SimpleMessageContent action={action} />;
14581451
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
14591452
const wasAutoForwarded = getOriginalMessage(action)?.automaticAction ?? false;
14601453
if (wasAutoForwarded) {
@@ -1466,8 +1459,6 @@ function PureReportActionItem({
14661459
} else {
14671460
children = <ReportActionItemBasicMessage message={translate('iou.forwarded')} />;
14681461
}
1469-
} else if (isRejectedAction(action)) {
1470-
children = <ReportActionItemBasicMessage message={translate('iou.rejectedThisReport')} />;
14711462
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.CORPORATE_UPGRADE) {
14721463
children = <ReportActionItemBasicMessage message={translate('workspaceActions.upgradedWorkspace')} />;
14731464
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.CORPORATE_FORCE_UPGRADE) {
@@ -1478,24 +1469,6 @@ function PureReportActionItem({
14781469
);
14791470
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.TEAM_DOWNGRADE) {
14801471
children = <ReportActionItemBasicMessage message={translate('workspaceActions.downgradedWorkspace')} />;
1481-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
1482-
children = <ReportActionItemBasicMessage message={translate('iou.heldExpense')} />;
1483-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT) {
1484-
children = <ReportActionItemBasicMessage message={getReportActionText(action)} />;
1485-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
1486-
children = <ReportActionItemBasicMessage message={translate('iou.unheldExpense')} />;
1487-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTEDTRANSACTION_THREAD) {
1488-
children = <ReportActionItemBasicMessage message={translate('iou.reject.reportActions.rejectedExpense')} />;
1489-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REJECTED_TRANSACTION_MARKASRESOLVED) {
1490-
children = <ReportActionItemBasicMessage message={translate('iou.reject.reportActions.markedAsResolved')} />;
1491-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.RETRACTED) {
1492-
children = <ReportActionItemBasicMessage message={translate('iou.retracted')} />;
1493-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.REOPENED) {
1494-
children = <ReportActionItemBasicMessage message={translate('iou.reopened')} />;
1495-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY) {
1496-
children = <ReportActionItemBasicMessage message={getPolicyChangeMessage(translate, action)} />;
1497-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION) {
1498-
children = <ReportActionItemBasicMessage message={getDeletedTransactionMessage(translate, action)} />;
14991472
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MOVED_TRANSACTION) {
15001473
children = (
15011474
<MovedTransactionAction
@@ -1525,18 +1498,12 @@ function PureReportActionItem({
15251498
originalReport={originalReport}
15261499
/>
15271500
);
1528-
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.MERGED_WITH_CASH_TRANSACTION) {
1529-
children = <ReportActionItemBasicMessage message={translate('systemMessage.mergedWithCashTransaction')} />;
15301501
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.CARD_FROZEN || action.actionName === CONST.REPORT.ACTIONS.TYPE.CARD_UNFROZEN) {
15311502
children = (
15321503
<ReportActionItemBasicMessage message="">
15331504
<RenderHTML html={`<comment><muted-text>${getReportActionHtml(action)}</muted-text></comment>`} />
15341505
</ReportActionItemBasicMessage>
15351506
);
1536-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION)) {
1537-
children = <ReportActionItemBasicMessage message={getDismissedViolationMessageText(translate, getOriginalMessage(action))} />;
1538-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.RESOLVED_DUPLICATES)) {
1539-
children = <ReportActionItemBasicMessage message={translate('violations.resolvedDuplicates')} />;
15401507
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_NAME) {
15411508
children = <ReportActionItemBasicMessage message={getWorkspaceNameUpdatedMessage(translate, action)} />;
15421509
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_CURRENCY) {
@@ -1648,8 +1615,6 @@ function PureReportActionItem({
16481615
children = <ReportActionItemBasicMessage message={getDeletedApprovalRuleMessage(translate, action)} />;
16491616
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.UPDATE_APPROVER_RULE)) {
16501617
children = <ReportActionItemBasicMessage message={getUpdatedApprovalRuleMessage(translate, action)} />;
1651-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REMOVED_FROM_APPROVAL_CHAIN)) {
1652-
children = <ReportActionItemBasicMessage message={getRemovedFromApprovalChainMessage(translate, action)} />;
16531618
} else if (isActionableCardFraudAlert(action)) {
16541619
const message = getActionableCardFraudAlertMessage(translate, action, getLocalDateFromDatetime);
16551620

@@ -1682,8 +1647,6 @@ function PureReportActionItem({
16821647
);
16831648
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.LEAVE_ROOM) || isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.LEAVE_ROOM)) {
16841649
children = <ReportActionItemBasicMessage message={translate('report.actions.type.leftTheChat')} />;
1685-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DEMOTED_FROM_WORKSPACE)) {
1686-
children = <ReportActionItemBasicMessage message={getDemotedFromWorkspaceMessage(translate, action)} />;
16871650
} else if (isCardIssuedAction(action)) {
16881651
const shouldNavigateToCardDetails = isPolicyAdmin(policy);
16891652
children = (
@@ -1706,8 +1669,6 @@ function PureReportActionItem({
17061669
);
17071670
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.EXPORTED_TO_INTEGRATION)) {
17081671
children = <ExportIntegration action={action} />;
1709-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.RECEIPT_SCAN_FAILED)) {
1710-
children = <ReportActionItemBasicMessage message={translate('iou.receiptScanningFailed')} />;
17111672
} else if (isRenamedAction(action)) {
17121673
const message = getRenamedAction(translate, action, isExpenseReport(report));
17131674
children = <ReportActionItemBasicMessage message={message} />;
@@ -1818,8 +1779,6 @@ function PureReportActionItem({
18181779
<RenderHTML html={`<comment><muted-text>${getSettlementAccountLockedMessage(translate, action)}</muted-text></comment>`} />
18191780
</ReportActionItemBasicMessage>
18201781
);
1821-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_CARD_3DS_TRANSACTION_APPROVAL)) {
1822-
children = <ReportActionItemBasicMessage message={getActionableCard3DSTransactionApprovalMessage(translate, action)} />;
18231782
} else {
18241783
const hasBeenFlagged =
18251784
![CONST.MODERATION.MODERATOR_DECISION_APPROVED, CONST.MODERATION.MODERATOR_DECISION_PENDING].some((item) => item === moderationDecision) && !isPendingRemove(action);
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import React from 'react';
2+
import useLocalize from '@hooks/useLocalize';
3+
import {
4+
getActionableCard3DSTransactionApprovalMessage,
5+
getDemotedFromWorkspaceMessage,
6+
getDismissedViolationMessageText,
7+
getOriginalMessage,
8+
getRemovedFromApprovalChainMessage,
9+
getReportActionText,
10+
isActionOfType,
11+
isRejectedAction,
12+
isUnapprovedAction,
13+
} from '@libs/ReportActionsUtils';
14+
import {getDeletedTransactionMessage, getPolicyChangeMessage} from '@libs/ReportUtils';
15+
import ReportActionItemBasicMessage from '@pages/inbox/report/ReportActionItemBasicMessage';
16+
import CONST from '@src/CONST';
17+
import type * as OnyxTypes from '@src/types/onyx';
18+
19+
type SimpleMessageContentProps = {
20+
action: OnyxTypes.ReportAction;
21+
};
22+
23+
const SIMPLE_MESSAGE_ACTION_TYPES = new Set<string>([
24+
CONST.REPORT.ACTIONS.TYPE.HOLD,
25+
CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT,
26+
CONST.REPORT.ACTIONS.TYPE.UNHOLD,
27+
CONST.REPORT.ACTIONS.TYPE.REJECTEDTRANSACTION_THREAD,
28+
CONST.REPORT.ACTIONS.TYPE.REJECTED_TRANSACTION_MARKASRESOLVED,
29+
CONST.REPORT.ACTIONS.TYPE.RETRACTED,
30+
CONST.REPORT.ACTIONS.TYPE.REOPENED,
31+
CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY,
32+
CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION,
33+
CONST.REPORT.ACTIONS.TYPE.MERGED_WITH_CASH_TRANSACTION,
34+
CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION,
35+
CONST.REPORT.ACTIONS.TYPE.RESOLVED_DUPLICATES,
36+
CONST.REPORT.ACTIONS.TYPE.RECEIPT_SCAN_FAILED,
37+
CONST.REPORT.ACTIONS.TYPE.DEMOTED_FROM_WORKSPACE,
38+
CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_CARD_3DS_TRANSACTION_APPROVAL,
39+
CONST.REPORT.ACTIONS.TYPE.REMOVED_FROM_APPROVAL_CHAIN,
40+
]);
41+
42+
function isSimpleMessageAction(action: OnyxTypes.ReportAction): boolean {
43+
return SIMPLE_MESSAGE_ACTION_TYPES.has(action.actionName) || isUnapprovedAction(action) || isRejectedAction(action);
44+
}
45+
46+
function SimpleMessageContent({action}: SimpleMessageContentProps) {
47+
const {translate} = useLocalize();
48+
49+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.HOLD)) {
50+
return <ReportActionItemBasicMessage message={translate('iou.heldExpense')} />;
51+
}
52+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.HOLD_COMMENT)) {
53+
return <ReportActionItemBasicMessage message={getReportActionText(action)} />;
54+
}
55+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.UNHOLD)) {
56+
return <ReportActionItemBasicMessage message={translate('iou.unheldExpense')} />;
57+
}
58+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REJECTEDTRANSACTION_THREAD)) {
59+
return <ReportActionItemBasicMessage message={translate('iou.reject.reportActions.rejectedExpense')} />;
60+
}
61+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REJECTED_TRANSACTION_MARKASRESOLVED)) {
62+
return <ReportActionItemBasicMessage message={translate('iou.reject.reportActions.markedAsResolved')} />;
63+
}
64+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.RETRACTED)) {
65+
return <ReportActionItemBasicMessage message={translate('iou.retracted')} />;
66+
}
67+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REOPENED)) {
68+
return <ReportActionItemBasicMessage message={translate('iou.reopened')} />;
69+
}
70+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.CHANGE_POLICY)) {
71+
return <ReportActionItemBasicMessage message={getPolicyChangeMessage(translate, action)} />;
72+
}
73+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DELETED_TRANSACTION)) {
74+
return <ReportActionItemBasicMessage message={getDeletedTransactionMessage(translate, action)} />;
75+
}
76+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.MERGED_WITH_CASH_TRANSACTION)) {
77+
return <ReportActionItemBasicMessage message={translate('systemMessage.mergedWithCashTransaction')} />;
78+
}
79+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DISMISSED_VIOLATION)) {
80+
return <ReportActionItemBasicMessage message={getDismissedViolationMessageText(translate, getOriginalMessage(action))} />;
81+
}
82+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.RESOLVED_DUPLICATES)) {
83+
return <ReportActionItemBasicMessage message={translate('violations.resolvedDuplicates')} />;
84+
}
85+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.RECEIPT_SCAN_FAILED)) {
86+
return <ReportActionItemBasicMessage message={translate('iou.receiptScanningFailed')} />;
87+
}
88+
if (isUnapprovedAction(action)) {
89+
return <ReportActionItemBasicMessage message={translate('iou.unapproved')} />;
90+
}
91+
if (isRejectedAction(action)) {
92+
return <ReportActionItemBasicMessage message={translate('iou.rejectedThisReport')} />;
93+
}
94+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.DEMOTED_FROM_WORKSPACE)) {
95+
return <ReportActionItemBasicMessage message={getDemotedFromWorkspaceMessage(translate, action)} />;
96+
}
97+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_CARD_3DS_TRANSACTION_APPROVAL)) {
98+
return <ReportActionItemBasicMessage message={getActionableCard3DSTransactionApprovalMessage(translate, action)} />;
99+
}
100+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.REMOVED_FROM_APPROVAL_CHAIN)) {
101+
return <ReportActionItemBasicMessage message={getRemovedFromApprovalChainMessage(translate, action)} />;
102+
}
103+
104+
return null;
105+
}
106+
107+
SimpleMessageContent.displayName = 'SimpleMessageContent';
108+
109+
export default SimpleMessageContent;
110+
export {isSimpleMessageAction};

0 commit comments

Comments
 (0)