-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ProfilePage.js
executable file
·190 lines (177 loc) · 8.06 KB
/
ProfilePage.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
import lodashGet from 'lodash/get';
import React, {useEffect} from 'react';
import {View, ScrollView} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import AvatarWithImagePicker from '../../../components/AvatarWithImagePicker';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
import MenuItem from '../../../components/MenuItem';
import MenuItemWithTopDescription from '../../../components/MenuItemWithTopDescription';
import ScreenWrapper from '../../../components/ScreenWrapper';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../../components/withCurrentUserPersonalDetails';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import CONST from '../../../CONST';
import * as PersonalDetails from '../../../libs/actions/PersonalDetails';
import compose from '../../../libs/compose';
import Navigation from '../../../libs/Navigation/Navigation';
import * as UserUtils from '../../../libs/UserUtils';
import ROUTES from '../../../ROUTES';
import styles from '../../../styles/styles';
import * as Expensicons from '../../../components/Icon/Expensicons';
import ONYXKEYS from '../../../ONYXKEYS';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import userPropTypes from '../userPropTypes';
import * as App from '../../../libs/actions/App';
import Permissions from '../../../libs/Permissions';
const propTypes = {
/* Onyx Props */
/** Login list for the user that is signed in */
loginList: PropTypes.objectOf(
PropTypes.shape({
/** Date login was validated, used to show brickroad info status */
validatedDate: PropTypes.string,
/** Field-specific server side errors keyed by microtime */
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
}),
),
user: userPropTypes,
...withLocalizePropTypes,
...windowDimensionsPropTypes,
...withCurrentUserPersonalDetailsPropTypes,
};
const defaultProps = {
loginList: {},
user: {},
...withCurrentUserPersonalDetailsDefaultProps,
};
function ProfilePage(props) {
const getPronouns = () => {
let pronounsKey = lodashGet(props.currentUserPersonalDetails, 'pronouns', '');
if (pronounsKey.startsWith(CONST.PRONOUNS.PREFIX)) {
pronounsKey = pronounsKey.slice(CONST.PRONOUNS.PREFIX.length);
}
if (!pronounsKey) {
return props.translate('profilePage.selectYourPronouns');
}
return props.translate(`pronouns.${pronounsKey}`);
};
const currentUserDetails = props.currentUserPersonalDetails || {};
const contactMethodBrickRoadIndicator = UserUtils.getLoginListBrickRoadIndicator(props.loginList);
const avatarURL = lodashGet(currentUserDetails, 'avatar', '');
const accountID = lodashGet(currentUserDetails, 'accountID', '');
const emojiCode = lodashGet(props, 'currentUserPersonalDetails.status.emojiCode', '');
const profileSettingsOptions = [
{
description: props.translate('displayNamePage.headerTitle'),
title: lodashGet(currentUserDetails, 'displayName', ''),
pageRoute: ROUTES.SETTINGS_DISPLAY_NAME,
},
{
description: props.translate('contacts.contactMethod'),
title: props.formatPhoneNumber(lodashGet(currentUserDetails, 'login', '')),
pageRoute: ROUTES.SETTINGS_CONTACT_METHODS,
brickRoadIndicator: contactMethodBrickRoadIndicator,
},
...(Permissions.canUseCustomStatus(props.betas)
? [
{
description: props.translate('statusPage.status'),
title: emojiCode ? `${emojiCode} ${lodashGet(props, 'currentUserPersonalDetails.status.text', '')}` : '',
pageRoute: ROUTES.SETTINGS_STATUS,
},
]
: []),
{
description: props.translate('pronounsPage.pronouns'),
title: getPronouns(),
pageRoute: ROUTES.SETTINGS_PRONOUNS,
},
{
description: props.translate('timezonePage.timezone'),
title: `${lodashGet(currentUserDetails, 'timezone.selected', '')}`,
pageRoute: ROUTES.SETTINGS_TIMEZONE,
},
];
useEffect(() => {
App.openProfile(props.currentUserPersonalDetails);
}, [props.currentUserPersonalDetails]);
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={ProfilePage.displayName}
>
<HeaderWithBackButton
title={props.translate('common.profile')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS)}
/>
<ScrollView>
<AvatarWithImagePicker
isUsingDefaultAvatar={UserUtils.isDefaultAvatar(lodashGet(currentUserDetails, 'avatar', ''))}
source={UserUtils.getAvatar(avatarURL, accountID)}
onImageSelected={PersonalDetails.updateAvatar}
onImageRemoved={PersonalDetails.deleteAvatar}
anchorPosition={styles.createMenuPositionProfile(props.windowWidth)}
anchorAlignment={{horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.LEFT, vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.TOP}}
size={CONST.AVATAR_SIZE.LARGE}
pendingAction={lodashGet(props.currentUserPersonalDetails, 'pendingFields.avatar', null)}
errors={lodashGet(props.currentUserPersonalDetails, 'errorFields.avatar', null)}
errorRowStyles={[styles.mt6]}
onErrorClose={PersonalDetails.clearAvatarErrors}
previewSource={UserUtils.getFullSizeAvatar(avatarURL, accountID)}
originalFileName={currentUserDetails.originalFileName}
headerTitle={props.translate('profilePage.profileAvatar')}
style={[styles.mh5]}
fallbackIcon={lodashGet(currentUserDetails, 'fallbackIcon')}
/>
<View style={[styles.mt4]}>
{_.map(profileSettingsOptions, (detail, index) => (
<MenuItemWithTopDescription
key={`${detail.title}_${index}`}
shouldShowRightIcon
title={detail.title}
description={detail.description}
onPress={() => Navigation.navigate(detail.pageRoute)}
brickRoadIndicator={detail.brickRoadIndicator}
/>
))}
</View>
<MenuItem
title={props.translate('privatePersonalDetails.personalDetails')}
icon={Expensicons.User}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_PERSONAL_DETAILS)}
shouldShowRightIcon
/>
{props.user.hasLoungeAccess && (
<MenuItem
title={props.translate('loungeAccessPage.loungeAccess')}
icon={Expensicons.LoungeAccess}
iconWidth={40}
iconHeight={40}
onPress={() => Navigation.navigate(ROUTES.SETTINGS_LOUNGE_ACCESS)}
shouldShowRightIcon
/>
)}
</ScrollView>
</ScreenWrapper>
);
}
ProfilePage.propTypes = propTypes;
ProfilePage.defaultProps = defaultProps;
ProfilePage.displayName = 'ProfilePage';
export default compose(
withLocalize,
withWindowDimensions,
withCurrentUserPersonalDetails,
withOnyx({
loginList: {
key: ONYXKEYS.LOGIN_LIST,
},
user: {
key: ONYXKEYS.USER,
},
betas: {
key: ONYXKEYS.BETAS,
},
}),
)(ProfilePage);