2018-06-05 01:17:02 +00:00
|
|
|
import React from 'react';
|
2018-06-13 01:33:00 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-02-27 14:26:40 +00:00
|
|
|
import { View, ScrollView, Keyboard } from 'react-native';
|
2018-06-13 01:33:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
2020-03-03 20:27:38 +00:00
|
|
|
import prompt from 'react-native-prompt-android';
|
2018-06-13 01:33:00 +00:00
|
|
|
import SHA256 from 'js-sha256';
|
2018-07-17 19:10:27 +00:00
|
|
|
import ImagePicker from 'react-native-image-crop-picker';
|
2018-06-13 01:33:00 +00:00
|
|
|
import RNPickerSelect from 'react-native-picker-select';
|
2020-10-30 13:12:02 +00:00
|
|
|
import { isEqual, omit } from 'lodash';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
import Touch from '../../utils/touch';
|
2018-06-13 01:33:00 +00:00
|
|
|
import KeyboardView from '../../presentation/KeyboardView';
|
|
|
|
import sharedStyles from '../Styles';
|
|
|
|
import styles from './styles';
|
|
|
|
import scrollPersistTaps from '../../utils/scrollPersistTaps';
|
2020-08-25 16:51:49 +00:00
|
|
|
import { showErrorAlert, showConfirmationAlert } from '../../utils/info';
|
2019-07-23 14:02:57 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
|
|
|
import EventEmitter from '../../utils/events';
|
2018-06-13 01:33:00 +00:00
|
|
|
import RocketChat from '../../lib/rocketchat';
|
|
|
|
import RCTextInput from '../../containers/TextInput';
|
2020-07-30 13:26:17 +00:00
|
|
|
import log, { logEvent, events } from '../../utils/log';
|
2018-06-13 01:33:00 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import Button from '../../containers/Button';
|
|
|
|
import Avatar from '../../containers/Avatar';
|
2018-12-12 15:15:10 +00:00
|
|
|
import { setUser as setUserAction } from '../../actions/login';
|
2019-03-01 16:49:11 +00:00
|
|
|
import { CustomIcon } from '../../lib/Icons';
|
2020-08-21 13:30:11 +00:00
|
|
|
import { DrawerButton, PreferencesButton } from '../../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2019-12-04 16:39:53 +00:00
|
|
|
import { themes } from '../../constants/colors';
|
|
|
|
import { withTheme } from '../../theme';
|
2020-02-11 14:09:14 +00:00
|
|
|
import { getUserSelector } from '../../selectors/login';
|
2020-06-15 14:00:46 +00:00
|
|
|
import SafeAreaView from '../../containers/SafeAreaView';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2019-08-07 13:51:34 +00:00
|
|
|
class ProfileView extends React.Component {
|
2020-06-15 14:00:46 +00:00
|
|
|
static navigationOptions = ({ navigation, isMasterDetail }) => {
|
|
|
|
const options = {
|
|
|
|
title: I18n.t('Profile')
|
|
|
|
};
|
|
|
|
if (!isMasterDetail) {
|
|
|
|
options.headerLeft = () => <DrawerButton navigation={navigation} />;
|
|
|
|
}
|
2020-08-21 13:30:11 +00:00
|
|
|
options.headerRight = () => (
|
2020-08-21 18:14:06 +00:00
|
|
|
<PreferencesButton onPress={() => navigation.navigate('UserPreferencesView')} testID='preferences-view-open' />
|
2020-08-21 13:30:11 +00:00
|
|
|
);
|
2020-06-15 14:00:46 +00:00
|
|
|
return options;
|
|
|
|
}
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
static propTypes = {
|
2018-09-11 16:32:52 +00:00
|
|
|
baseUrl: PropTypes.string,
|
2018-06-13 01:33:00 +00:00
|
|
|
user: PropTypes.object,
|
2020-02-20 18:26:42 +00:00
|
|
|
Accounts_AllowEmailChange: PropTypes.bool,
|
|
|
|
Accounts_AllowPasswordChange: PropTypes.bool,
|
|
|
|
Accounts_AllowRealNameChange: PropTypes.bool,
|
|
|
|
Accounts_AllowUserAvatarChange: PropTypes.bool,
|
|
|
|
Accounts_AllowUsernameChange: PropTypes.bool,
|
2018-11-27 19:40:53 +00:00
|
|
|
Accounts_CustomFields: PropTypes.string,
|
2019-12-04 16:39:53 +00:00
|
|
|
setUser: PropTypes.func,
|
|
|
|
theme: PropTypes.string
|
2018-07-10 13:40:32 +00:00
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2019-05-28 13:03:08 +00:00
|
|
|
state = {
|
|
|
|
saving: false,
|
|
|
|
name: null,
|
|
|
|
username: null,
|
|
|
|
email: null,
|
|
|
|
newPassword: null,
|
|
|
|
currentPassword: null,
|
|
|
|
avatarUrl: null,
|
|
|
|
avatar: {},
|
|
|
|
avatarSuggestions: {},
|
|
|
|
customFields: {}
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount() {
|
|
|
|
this.init();
|
|
|
|
|
|
|
|
try {
|
|
|
|
const result = await RocketChat.getAvatarSuggestion();
|
|
|
|
this.setState({ avatarSuggestions: result });
|
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-08 16:37:49 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { user } = this.props;
|
2020-10-30 13:12:02 +00:00
|
|
|
/*
|
|
|
|
* We need to ignore status because on Android ImagePicker
|
|
|
|
* changes the activity, so, the user status changes and
|
|
|
|
* it's resetting the avatar right after
|
|
|
|
* select some image from gallery.
|
|
|
|
*/
|
|
|
|
if (!isEqual(omit(user, ['status']), omit(nextProps.user, ['status']))) {
|
2018-06-13 01:33:00 +00:00
|
|
|
this.init(nextProps.user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 10:55:35 +00:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2020-10-30 13:12:02 +00:00
|
|
|
if (!isEqual(nextState, this.state)) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-10-30 13:12:02 +00:00
|
|
|
if (!isEqual(nextProps, this.props)) {
|
2018-12-21 10:55:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
setAvatar = (avatar) => {
|
2020-02-20 18:26:42 +00:00
|
|
|
const { Accounts_AllowUserAvatarChange } = this.props;
|
|
|
|
|
|
|
|
if (!Accounts_AllowUserAvatarChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-10 13:40:32 +00:00
|
|
|
this.setState({ avatar });
|
|
|
|
}
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
init = (user) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { user: userProps } = this.props;
|
2018-06-13 01:33:00 +00:00
|
|
|
const {
|
|
|
|
name, username, emails, customFields
|
2018-09-25 19:28:42 +00:00
|
|
|
} = user || userProps;
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
this.setState({
|
|
|
|
name,
|
|
|
|
username,
|
|
|
|
email: emails ? emails[0].address : null,
|
|
|
|
newPassword: null,
|
2018-12-12 15:15:10 +00:00
|
|
|
currentPassword: null,
|
2018-06-13 01:33:00 +00:00
|
|
|
avatarUrl: null,
|
|
|
|
avatar: {},
|
|
|
|
customFields: customFields || {}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
formIsChanged = () => {
|
|
|
|
const {
|
|
|
|
name, username, email, newPassword, avatar, customFields
|
|
|
|
} = this.state;
|
|
|
|
const { user } = this.props;
|
|
|
|
let customFieldsChanged = false;
|
|
|
|
|
|
|
|
const customFieldsKeys = Object.keys(customFields);
|
|
|
|
if (customFieldsKeys.length) {
|
|
|
|
customFieldsKeys.forEach((key) => {
|
2018-12-12 15:15:10 +00:00
|
|
|
if (!user.customFields || user.customFields[key] !== customFields[key]) {
|
2018-06-13 01:33:00 +00:00
|
|
|
customFieldsChanged = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
return !(user.name === name
|
|
|
|
&& user.username === username
|
|
|
|
&& !newPassword
|
|
|
|
&& (user.emails && user.emails[0].address === email)
|
|
|
|
&& !avatar.data
|
|
|
|
&& !customFieldsChanged
|
2018-06-13 01:33:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleError = (e, func, action) => {
|
2020-03-17 16:26:32 +00:00
|
|
|
if (e.data && e.data.error.includes('[error-too-many-requests]')) {
|
2018-12-12 15:15:10 +00:00
|
|
|
return showErrorAlert(e.data.error);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
2020-03-03 20:27:38 +00:00
|
|
|
showErrorAlert(I18n.t('There_was_an_error_while_action', { action: I18n.t(action) }));
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
submit = async() => {
|
|
|
|
Keyboard.dismiss();
|
|
|
|
|
|
|
|
if (!this.formIsChanged()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-21 16:38:26 +00:00
|
|
|
this.setState({ saving: true });
|
2018-06-13 01:33:00 +00:00
|
|
|
|
|
|
|
const {
|
2018-12-12 15:15:10 +00:00
|
|
|
name, username, email, newPassword, currentPassword, avatar, customFields
|
2018-06-13 01:33:00 +00:00
|
|
|
} = this.state;
|
2018-12-12 15:15:10 +00:00
|
|
|
const { user, setUser } = this.props;
|
2018-06-13 01:33:00 +00:00
|
|
|
const params = {};
|
|
|
|
|
|
|
|
// Name
|
|
|
|
if (user.name !== name) {
|
2018-12-12 15:15:10 +00:00
|
|
|
params.name = name;
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Username
|
|
|
|
if (user.username !== username) {
|
|
|
|
params.username = username;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Email
|
|
|
|
if (user.emails && user.emails[0].address !== email) {
|
|
|
|
params.email = email;
|
|
|
|
}
|
|
|
|
|
|
|
|
// newPassword
|
|
|
|
if (newPassword) {
|
|
|
|
params.newPassword = newPassword;
|
|
|
|
}
|
|
|
|
|
2018-12-12 15:15:10 +00:00
|
|
|
// currentPassword
|
|
|
|
if (currentPassword) {
|
|
|
|
params.currentPassword = SHA256(currentPassword);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const requirePassword = !!params.email || newPassword;
|
2018-12-12 15:15:10 +00:00
|
|
|
if (requirePassword && !params.currentPassword) {
|
2020-03-03 20:27:38 +00:00
|
|
|
this.setState({ saving: false });
|
|
|
|
prompt(
|
|
|
|
I18n.t('Please_enter_your_password'),
|
|
|
|
I18n.t('For_your_security_you_must_enter_your_current_password_to_continue'),
|
|
|
|
[
|
|
|
|
{ text: I18n.t('Cancel'), onPress: () => {}, style: 'cancel' },
|
|
|
|
{
|
|
|
|
text: I18n.t('Save'),
|
|
|
|
onPress: (p) => {
|
|
|
|
this.setState({ currentPassword: p });
|
|
|
|
this.submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{
|
|
|
|
type: 'secure-text',
|
|
|
|
cancelable: false
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return;
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (avatar.url) {
|
|
|
|
try {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_SAVE_AVATAR);
|
2018-06-13 01:33:00 +00:00
|
|
|
await RocketChat.setAvatarFromService(avatar);
|
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_SAVE_AVATAR_F);
|
2018-12-12 15:15:10 +00:00
|
|
|
this.setState({ saving: false, currentPassword: null });
|
|
|
|
return this.handleError(e, 'setAvatarFromService', 'changing_avatar');
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:29:07 +00:00
|
|
|
const result = await RocketChat.saveUserProfile(params, customFields);
|
2018-12-12 15:15:10 +00:00
|
|
|
|
|
|
|
if (result.success) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_SAVE_CHANGES);
|
2019-06-05 16:29:07 +00:00
|
|
|
if (customFields) {
|
|
|
|
setUser({ customFields, ...params });
|
|
|
|
} else {
|
|
|
|
setUser({ ...params });
|
2018-12-12 15:15:10 +00:00
|
|
|
}
|
2019-07-23 14:02:57 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Profile_saved_successfully') });
|
2018-06-13 01:33:00 +00:00
|
|
|
this.init();
|
2018-12-12 15:15:10 +00:00
|
|
|
}
|
2020-04-01 20:32:24 +00:00
|
|
|
this.setState({ saving: false });
|
2018-06-13 01:33:00 +00:00
|
|
|
} catch (e) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_SAVE_CHANGES_F);
|
2018-12-12 15:15:10 +00:00
|
|
|
this.setState({ saving: false, currentPassword: null });
|
|
|
|
this.handleError(e, 'saveUserProfile', 'saving_profile');
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resetAvatar = async() => {
|
2020-02-20 18:26:42 +00:00
|
|
|
const { Accounts_AllowUserAvatarChange } = this.props;
|
|
|
|
|
|
|
|
if (!Accounts_AllowUserAvatarChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
try {
|
2018-12-12 15:15:10 +00:00
|
|
|
const { user } = this.props;
|
|
|
|
await RocketChat.resetAvatar(user.id);
|
2019-07-23 14:02:57 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Avatar_changed_successfully') });
|
2018-06-13 01:33:00 +00:00
|
|
|
this.init();
|
|
|
|
} catch (e) {
|
|
|
|
this.handleError(e, 'resetAvatar', 'changing_avatar');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:10:27 +00:00
|
|
|
pickImage = async() => {
|
2020-02-20 18:26:42 +00:00
|
|
|
const { Accounts_AllowUserAvatarChange } = this.props;
|
|
|
|
|
|
|
|
if (!Accounts_AllowUserAvatarChange) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
const options = {
|
2018-07-17 19:10:27 +00:00
|
|
|
cropping: true,
|
|
|
|
compressImageQuality: 0.8,
|
2020-10-30 15:54:44 +00:00
|
|
|
freeStyleCropEnabled: true,
|
2018-07-17 19:10:27 +00:00
|
|
|
cropperAvoidEmptySpaceAroundImage: false,
|
|
|
|
cropperChooseText: I18n.t('Choose'),
|
|
|
|
cropperCancelText: I18n.t('Cancel'),
|
|
|
|
includeBase64: true
|
2018-06-13 01:33:00 +00:00
|
|
|
};
|
2018-07-17 19:10:27 +00:00
|
|
|
try {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_PICK_AVATAR);
|
2018-07-17 19:10:27 +00:00
|
|
|
const response = await ImagePicker.openPicker(options);
|
|
|
|
this.setAvatar({ url: response.path, data: `data:image/jpeg;base64,${ response.data }`, service: 'upload' });
|
|
|
|
} catch (error) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_PICK_AVATAR_F);
|
2018-07-17 19:10:27 +00:00
|
|
|
console.warn(error);
|
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
2020-07-30 13:26:17 +00:00
|
|
|
pickImageWithURL = (avatarUrl) => {
|
|
|
|
logEvent(events.PROFILE_PICK_AVATAR_WITH_URL);
|
|
|
|
this.setAvatar({ url: avatarUrl, data: avatarUrl, service: 'url' });
|
|
|
|
}
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
renderAvatarButton = ({
|
|
|
|
key, child, onPress, disabled = false
|
2019-12-04 16:39:53 +00:00
|
|
|
}) => {
|
|
|
|
const { theme } = this.props;
|
|
|
|
return (
|
|
|
|
<Touch
|
|
|
|
key={key}
|
|
|
|
testID={key}
|
|
|
|
onPress={onPress}
|
|
|
|
style={[styles.avatarButton, { opacity: disabled ? 0.5 : 1 }, { backgroundColor: themes[theme].borderColor }]}
|
|
|
|
enabled={!disabled}
|
|
|
|
theme={theme}
|
2018-06-13 01:33:00 +00:00
|
|
|
>
|
|
|
|
{child}
|
2019-12-04 16:39:53 +00:00
|
|
|
</Touch>
|
|
|
|
);
|
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2018-09-25 19:28:42 +00:00
|
|
|
renderAvatarButtons = () => {
|
|
|
|
const { avatarUrl, avatarSuggestions } = this.state;
|
2020-02-20 18:26:42 +00:00
|
|
|
const {
|
|
|
|
user,
|
|
|
|
theme,
|
|
|
|
Accounts_AllowUserAvatarChange
|
|
|
|
} = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<View style={styles.avatarButtons}>
|
|
|
|
{this.renderAvatarButton({
|
2020-10-30 13:12:02 +00:00
|
|
|
child: <Avatar text={`@${ user.username }`} size={50} />,
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress: () => this.resetAvatar(),
|
2020-02-20 18:26:42 +00:00
|
|
|
disabled: !Accounts_AllowUserAvatarChange,
|
2018-09-25 19:28:42 +00:00
|
|
|
key: 'profile-view-reset-avatar'
|
|
|
|
})}
|
|
|
|
{this.renderAvatarButton({
|
2019-12-04 16:39:53 +00:00
|
|
|
child: <CustomIcon name='upload' size={30} color={themes[theme].bodyText} />,
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress: () => this.pickImage(),
|
2020-02-20 18:26:42 +00:00
|
|
|
disabled: !Accounts_AllowUserAvatarChange,
|
2018-09-25 19:28:42 +00:00
|
|
|
key: 'profile-view-upload-avatar'
|
|
|
|
})}
|
|
|
|
{this.renderAvatarButton({
|
2020-06-05 13:28:58 +00:00
|
|
|
child: <CustomIcon name='link' size={30} color={themes[theme].bodyText} />,
|
2020-07-30 13:26:17 +00:00
|
|
|
onPress: () => this.pickImageWithURL(avatarUrl),
|
2018-09-25 19:28:42 +00:00
|
|
|
disabled: !avatarUrl,
|
|
|
|
key: 'profile-view-avatar-url-button'
|
|
|
|
})}
|
|
|
|
{Object.keys(avatarSuggestions).map((service) => {
|
|
|
|
const { url, blob, contentType } = avatarSuggestions[service];
|
|
|
|
return this.renderAvatarButton({
|
2020-02-20 18:26:42 +00:00
|
|
|
disabled: !Accounts_AllowUserAvatarChange,
|
2018-09-25 19:28:42 +00:00
|
|
|
key: `profile-view-avatar-${ service }`,
|
2020-10-30 13:12:02 +00:00
|
|
|
child: <Avatar avatar={url} size={50} />,
|
2018-09-25 19:28:42 +00:00
|
|
|
onPress: () => this.setAvatar({
|
|
|
|
url, data: blob, service, contentType
|
|
|
|
})
|
|
|
|
});
|
|
|
|
})}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2018-06-13 01:33:00 +00:00
|
|
|
|
|
|
|
renderCustomFields = () => {
|
|
|
|
const { customFields } = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const { Accounts_CustomFields, theme } = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
|
|
|
if (!Accounts_CustomFields) {
|
2018-06-13 01:33:00 +00:00
|
|
|
return null;
|
|
|
|
}
|
2018-12-12 15:15:10 +00:00
|
|
|
try {
|
|
|
|
const parsedCustomFields = JSON.parse(Accounts_CustomFields);
|
|
|
|
return Object.keys(parsedCustomFields).map((key, index, array) => {
|
|
|
|
if (parsedCustomFields[key].type === 'select') {
|
|
|
|
const options = parsedCustomFields[key].options.map(option => ({ label: option, value: option }));
|
|
|
|
return (
|
|
|
|
<RNPickerSelect
|
|
|
|
key={key}
|
|
|
|
items={options}
|
|
|
|
onValueChange={(value) => {
|
|
|
|
const newValue = {};
|
|
|
|
newValue[key] = value;
|
|
|
|
this.setState({ customFields: { ...customFields, ...newValue } });
|
|
|
|
}}
|
|
|
|
value={customFields[key]}
|
|
|
|
>
|
|
|
|
<RCTextInput
|
|
|
|
inputRef={(e) => { this[key] = e; }}
|
|
|
|
label={key}
|
|
|
|
placeholder={key}
|
|
|
|
value={customFields[key]}
|
|
|
|
testID='settings-view-language'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-12-12 15:15:10 +00:00
|
|
|
/>
|
|
|
|
</RNPickerSelect>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
return (
|
2018-12-12 15:15:10 +00:00
|
|
|
<RCTextInput
|
|
|
|
inputRef={(e) => { this[key] = e; }}
|
2018-06-13 01:33:00 +00:00
|
|
|
key={key}
|
2018-12-12 15:15:10 +00:00
|
|
|
label={key}
|
|
|
|
placeholder={key}
|
|
|
|
value={customFields[key]}
|
|
|
|
onChangeText={(value) => {
|
2018-06-13 01:33:00 +00:00
|
|
|
const newValue = {};
|
|
|
|
newValue[key] = value;
|
2018-09-25 19:28:42 +00:00
|
|
|
this.setState({ customFields: { ...customFields, ...newValue } });
|
2018-06-13 01:33:00 +00:00
|
|
|
}}
|
2018-12-12 15:15:10 +00:00
|
|
|
onSubmitEditing={() => {
|
|
|
|
if (array.length - 1 > index) {
|
|
|
|
return this[array[index + 1]].focus();
|
|
|
|
}
|
|
|
|
this.avatarUrl.focus();
|
|
|
|
}}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-12-12 15:15:10 +00:00
|
|
|
/>
|
2018-06-13 01:33:00 +00:00
|
|
|
);
|
2018-12-12 15:15:10 +00:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-06-05 01:17:02 +00:00
|
|
|
}
|
|
|
|
|
2020-08-25 16:51:49 +00:00
|
|
|
logoutOtherLocations = () => {
|
|
|
|
logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS);
|
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('You_will_be_logged_out_from_other_locations'),
|
|
|
|
callToAction: I18n.t('Logout'),
|
|
|
|
onPress: async() => {
|
|
|
|
try {
|
|
|
|
await RocketChat.logoutOtherLocations();
|
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Logged_out_of_other_clients_successfully') });
|
|
|
|
} catch {
|
|
|
|
logEvent(events.PROFILE_LOGOUT_OTHER_LOCATIONS_F);
|
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Logout_failed') });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-05 01:17:02 +00:00
|
|
|
render() {
|
2018-06-13 01:33:00 +00:00
|
|
|
const {
|
2020-03-03 20:27:38 +00:00
|
|
|
name, username, email, newPassword, avatarUrl, customFields, avatar, saving
|
2018-06-13 01:33:00 +00:00
|
|
|
} = this.state;
|
2019-12-04 16:39:53 +00:00
|
|
|
const {
|
2020-02-20 18:26:42 +00:00
|
|
|
user,
|
|
|
|
theme,
|
|
|
|
Accounts_AllowEmailChange,
|
|
|
|
Accounts_AllowPasswordChange,
|
|
|
|
Accounts_AllowRealNameChange,
|
|
|
|
Accounts_AllowUserAvatarChange,
|
|
|
|
Accounts_AllowUsernameChange,
|
|
|
|
Accounts_CustomFields
|
2019-12-04 16:39:53 +00:00
|
|
|
} = this.props;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-06-05 01:17:02 +00:00
|
|
|
return (
|
2018-06-13 01:33:00 +00:00
|
|
|
<KeyboardView
|
2019-12-04 16:39:53 +00:00
|
|
|
style={{ backgroundColor: themes[theme].auxiliaryBackground }}
|
2018-06-13 01:33:00 +00:00
|
|
|
contentContainerStyle={sharedStyles.container}
|
|
|
|
keyboardVerticalOffset={128}
|
|
|
|
>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
|
|
|
<SafeAreaView testID='profile-view'>
|
2019-12-04 16:39:53 +00:00
|
|
|
<ScrollView
|
|
|
|
contentContainerStyle={sharedStyles.containerScrollView}
|
|
|
|
testID='profile-view-list'
|
|
|
|
{...scrollPersistTaps}
|
|
|
|
>
|
2018-06-13 01:33:00 +00:00
|
|
|
<View style={styles.avatarContainer} testID='profile-view-avatar'>
|
|
|
|
<Avatar
|
2020-10-30 13:12:02 +00:00
|
|
|
text={user.username}
|
|
|
|
avatar={avatar?.url}
|
|
|
|
isStatic={avatar?.url}
|
2018-06-13 01:33:00 +00:00
|
|
|
size={100}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<RCTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowRealNameChange}
|
|
|
|
inputStyle={[
|
|
|
|
!Accounts_AllowRealNameChange && styles.disabled
|
|
|
|
]}
|
2018-06-13 01:33:00 +00:00
|
|
|
inputRef={(e) => { this.name = e; }}
|
|
|
|
label={I18n.t('Name')}
|
|
|
|
placeholder={I18n.t('Name')}
|
|
|
|
value={name}
|
|
|
|
onChangeText={value => this.setState({ name: value })}
|
|
|
|
onSubmitEditing={() => { this.username.focus(); }}
|
|
|
|
testID='profile-view-name'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-06-13 01:33:00 +00:00
|
|
|
/>
|
|
|
|
<RCTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowUsernameChange}
|
|
|
|
inputStyle={[
|
|
|
|
!Accounts_AllowUsernameChange && styles.disabled
|
|
|
|
]}
|
2018-06-13 01:33:00 +00:00
|
|
|
inputRef={(e) => { this.username = e; }}
|
|
|
|
label={I18n.t('Username')}
|
|
|
|
placeholder={I18n.t('Username')}
|
|
|
|
value={username}
|
|
|
|
onChangeText={value => this.setState({ username: value })}
|
|
|
|
onSubmitEditing={() => { this.email.focus(); }}
|
|
|
|
testID='profile-view-username'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-06-13 01:33:00 +00:00
|
|
|
/>
|
|
|
|
<RCTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowEmailChange}
|
|
|
|
inputStyle={[
|
|
|
|
!Accounts_AllowEmailChange && styles.disabled
|
|
|
|
]}
|
2018-06-13 01:33:00 +00:00
|
|
|
inputRef={(e) => { this.email = e; }}
|
|
|
|
label={I18n.t('Email')}
|
|
|
|
placeholder={I18n.t('Email')}
|
|
|
|
value={email}
|
|
|
|
onChangeText={value => this.setState({ email: value })}
|
|
|
|
onSubmitEditing={() => { this.newPassword.focus(); }}
|
|
|
|
testID='profile-view-email'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-06-13 01:33:00 +00:00
|
|
|
/>
|
|
|
|
<RCTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowPasswordChange}
|
|
|
|
inputStyle={[
|
|
|
|
!Accounts_AllowPasswordChange && styles.disabled
|
|
|
|
]}
|
2018-06-13 01:33:00 +00:00
|
|
|
inputRef={(e) => { this.newPassword = e; }}
|
|
|
|
label={I18n.t('New_Password')}
|
|
|
|
placeholder={I18n.t('New_Password')}
|
|
|
|
value={newPassword}
|
|
|
|
onChangeText={value => this.setState({ newPassword: value })}
|
|
|
|
onSubmitEditing={() => {
|
2019-11-13 19:53:20 +00:00
|
|
|
if (Accounts_CustomFields && Object.keys(customFields).length) {
|
2018-06-13 01:33:00 +00:00
|
|
|
return this[Object.keys(customFields)[0]].focus();
|
|
|
|
}
|
|
|
|
this.avatarUrl.focus();
|
|
|
|
}}
|
|
|
|
secureTextEntry
|
|
|
|
testID='profile-view-new-password'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-06-13 01:33:00 +00:00
|
|
|
/>
|
|
|
|
{this.renderCustomFields()}
|
|
|
|
<RCTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowUserAvatarChange}
|
|
|
|
inputStyle={[
|
|
|
|
!Accounts_AllowUserAvatarChange && styles.disabled
|
|
|
|
]}
|
2018-06-13 01:33:00 +00:00
|
|
|
inputRef={(e) => { this.avatarUrl = e; }}
|
|
|
|
label={I18n.t('Avatar_Url')}
|
|
|
|
placeholder={I18n.t('Avatar_Url')}
|
|
|
|
value={avatarUrl}
|
|
|
|
onChangeText={value => this.setState({ avatarUrl: value })}
|
|
|
|
onSubmitEditing={this.submit}
|
|
|
|
testID='profile-view-avatar-url'
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-06-13 01:33:00 +00:00
|
|
|
/>
|
|
|
|
{this.renderAvatarButtons()}
|
2018-12-12 15:15:10 +00:00
|
|
|
<Button
|
|
|
|
title={I18n.t('Save_Changes')}
|
|
|
|
type='primary'
|
|
|
|
onPress={this.submit}
|
|
|
|
disabled={!this.formIsChanged()}
|
|
|
|
testID='profile-view-submit'
|
|
|
|
loading={saving}
|
2019-12-04 16:39:53 +00:00
|
|
|
theme={theme}
|
2018-12-12 15:15:10 +00:00
|
|
|
/>
|
2020-08-25 16:51:49 +00:00
|
|
|
<Button
|
|
|
|
title={I18n.t('Logout_from_other_logged_in_locations')}
|
|
|
|
type='secondary'
|
|
|
|
backgroundColor={themes[theme].chatComponentBackground}
|
|
|
|
onPress={this.logoutOtherLocations}
|
|
|
|
testID='profile-view-logout-other-locations'
|
|
|
|
theme={theme}
|
|
|
|
/>
|
2019-12-04 16:39:53 +00:00
|
|
|
</ScrollView>
|
|
|
|
</SafeAreaView>
|
2018-06-13 01:33:00 +00:00
|
|
|
</KeyboardView>
|
2018-06-05 01:17:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-08-07 13:51:34 +00:00
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
user: getUserSelector(state),
|
2020-02-20 18:26:42 +00:00
|
|
|
Accounts_AllowEmailChange: state.settings.Accounts_AllowEmailChange,
|
|
|
|
Accounts_AllowPasswordChange: state.settings.Accounts_AllowPasswordChange,
|
|
|
|
Accounts_AllowRealNameChange: state.settings.Accounts_AllowRealNameChange,
|
|
|
|
Accounts_AllowUserAvatarChange: state.settings.Accounts_AllowUserAvatarChange,
|
|
|
|
Accounts_AllowUsernameChange: state.settings.Accounts_AllowUsernameChange,
|
2019-08-07 13:51:34 +00:00
|
|
|
Accounts_CustomFields: state.settings.Accounts_CustomFields,
|
2020-02-11 14:09:14 +00:00
|
|
|
baseUrl: state.server.server
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
setUser: params => dispatch(setUserAction(params))
|
|
|
|
});
|
|
|
|
|
2019-12-04 16:39:53 +00:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(withTheme(ProfileView));
|