-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportActionItemContentCreated.tsx
198 lines (177 loc) · 8.21 KB
/
ReportActionItemContentCreated.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import lodashIsEqual from 'lodash/isEqual';
import React, {memo, useMemo} from 'react';
import {View} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import RenderHTML from '@components/RenderHTML';
import MoneyReportView from '@components/ReportActionItem/MoneyReportView';
import MoneyRequestView from '@components/ReportActionItem/MoneyRequestView';
import TaskView from '@components/ReportActionItem/TaskView';
import {ShowContextMenuContext} from '@components/ShowContextMenuContext';
import type {ShowContextMenuContextProps} from '@components/ShowContextMenuContext';
import SpacerView from '@components/SpacerView';
import UnreadActionIndicator from '@components/UnreadActionIndicator';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import ReportActionItemCreated from './ReportActionItemCreated';
import ReportActionItemSingle from './ReportActionItemSingle';
type ReportActionItemContentCreatedProps = {
/** The context value containing the report and action data, along with the show context menu props */
contextValue: ShowContextMenuContextProps & {
report: OnyxTypes.Report;
action: OnyxTypes.ReportAction;
};
/** Report action belonging to the report's parent */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;
/** The transaction ID */
transactionID: string | undefined;
/** The draft message */
draftMessage: string | undefined;
/** Flag to show, hide the thread divider line */
shouldHideThreadDividerLine: boolean;
};
function ReportActionItemContentCreated({contextValue, parentReportAction, transactionID, draftMessage, shouldHideThreadDividerLine}: ReportActionItemContentCreatedProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {report, action, transactionThreadReport} = contextValue;
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report.policyID ?? '-1'}`);
const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID ?? '-1'}`);
const transactionCurrency = TransactionUtils.getCurrency(transaction);
const renderThreadDivider = useMemo(
() =>
shouldHideThreadDividerLine ? (
<UnreadActionIndicator
reportActionID={report.reportID}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
/>
) : (
<SpacerView
shouldShow={!shouldHideThreadDividerLine}
style={[!shouldHideThreadDividerLine ? styles.reportHorizontalRule : {}]}
/>
),
[shouldHideThreadDividerLine, report.reportID, styles.reportHorizontalRule],
);
if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
const isReversedTransaction = ReportActionsUtils.isReversedTransaction(parentReportAction);
if (ReportActionsUtils.isMessageDeleted(parentReportAction) || isReversedTransaction) {
let message: TranslationPaths;
if (isReversedTransaction) {
message = 'parentReportAction.reversedTransaction';
} else {
message = 'parentReportAction.deletedExpense';
}
return (
<View style={[styles.pRelative]}>
<AnimatedEmptyStateBackground />
<OfflineWithFeedback pendingAction={parentReportAction?.pendingAction ?? null}>
<ReportActionItemSingle
action={parentReportAction}
showHeader
report={report}
>
<RenderHTML html={`<comment>${translate(message)}</comment>`} />
</ReportActionItemSingle>
<View style={styles.threadDividerLine} />
</OfflineWithFeedback>
</View>
);
}
return (
<ShowContextMenuContext.Provider value={contextValue}>
<View>
<MoneyRequestView
report={report}
shouldShowAnimatedBackground
/>
{renderThreadDivider}
</View>
</ShowContextMenuContext.Provider>
);
}
if (ReportUtils.isTaskReport(report)) {
if (ReportUtils.isCanceledTaskReport(report, parentReportAction)) {
return (
<View style={[styles.pRelative]}>
<AnimatedEmptyStateBackground />
<OfflineWithFeedback pendingAction={parentReportAction?.pendingAction}>
<ReportActionItemSingle
action={parentReportAction}
showHeader={draftMessage === undefined}
report={report}
>
<RenderHTML html={`<comment>${translate('parentReportAction.deletedTask')}</comment>`} />
</ReportActionItemSingle>
</OfflineWithFeedback>
<View style={styles.reportHorizontalRule} />
</View>
);
}
return (
<View style={[styles.pRelative]}>
<AnimatedEmptyStateBackground />
<View>
<TaskView report={report} />
{renderThreadDivider}
</View>
</View>
);
}
if (ReportUtils.isExpenseReport(report) || ReportUtils.isIOUReport(report) || ReportUtils.isInvoiceReport(report)) {
return (
<OfflineWithFeedback pendingAction={action.pendingAction}>
{transactionThreadReport && !isEmptyObject(transactionThreadReport) ? (
<>
<MoneyReportView
report={report}
policy={policy}
isCombinedReport
shouldShowTotal={transactionCurrency !== report.currency}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
/>
<ShowContextMenuContext.Provider value={contextValue}>
<View>
<MoneyRequestView
report={transactionThreadReport}
shouldShowAnimatedBackground={false}
/>
{renderThreadDivider}
</View>
</ShowContextMenuContext.Provider>
</>
) : (
<MoneyReportView
report={report}
policy={policy}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
/>
)}
</OfflineWithFeedback>
);
}
return (
<ReportActionItemCreated
reportID={report.reportID}
policyID={report.policyID}
/>
);
}
ReportActionItemContentCreated.displayName = 'ReportActionItemContentCreated';
export default memo(
ReportActionItemContentCreated,
(prevProps, nextProps) =>
lodashIsEqual(prevProps.contextValue, nextProps.contextValue) &&
lodashIsEqual(prevProps.parentReportAction, nextProps.parentReportAction) &&
prevProps.transactionID === nextProps.transactionID &&
prevProps.draftMessage === nextProps.draftMessage &&
prevProps.shouldHideThreadDividerLine === nextProps.shouldHideThreadDividerLine,
);