forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportDetailsPage.js
205 lines (188 loc) · 8.29 KB
/
ReportDetailsPage.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
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
199
200
201
202
203
204
205
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import _ from 'underscore';
import {View, ScrollView} from 'react-native';
import lodashGet from 'lodash/get';
import Avatar from '../components/Avatar';
import compose from '../libs/compose';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import ONYXKEYS from '../ONYXKEYS';
import ScreenWrapper from '../components/ScreenWrapper';
import Navigation from '../libs/Navigation/Navigation';
import HeaderWithCloseButton from '../components/HeaderWithCloseButton';
import styles from '../styles/styles';
import DisplayNames from '../components/DisplayNames';
import * as OptionsListUtils from '../libs/OptionsListUtils';
import * as ReportUtils from '../libs/reportUtils';
import {participantPropTypes} from './home/sidebar/optionPropTypes';
import * as Expensicons from '../components/Icon/Expensicons';
import ROUTES from '../ROUTES';
import MenuItem from '../components/MenuItem';
import Text from '../components/Text';
const propTypes = {
...withLocalizePropTypes,
/** Whether or not to show the Compose Input */
session: PropTypes.shape({
accountID: PropTypes.number,
}).isRequired,
/** The report currently being looked at */
report: PropTypes.shape({
/** Name of the report */
reportName: PropTypes.string,
/** List of primarylogins of participants of the report */
participants: PropTypes.arrayOf(PropTypes.string),
/** List of icons for report participants */
icons: PropTypes.arrayOf(PropTypes.string),
/** ID of the report */
reportID: PropTypes.number,
}).isRequired,
/** The policies which the user has access to and which the report could be tied to */
policies: PropTypes.shape({
/** Name of the policy */
name: PropTypes.string,
}).isRequired,
/** Route params */
route: PropTypes.shape({
params: PropTypes.shape({
/** Report ID passed via route r/:reportID/details */
reportID: PropTypes.string,
}),
}).isRequired,
/** Personal details of all the users */
personalDetails: PropTypes.objectOf(participantPropTypes).isRequired,
};
class ReportDetailsPage extends Component {
constructor(props) {
super(props);
this.menuItems = [];
if (ReportUtils.isArchivedRoom(this.props.report)) {
return;
}
// All nonarchived chats should let you see their members
this.menuItems.push({
translationKey: 'common.members',
icon: Expensicons.Users,
subtitle: props.report.participants.length,
action: () => { Navigation.navigate(ROUTES.getReportParticipantsRoute(props.report.reportID)); },
});
// Chat rooms will allow you to more things than typical chats so they have extra options
if (ReportUtils.isChatRoom(this.props.report)) {
this.menuItems = this.menuItems.concat([
{
translationKey: 'common.settings',
icon: Expensicons.Gear,
action: () => { Navigation.navigate(ROUTES.getReportSettingsRoute(props.report.reportID)); },
},
{
translationKey: 'common.invite',
icon: Expensicons.Plus,
action: () => { /* Placeholder for when inviting other users is built in */ },
},
{
translationKey: 'common.leaveRoom',
icon: Expensicons.Exit,
action: () => { /* Placeholder for when leaving rooms is built in */ },
},
]);
}
}
render() {
const isChatRoom = ReportUtils.isChatRoom(this.props.report);
const chatRoomSubtitle = ReportUtils.getChatRoomSubtitle(this.props.report, this.props.policies);
const participants = lodashGet(this.props.report, 'participants', []);
const isMultipleParticipant = participants.length > 1;
const displayNamesWithTooltips = _.map(
OptionsListUtils.getPersonalDetailsForLogins(participants, this.props.personalDetails),
({displayName, firstName, login}) => {
const displayNameTrimmed = Str.isSMSLogin(login) ? this.props.toLocalPhone(displayName) : displayName;
return {
displayName: (isMultipleParticipant ? firstName : displayNameTrimmed) || Str.removeSMSDomain(login),
tooltip: Str.removeSMSDomain(login),
};
},
);
return (
<ScreenWrapper>
<HeaderWithCloseButton
title={this.props.translate('common.details')}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
onCloseButtonPress={() => Navigation.dismissModal(true)}
/>
<ScrollView style={[styles.flex1]}>
<View style={[styles.m5]}>
<View
style={styles.reportDetailsTitleContainer}
>
<Avatar
isChatRoom={isChatRoom}
isArchivedRoom={ReportUtils.isArchivedRoom(this.props.report)}
containerStyles={[styles.singleAvatarLarge, styles.mb4]}
imageStyles={[styles.singleAvatarLarge]}
source={this.props.report.icons[0]}
/>
<View style={[styles.reportDetailsRoomInfo, styles.mw100]}>
<View style={[styles.alignSelfCenter, styles.w100]}>
<DisplayNames
fullTitle={this.props.report.reportName}
displayNamesWithTooltips={displayNamesWithTooltips}
tooltipEnabled
numberOfLines={1}
textStyles={[styles.headerText, styles.mb2]}
shouldUseFullTitle={isChatRoom}
/>
</View>
<Text
style={[
styles.sidebarLinkText,
styles.optionAlternateText,
styles.textLabelSupporting,
styles.mb5,
]}
numberOfLines={1}
>
{chatRoomSubtitle}
</Text>
</View>
</View>
</View>
{_.map(this.menuItems, (item) => {
const keyTitle = item.translationKey ? this.props.translate(item.translationKey) : item.title;
return (
<MenuItem
key={keyTitle}
title={keyTitle}
subtitle={item.subtitle}
icon={item.icon}
onPress={item.action}
iconStyles={item.iconStyles}
iconFill={item.iconFill}
shouldShowRightIcon
/>
);
})}
</ScrollView>
</ScreenWrapper>
);
}
}
ReportDetailsPage.propTypes = propTypes;
export default compose(
withLocalize,
withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(ReportDetailsPage);