forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailsPage.js
executable file
·224 lines (205 loc) · 10.2 KB
/
DetailsPage.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import React from 'react';
import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import Str from 'expensify-common/lib/str';
import lodashGet from 'lodash/get';
import styles from '../styles/styles';
import Text from '../components/Text';
import ONYXKEYS from '../ONYXKEYS';
import Avatar from '../components/Avatar';
import HeaderWithCloseButton from '../components/HeaderWithCloseButton';
import Navigation from '../libs/Navigation/Navigation';
import ScreenWrapper from '../components/ScreenWrapper';
import personalDetailsPropType from './personalDetailsPropType';
import withLocalize, {withLocalizePropTypes} from '../components/withLocalize';
import compose from '../libs/compose';
import CommunicationsLink from '../components/CommunicationsLink';
import Tooltip from '../components/Tooltip';
import CONST from '../CONST';
import * as ReportUtils from '../libs/ReportUtils';
import * as Expensicons from '../components/Icon/Expensicons';
import MenuItem from '../components/MenuItem';
import AttachmentModal from '../components/AttachmentModal';
import PressableWithoutFocus from '../components/PressableWithoutFocus';
import * as Report from '../libs/actions/Report';
import OfflineWithFeedback from '../components/OfflineWithFeedback';
import AutoUpdateTime from '../components/AutoUpdateTime';
import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView';
const matchType = PropTypes.shape({
params: PropTypes.shape({
/** login passed via route /details/:login */
login: PropTypes.string,
/** report ID passed */
reportID: PropTypes.string,
}),
});
const propTypes = {
/* Onyx Props */
/** The personal details of the person who is logged in */
personalDetails: personalDetailsPropType,
/** Route params */
route: matchType.isRequired,
/** Session of currently logged in user */
session: PropTypes.shape({
email: PropTypes.string.isRequired,
}),
...withLocalizePropTypes,
};
const defaultProps = {
// When opening someone else's profile (via deep link) before login, this is empty
personalDetails: {},
session: {
email: null,
},
};
/**
* Gets the phone number to display for SMS logins
*
* @param {Object} details
* @param {String} details.login
* @param {String} details.displayName
* @returns {String}
*/
const getPhoneNumber = (details) => {
// If the user hasn't set a displayName, it is set to their phone number, so use that
if (Str.isValidPhone(details.displayName)) {
return details.displayName;
}
// If the user has set a displayName, get the phone number from the SMS login
return Str.removeSMSDomain(details.login);
};
class DetailsPage extends React.PureComponent {
render() {
const login = lodashGet(this.props.route.params, 'login', '');
const reportID = lodashGet(this.props.route.params, 'reportID', '');
let details = lodashGet(this.props.personalDetails, login);
if (!details) {
details = {
login,
displayName: ReportUtils.getDisplayNameForParticipant(login),
avatar: ReportUtils.getAvatar(lodashGet(details, 'avatar', ''), login),
};
}
const isSMSLogin = Str.isSMSLogin(details.login);
// If we have a reportID param this means that we
// arrived here via the ParticipantsPage and should be allowed to navigate back to it
const shouldShowBackButton = Boolean(reportID);
const shouldShowLocalTime = !ReportUtils.hasAutomatedExpensifyEmails([details.login]) && details.timezone;
let pronouns = details.pronouns;
if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) {
const localeKey = pronouns.replace(CONST.PRONOUNS.PREFIX, '');
pronouns = this.props.translate(`pronouns.${localeKey}`);
}
const phoneNumber = getPhoneNumber(details);
const displayName = isSMSLogin ? this.props.formatPhoneNumber(phoneNumber) : details.displayName;
const phoneOrEmail = isSMSLogin ? getPhoneNumber(details) : details.login;
return (
<ScreenWrapper>
<FullPageNotFoundView shouldShow={_.isEmpty(login)}>
<HeaderWithCloseButton
title={this.props.translate('common.details')}
shouldShowBackButton={shouldShowBackButton}
onBackButtonPress={() => Navigation.goBack()}
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<View
pointerEvents="box-none"
style={[
styles.containerWithSpaceBetween,
]}
>
{details ? (
<ScrollView>
<View style={styles.avatarSectionWrapper}>
<AttachmentModal
headerTitle={displayName}
source={ReportUtils.getFullSizeAvatar(details.avatar, details.login)}
isAuthTokenRequired
>
{({show}) => (
<PressableWithoutFocus
style={styles.noOutline}
onPress={show}
>
<OfflineWithFeedback
pendingAction={lodashGet(details, 'pendingFields.avatar', null)}
>
<Avatar
containerStyles={[styles.avatarLarge, styles.mb3]}
imageStyles={[styles.avatarLarge]}
source={ReportUtils.getAvatar(details.avatar, details.login)}
size={CONST.AVATAR_SIZE.LARGE}
/>
</OfflineWithFeedback>
</PressableWithoutFocus>
)}
</AttachmentModal>
{Boolean(details.displayName) && (
<Text style={[styles.textHeadline, styles.mb6, styles.pre]} numberOfLines={1}>
{displayName}
</Text>
)}
{details.login ? (
<View style={[styles.mb6, styles.detailsPageSectionContainer, styles.w100]}>
<Text style={[styles.textLabelSupporting, styles.mb1]} numberOfLines={1}>
{this.props.translate(isSMSLogin
? 'common.phoneNumber'
: 'common.email')}
</Text>
<CommunicationsLink
value={phoneOrEmail}
>
<Tooltip text={phoneOrEmail}>
<Text numberOfLines={1}>
{isSMSLogin
? this.props.formatPhoneNumber(phoneNumber)
: details.login}
</Text>
</Tooltip>
</CommunicationsLink>
</View>
) : null}
{pronouns ? (
<View style={[styles.mb6, styles.detailsPageSectionContainer]}>
<Text style={[styles.textLabelSupporting, styles.mb1]} numberOfLines={1}>
{this.props.translate('profilePage.preferredPronouns')}
</Text>
<Text numberOfLines={1}>
{pronouns}
</Text>
</View>
) : null}
{shouldShowLocalTime && <AutoUpdateTime timezone={details.timezone} />}
</View>
{details.login !== this.props.session.email && (
<MenuItem
title={`${this.props.translate('common.message')}${displayName}`}
icon={Expensicons.ChatBubble}
onPress={() => Report.navigateToAndOpenReport([details.login])}
wrapperStyle={styles.breakAll}
shouldShowRightIcon
/>
)}
</ScrollView>
) : null}
</View>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
}
DetailsPage.propTypes = propTypes;
DetailsPage.defaultProps = defaultProps;
export default compose(
withLocalize,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
}),
)(DetailsPage);