-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathReportActionItemSingle.js
147 lines (131 loc) · 6.2 KB
/
ReportActionItemSingle.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
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
import lodashGet from 'lodash/get';
import React from 'react';
import {View, Pressable} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import reportActionPropTypes from './reportActionPropTypes';
import ReportActionItemFragment from './ReportActionItemFragment';
import styles from '../../../styles/styles';
import ReportActionItemDate from './ReportActionItemDate';
import Avatar from '../../../components/Avatar';
import personalDetailsPropType from '../../personalDetailsPropType';
import compose from '../../../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import Navigation from '../../../libs/Navigation/Navigation';
import ROUTES from '../../../ROUTES';
import {withPersonalDetails} from '../../../components/OnyxProvider';
import Tooltip from '../../../components/Tooltip';
import ControlSelection from '../../../libs/ControlSelection';
import * as ReportUtils from '../../../libs/ReportUtils';
import OfflineWithFeedback from '../../../components/OfflineWithFeedback';
import CONST from '../../../CONST';
import SubscriptAvatar from '../../../components/SubscriptAvatar';
import reportPropTypes from '../../reportPropTypes';
import * as UserUtils from '../../../libs/UserUtils';
const propTypes = {
/** All the data of the action */
action: PropTypes.shape(reportActionPropTypes).isRequired,
/** All of the personalDetails */
personalDetails: PropTypes.objectOf(personalDetailsPropType),
/** Styles for the outermost View */
// eslint-disable-next-line react/forbid-prop-types
wrapperStyles: PropTypes.arrayOf(PropTypes.object),
/** Children view component for this action item */
children: PropTypes.node.isRequired,
/** Report for this action */
report: reportPropTypes,
/** Show header for action */
showHeader: PropTypes.bool,
/** Determines if the avatar is displayed as a subscript (positioned lower than normal) */
shouldShowSubscriptAvatar: PropTypes.bool,
/** If the message has been flagged for moderation */
hasBeenFlagged: PropTypes.bool,
...withLocalizePropTypes,
};
const defaultProps = {
personalDetails: {},
wrapperStyles: [styles.chatItem],
showHeader: true,
shouldShowSubscriptAvatar: false,
hasBeenFlagged: false,
report: undefined,
};
const showUserDetails = (email) => {
Navigation.navigate(ROUTES.getDetailsRoute(email));
};
const ReportActionItemSingle = (props) => {
const actorEmail = props.action.actorEmail.replace(CONST.REGEX.MERGED_ACCOUNT_PREFIX, '');
const {avatar, displayName, pendingFields} = props.personalDetails[actorEmail] || {};
const avatarSource = UserUtils.getAvatar(avatar, actorEmail);
// Since the display name for a report action message is delivered with the report history as an array of fragments
// we'll need to take the displayName from personal details and have it be in the same format for now. Eventually,
// we should stop referring to the report history items entirely for this information.
const personArray = displayName
? [
{
type: 'TEXT',
text: displayName,
},
]
: props.action.person;
return (
<View style={props.wrapperStyles}>
<Pressable
style={[styles.alignSelfStart, styles.mr3]}
onPressIn={ControlSelection.block}
onPressOut={ControlSelection.unblock}
onPress={() => showUserDetails(actorEmail)}
>
<OfflineWithFeedback pendingAction={lodashGet(pendingFields, 'avatar', null)}>
{props.shouldShowSubscriptAvatar ? (
<SubscriptAvatar
mainAvatar={{source: avatarSource, type: CONST.ICON_TYPE_AVATAR}}
secondaryAvatar={ReportUtils.getIcons(props.report, {})[props.report.isOwnPolicyExpenseChat ? 0 : 1]}
mainTooltip={actorEmail}
secondaryTooltip={ReportUtils.getPolicyName(props.report)}
noMargin
/>
) : (
<Tooltip text={actorEmail}>
<View>
<Avatar
containerStyles={[styles.actionAvatar]}
source={avatarSource}
/>
</View>
</Tooltip>
)}
</OfflineWithFeedback>
</Pressable>
<View style={[styles.chatItemRight]}>
{props.showHeader ? (
<View style={[styles.chatItemMessageHeader]}>
<Pressable
style={[styles.flexShrink1, styles.mr1]}
onPressIn={ControlSelection.block}
onPressOut={ControlSelection.unblock}
onPress={() => showUserDetails(actorEmail)}
>
{_.map(personArray, (fragment, index) => (
<ReportActionItemFragment
key={`person-${props.action.reportActionID}-${index}`}
fragment={fragment}
tooltipText={actorEmail}
isAttachment={props.action.isAttachment}
isLoading={props.action.isLoading}
isSingleLine
/>
))}
</Pressable>
<ReportActionItemDate created={props.action.created} />
</View>
) : null}
<View style={props.hasBeenFlagged ? styles.blockquote : {}}>{props.children}</View>
</View>
</View>
);
};
ReportActionItemSingle.propTypes = propTypes;
ReportActionItemSingle.defaultProps = defaultProps;
ReportActionItemSingle.displayName = 'ReportActionItemSingle';
export default compose(withLocalize, withPersonalDetails())(ReportActionItemSingle);