-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportActionItemParentAction.js
100 lines (89 loc) · 4.05 KB
/
ReportActionItemParentAction.js
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
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import withLocalize from '@components/withLocalize';
import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import reportPropTypes from '@pages/reportPropTypes';
import * as Report from '@userActions/Report';
import ONYXKEYS from '@src/ONYXKEYS';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import ReportActionItem from './ReportActionItem';
import reportActionPropTypes from './reportActionPropTypes';
const propTypes = {
/** Flag to show, hide the thread divider line */
shouldHideThreadDividerLine: PropTypes.bool,
/** The id of the report */
reportID: PropTypes.string.isRequired,
/** The id of the parent report */
// eslint-disable-next-line react/no-unused-prop-types
parentReportID: PropTypes.string.isRequired,
/** ONYX PROPS */
/** The report currently being looked at */
report: reportPropTypes,
/** The actions from the parent report */
// TO DO: Replace with HOC https://github.com/Expensify/App/issues/18769.
parentReportActions: PropTypes.objectOf(PropTypes.shape(reportActionPropTypes)),
...windowDimensionsPropTypes,
};
const defaultProps = {
report: {},
parentReportActions: {},
shouldHideThreadDividerLine: false,
};
function ReportActionItemParentAction(props) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const parentReportAction = props.parentReportActions[`${props.report.parentReportActionID}`];
// In case of transaction threads, we do not want to render the parent report action.
if (ReportActionsUtils.isTransactionThread(parentReportAction)) {
return null;
}
return (
<OfflineWithFeedback
shouldDisableOpacity={Boolean(lodashGet(parentReportAction, 'pendingAction'))}
pendingAction={lodashGet(props.report, 'pendingFields.addWorkspaceRoom') || lodashGet(props.report, 'pendingFields.createChat')}
errors={lodashGet(props.report, 'errorFields.addWorkspaceRoom') || lodashGet(props.report, 'errorFields.createChat')}
errorRowStyles={[styles.ml10, styles.mr2]}
onClose={() => Report.navigateToConciergeChatAndDeleteReport(props.report.reportID)}
>
<View style={StyleUtils.getReportWelcomeContainerStyle(props.isSmallScreenWidth)}>
<AnimatedEmptyStateBackground />
<View style={[styles.p5, StyleUtils.getReportWelcomeTopMarginStyle(props.isSmallScreenWidth)]} />
{parentReportAction && (
<ReportActionItem
report={props.report}
action={parentReportAction}
displayAsGroup={false}
isMostRecentIOUReportAction={false}
shouldDisplayNewMarker={props.shouldDisplayNewMarker}
index={0}
/>
)}
</View>
{!props.shouldHideThreadDividerLine && <View style={[styles.threadDividerLine]} />}
</OfflineWithFeedback>
);
}
ReportActionItemParentAction.defaultProps = defaultProps;
ReportActionItemParentAction.propTypes = propTypes;
ReportActionItemParentAction.displayName = 'ReportActionItemParentAction';
export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
parentReportActions: {
key: ({parentReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`,
canEvict: false,
},
}),
)(ReportActionItemParentAction);