Skip to content

Commit d6e1400

Browse files
committed
refactor: add ApprovalFlowContent
1 parent 9e543f2 commit d6e1400

2 files changed

Lines changed: 114 additions & 56 deletions

File tree

src/pages/inbox/report/PureReportActionItem.tsx

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import type {ReportsSplitNavigatorParamList} from '@libs/Navigation/types';
7676
import {getBankAccountLastFourDigits} from '@libs/PaymentUtils';
7777
import Permissions from '@libs/Permissions';
7878
import {getDisplayNameOrDefault} from '@libs/PersonalDetailsUtils';
79-
import {getCleanedTagName, hasDynamicExternalWorkflow, isPolicyAdmin, isPolicyMember, isPolicyOwner} from '@libs/PolicyUtils';
79+
import {getCleanedTagName, isPolicyAdmin, isPolicyMember, isPolicyOwner} from '@libs/PolicyUtils';
8080
import {containsActionableFollowUps, parseFollowupsFromHtml} from '@libs/ReportActionFollowupUtils';
8181
import {
8282
extractLinksFromMessageHtml,
@@ -175,8 +175,6 @@ import {
175175
getWorkspaceTagUpdateMessage,
176176
getWorkspaceTaxUpdateMessage,
177177
getWorkspaceUpdateFieldMessage,
178-
hasPendingDEWApprove,
179-
hasPendingDEWSubmit,
180178
isActionableAddPaymentCard,
181179
isActionableCardFraudAlert,
182180
isActionableJoinRequest,
@@ -193,7 +191,6 @@ import {
193191
isDeletedAction,
194192
isDeletedParentAction as isDeletedParentActionUtils,
195193
isIOURequestReportAction,
196-
isMarkAsClosedAction,
197194
isMessageDeleted,
198195
isMoneyRequestAction,
199196
isPendingRemove,
@@ -259,6 +256,7 @@ import type * as OnyxTypes from '@src/types/onyx';
259256
import type {Errors} from '@src/types/onyx/OnyxCommon';
260257
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
261258
import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
259+
import ApprovalFlowContent, {isApprovalFlowAction} from './actionContents/ApprovalFlowContent';
262260
import {RestrictedReadOnlyContextMenuActions} from './ContextMenu/ContextMenuActions';
263261
import MiniReportActionContextMenu from './ContextMenu/MiniReportActionContextMenu';
264262
import type {ContextMenuAnchor} from './ContextMenu/ReportActionContextMenu';
@@ -1372,47 +1370,16 @@ function PureReportActionItem({
13721370
originalReport={originalReport}
13731371
/>
13741372
);
1375-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED) || isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED) || isMarkAsClosedAction(action)) {
1376-
const wasSubmittedViaHarvesting = !isMarkAsClosedAction(action) ? (getOriginalMessage(action)?.harvesting ?? false) : false;
1377-
const isDEWPolicy = hasDynamicExternalWorkflow(policy);
1378-
1379-
const isPendingAdd = action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;
1380-
if (wasSubmittedViaHarvesting) {
1381-
children = (
1382-
<ReportActionItemMessageWithExplain
1383-
message={translate('iou.automaticallySubmitted')}
1384-
action={action}
1385-
childReport={childReport}
1386-
originalReport={originalReport}
1387-
/>
1388-
);
1389-
} else if (hasPendingDEWSubmit(reportMetadata, isDEWPolicy) && isPendingAdd) {
1390-
children = <ReportActionItemBasicMessage message={translate('iou.queuedToSubmitViaDEW')} />;
1391-
} else if (isDEWPolicy) {
1392-
// Don't show a memo for DEW actions, it's shown in the Concierge action below
1393-
children = <ReportActionItemBasicMessage message={translate('iou.submitted')} />;
1394-
} else {
1395-
children = <ReportActionItemBasicMessage message={translate('iou.submitted', getOriginalMessage(action)?.message)} />;
1396-
}
1397-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
1398-
const wasAutoApproved = getOriginalMessage(action)?.automaticAction ?? false;
1399-
const isDEWPolicy = hasDynamicExternalWorkflow(policy);
1400-
const isPendingAdd = action.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;
1401-
1402-
if (wasAutoApproved) {
1403-
children = (
1404-
<ReportActionItemMessageWithExplain
1405-
message={translate('iou.automaticallyApproved')}
1406-
action={action}
1407-
childReport={childReport}
1408-
originalReport={originalReport}
1409-
/>
1410-
);
1411-
} else if (hasPendingDEWApprove(reportMetadata, isDEWPolicy) && isPendingAdd) {
1412-
children = <ReportActionItemBasicMessage message={translate('iou.queuedToApproveViaDEW')} />;
1413-
} else {
1414-
children = <ReportActionItemBasicMessage message={translate('iou.approvedMessage')} />;
1415-
}
1373+
} else if (isApprovalFlowAction(action)) {
1374+
children = (
1375+
<ApprovalFlowContent
1376+
action={action}
1377+
policy={policy}
1378+
reportMetadata={reportMetadata}
1379+
childReport={childReport}
1380+
originalReport={originalReport}
1381+
/>
1382+
);
14161383
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.IOU) && getOriginalMessage(action)?.type === CONST.IOU.REPORT_ACTION_TYPE.PAY) {
14171384
const wasAutoPaid = getOriginalMessage(action)?.automaticAction ?? false;
14181385
const paymentType = getOriginalMessage(action)?.paymentType;
@@ -1463,17 +1430,6 @@ function PureReportActionItem({
14631430
children = <ReportActionItemBasicMessage message={getReimbursedMessage(translate, action, report, currentUserAccountID)} />;
14641431
} else if (isUnapprovedAction(action)) {
14651432
children = <ReportActionItemBasicMessage message={translate('iou.unapproved')} />;
1466-
} else if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
1467-
const wasAutoForwarded = getOriginalMessage(action)?.automaticAction ?? false;
1468-
if (wasAutoForwarded) {
1469-
children = (
1470-
<ReportActionItemBasicMessage>
1471-
<RenderHTML html={`<comment><muted-text>${translate('iou.automaticallyForwarded')}</muted-text></comment>`} />
1472-
</ReportActionItemBasicMessage>
1473-
);
1474-
} else {
1475-
children = <ReportActionItemBasicMessage message={translate('iou.forwarded')} />;
1476-
}
14771433
} else if (isRejectedAction(action)) {
14781434
children = <ReportActionItemBasicMessage message={translate('iou.rejectedThisReport')} />;
14791435
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.POLICY_CHANGE_LOG.CORPORATE_UPGRADE) {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import React from 'react';
2+
import type {OnyxEntry} from 'react-native-onyx';
3+
import RenderHTML from '@components/RenderHTML';
4+
import useLocalize from '@hooks/useLocalize';
5+
import {hasDynamicExternalWorkflow} from '@libs/PolicyUtils';
6+
import {getOriginalMessage, hasPendingDEWApprove, hasPendingDEWSubmit, isActionOfType, isMarkAsClosedAction} from '@libs/ReportActionsUtils';
7+
import ReportActionItemBasicMessage from '@pages/inbox/report/ReportActionItemBasicMessage';
8+
import ReportActionItemMessageWithExplain from '@pages/inbox/report/ReportActionItemMessageWithExplain';
9+
import CONST from '@src/CONST';
10+
import type * as OnyxTypes from '@src/types/onyx';
11+
12+
type ApprovalFlowContentProps = {
13+
action: OnyxTypes.ReportAction;
14+
policy: OnyxEntry<OnyxTypes.Policy>;
15+
reportMetadata: OnyxEntry<OnyxTypes.ReportMetadata>;
16+
childReport: OnyxEntry<OnyxTypes.Report>;
17+
originalReport: OnyxEntry<OnyxTypes.Report>;
18+
};
19+
20+
function isApprovalFlowAction(action: OnyxTypes.ReportAction): boolean {
21+
return (
22+
isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED) ||
23+
isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED) ||
24+
isMarkAsClosedAction(action) ||
25+
isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.APPROVED) ||
26+
isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)
27+
);
28+
}
29+
30+
function ApprovalFlowContent({action, policy, reportMetadata, childReport, originalReport}: ApprovalFlowContentProps) {
31+
const {translate} = useLocalize();
32+
const isDEWPolicy = hasDynamicExternalWorkflow(policy);
33+
const isPendingAdd = action?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;
34+
35+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED) || isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.SUBMITTED_AND_CLOSED) || isMarkAsClosedAction(action)) {
36+
const wasSubmittedViaHarvesting = !isMarkAsClosedAction(action) ? (getOriginalMessage(action)?.harvesting ?? false) : false;
37+
38+
if (wasSubmittedViaHarvesting) {
39+
return (
40+
<ReportActionItemMessageWithExplain
41+
message={translate('iou.automaticallySubmitted')}
42+
action={action}
43+
childReport={childReport}
44+
originalReport={originalReport}
45+
/>
46+
);
47+
}
48+
49+
if (hasPendingDEWSubmit(reportMetadata, isDEWPolicy) && isPendingAdd) {
50+
return <ReportActionItemBasicMessage message={translate('iou.queuedToSubmitViaDEW')} />;
51+
}
52+
53+
if (isDEWPolicy) {
54+
// Don't show a memo for DEW actions, it's shown in the Concierge action below
55+
return <ReportActionItemBasicMessage message={translate('iou.submitted')} />;
56+
}
57+
58+
return <ReportActionItemBasicMessage message={translate('iou.submitted', getOriginalMessage(action)?.message)} />;
59+
}
60+
61+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.APPROVED)) {
62+
const wasAutoApproved = getOriginalMessage(action)?.automaticAction ?? false;
63+
64+
if (wasAutoApproved) {
65+
return (
66+
<ReportActionItemMessageWithExplain
67+
message={translate('iou.automaticallyApproved')}
68+
action={action}
69+
childReport={childReport}
70+
originalReport={originalReport}
71+
/>
72+
);
73+
}
74+
75+
if (hasPendingDEWApprove(reportMetadata, isDEWPolicy) && isPendingAdd) {
76+
return <ReportActionItemBasicMessage message={translate('iou.queuedToApproveViaDEW')} />;
77+
}
78+
79+
return <ReportActionItemBasicMessage message={translate('iou.approvedMessage')} />;
80+
}
81+
82+
if (isActionOfType(action, CONST.REPORT.ACTIONS.TYPE.FORWARDED)) {
83+
const wasAutoForwarded = getOriginalMessage(action)?.automaticAction ?? false;
84+
85+
if (wasAutoForwarded) {
86+
return (
87+
<ReportActionItemBasicMessage>
88+
<RenderHTML html={`<comment><muted-text>${translate('iou.automaticallyForwarded')}</muted-text></comment>`} />
89+
</ReportActionItemBasicMessage>
90+
);
91+
}
92+
93+
return <ReportActionItemBasicMessage message={translate('iou.forwarded')} />;
94+
}
95+
96+
return null;
97+
}
98+
99+
ApprovalFlowContent.displayName = 'ApprovalFlowContent';
100+
101+
export default ApprovalFlowContent;
102+
export {isApprovalFlowAction};

0 commit comments

Comments
 (0)