-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ReportParticipantsPage.js
executable file
·154 lines (142 loc) · 6.14 KB
/
ReportParticipantsPage.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
import React from 'react';
import _ from 'underscore';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import lodashGet from 'lodash/get';
import styles from '../styles/styles';
import ONYXKEYS from '../ONYXKEYS';
import HeaderWithBackButton from '../components/HeaderWithBackButton';
import Navigation from '../libs/Navigation/Navigation';
import ScreenWrapper from '../components/ScreenWrapper';
import OptionsList from '../components/OptionsList';
import ROUTES from '../ROUTES';
import personalDetailsPropType from './personalDetailsPropType';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import compose from '../libs/compose';
import * as ReportUtils from '../libs/ReportUtils';
import reportPropTypes from './reportPropTypes';
import withReportOrNotFound from './home/report/withReportOrNotFound';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
import CONST from '../CONST';
import * as UserUtils from '../libs/UserUtils';
import * as LocalePhoneNumber from '../libs/LocalePhoneNumber';
const propTypes = {
/* Onyx Props */
/** The personal details of the person who is logged in */
personalDetails: PropTypes.objectOf(personalDetailsPropType),
/** The active report */
report: reportPropTypes.isRequired,
/** Route params */
route: PropTypes.shape({
params: PropTypes.shape({
/** Report ID passed via route r/:reportID/participants */
reportID: PropTypes.string,
}),
}).isRequired,
...withLocalizePropTypes,
};
const defaultProps = {
personalDetails: {},
};
/**
* Returns all the participants in the active report
*
* @param {Object} report The active report object
* @param {Object} personalDetails The personal details of the users
* @param {Object} translate The localize
* @return {Array}
*/
const getAllParticipants = (report, personalDetails, translate) =>
_.chain(ReportUtils.getParticipantsIDs(report))
.map((accountID, index) => {
const userPersonalDetail = lodashGet(personalDetails, accountID, {displayName: personalDetails.displayName || translate('common.hidden'), avatar: ''});
const userLogin = LocalePhoneNumber.formatPhoneNumber(userPersonalDetail.login || '') || translate('common.hidden');
return {
alternateText: userLogin,
displayName: userPersonalDetail.displayName,
accountID: userPersonalDetail.accountID,
icons: [
{
id: accountID,
source: UserUtils.getAvatar(userPersonalDetail.avatar, accountID),
name: userLogin,
type: CONST.ICON_TYPE_AVATAR,
},
],
keyForList: `${index}-${userLogin}`,
login: userLogin,
text: userPersonalDetail.displayName,
tooltipText: userLogin,
participantsList: [{accountID, displayName: userPersonalDetail.displayName}],
};
})
.sortBy((participant) => participant.displayName.toLowerCase())
.value();
function ReportParticipantsPage(props) {
const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({
...participant,
isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
}));
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={ReportParticipantsPage.displayName}
>
{({safeAreaPaddingBottomStyle}) => (
<FullPageNotFoundView shouldShow={_.isEmpty(props.report) || ReportUtils.isArchivedRoom(props.report)}>
<HeaderWithBackButton
title={props.translate(
ReportUtils.isChatRoom(props.report) ||
ReportUtils.isPolicyExpenseChat(props.report) ||
ReportUtils.isChatThread(props.report) ||
ReportUtils.isTaskReport(props.report) ||
ReportUtils.isMoneyRequestReport(props.report)
? 'common.members'
: 'common.details',
)}
/>
<View
pointerEvents="box-none"
style={[styles.containerWithSpaceBetween]}
>
{Boolean(participants.length) && (
<OptionsList
sections={[
{
title: '',
data: participants,
shouldShow: true,
indexOffset: 0,
},
]}
onSelectRow={(option) => {
Navigation.navigate(ROUTES.PROFILE.getRoute(option.accountID));
}}
hideSectionHeaders
showTitleTooltip
showScrollIndicator
disableFocusOptions
boldStyle
optionHoveredStyle={styles.hoveredComponentBG}
contentContainerStyles={[safeAreaPaddingBottomStyle]}
/>
)}
</View>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
}
ReportParticipantsPage.propTypes = propTypes;
ReportParticipantsPage.defaultProps = defaultProps;
ReportParticipantsPage.displayName = 'ReportParticipantsPage';
export default compose(
withLocalize,
withReportOrNotFound(),
withOnyx({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
}),
)(ReportParticipantsPage);