-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
DetailsPage.js
executable file
·215 lines (199 loc) · 9.93 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
import React from 'react';
import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
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 DateUtils from '../libs/DateUtils';
import * as Expensicons from '../components/Icon/Expensicons';
import FullscreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
import MenuItem from '../components/MenuItem';
import AttachmentModal from '../components/AttachmentModal';
import PressableWithoutFocus from '../components/PressableWithoutFocus';
import * as Report from '../libs/actions/Report';
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.isRequired,
/** Route params */
route: matchType.isRequired,
...withLocalizePropTypes,
};
/**
* 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 {
componentDidMount() {
if (lodashGet(this.props.route.params, 'login')) {
return;
}
Navigation.dismissModal();
}
render() {
const details = this.props.personalDetails[lodashGet(this.props.route.params, 'login')];
if (!details) {
// Personal details have not loaded yet
return <FullscreenLoadingIndicator />;
}
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(this.props.route.params.reportID);
const timezone = DateUtils.getLocalMomentFromTimestamp(this.props.preferredLocale, null, details.timezone.selected);
const GMTTime = `${timezone.toString().split(/[+-]/)[0].slice(-3)} ${timezone.zoneAbbr()}`;
const currentTime = Number.isNaN(Number(timezone.zoneAbbr())) ? timezone.zoneAbbr() : GMTTime;
const shouldShowLocalTime = !ReportUtils.hasExpensifyEmails([details.login]);
let pronouns = details.pronouns;
if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) {
const localeKey = pronouns.replace(CONST.PRONOUNS.PREFIX, '');
pronouns = this.props.translate(`pronouns.${localeKey}`);
}
return (
<ScreenWrapper>
<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.pageWrapper}>
<AttachmentModal
headerTitle={isSMSLogin ? this.props.toLocalPhone(details.displayName) : details.displayName}
sourceURL={details.avatar}
isAuthTokenRequired
>
{({show}) => (
<PressableWithoutFocus
style={styles.noOutline}
onPress={show}
>
<Avatar
containerStyles={[styles.avatarLarge, styles.mb3]}
imageStyles={[styles.avatarLarge]}
source={details.avatar}
size={CONST.AVATAR_SIZE.LARGE}
/>
</PressableWithoutFocus>
)}
</AttachmentModal>
{details.displayName && (
<Text style={[styles.displayName, styles.mb6]} numberOfLines={1}>
{isSMSLogin ? this.props.toLocalPhone(details.displayName) : details.displayName}
</Text>
)}
{details.login ? (
<View style={[styles.mb6, styles.detailsPageSectionContainer, styles.w100]}>
<Text style={[styles.formLabel, styles.mb2]} numberOfLines={1}>
{this.props.translate(isSMSLogin
? 'common.phoneNumber'
: 'common.email')}
</Text>
<CommunicationsLink
type={isSMSLogin ? CONST.LOGIN_TYPE.PHONE : CONST.LOGIN_TYPE.EMAIL}
value={isSMSLogin ? getPhoneNumber(details) : details.login}
>
<Tooltip text={isSMSLogin ? getPhoneNumber(details) : details.login}>
<Text numberOfLines={1}>
{isSMSLogin
? this.props.toLocalPhone(getPhoneNumber(details))
: details.login}
</Text>
</Tooltip>
</CommunicationsLink>
</View>
) : null}
{pronouns ? (
<View style={[styles.mb6, styles.detailsPageSectionContainer]}>
<Text style={[styles.formLabel, styles.mb2]} numberOfLines={1}>
{this.props.translate('profilePage.preferredPronouns')}
</Text>
<Text numberOfLines={1}>
{pronouns}
</Text>
</View>
) : null}
{shouldShowLocalTime && details.timezone ? (
<View style={[styles.mb6, styles.detailsPageSectionContainer]}>
<Text style={[styles.formLabel, styles.mb2]} numberOfLines={1}>
{this.props.translate('detailsPage.localTime')}
</Text>
<Text numberOfLines={1}>
{timezone.format('LT')}
{' '}
{currentTime}
</Text>
</View>
) : null}
</View>
{details.login !== this.props.session.email && (
<MenuItem
title={`${this.props.translate('common.message')}${details.displayName}`}
icon={Expensicons.ChatBubble}
onPress={() => Report.fetchOrCreateChatReport([this.props.session.email, details.login])}
wrapperStyle={styles.breakAll}
shouldShowRightIcon
/>
)}
</ScrollView>
) : null}
</View>
</ScreenWrapper>
);
}
}
DetailsPage.propTypes = propTypes;
DetailsPage.displayName = 'DetailsPage';
export default compose(
withLocalize,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS,
},
}),
)(DetailsPage);