2018-06-05 01:17:02 +00:00
|
|
|
import React from 'react';
|
2022-05-07 02:11:07 +00:00
|
|
|
import { Keyboard, ScrollView, TextInput, View } from 'react-native';
|
2018-06-13 01:33:00 +00:00
|
|
|
import { connect } from 'react-redux';
|
2021-11-10 15:10:34 +00:00
|
|
|
import { sha256 } from 'js-sha256';
|
2018-06-13 01:33:00 +00:00
|
|
|
import RNPickerSelect from 'react-native-picker-select';
|
2021-02-26 16:01:45 +00:00
|
|
|
import { dequal } from 'dequal';
|
2021-02-01 17:18:55 +00:00
|
|
|
import omit from 'lodash/omit';
|
2021-11-10 15:10:34 +00:00
|
|
|
import { StackNavigationOptions } from '@react-navigation/stack';
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2022-08-17 13:32:21 +00:00
|
|
|
import Touch from '../../containers/Touch';
|
2022-04-13 20:43:56 +00:00
|
|
|
import KeyboardView from '../../containers/KeyboardView';
|
2018-06-13 01:33:00 +00:00
|
|
|
import sharedStyles from '../Styles';
|
2022-06-06 14:17:51 +00:00
|
|
|
import scrollPersistTaps from '../../lib/methods/helpers/scrollPersistTaps';
|
2023-04-10 14:59:00 +00:00
|
|
|
import { showErrorAlert, showConfirmationAlert } from '../../lib/methods/helpers';
|
2019-07-23 14:02:57 +00:00
|
|
|
import { LISTENER } from '../../containers/Toast';
|
2022-06-06 14:17:51 +00:00
|
|
|
import EventEmitter from '../../lib/methods/helpers/events';
|
2022-06-27 18:46:59 +00:00
|
|
|
import { FormTextInput } from '../../containers/TextInput';
|
2023-04-10 14:59:00 +00:00
|
|
|
import { events, logEvent } from '../../lib/methods/helpers/log';
|
2018-06-13 01:33:00 +00:00
|
|
|
import I18n from '../../i18n';
|
|
|
|
import Button from '../../containers/Button';
|
2023-04-10 14:59:00 +00:00
|
|
|
import { AvatarWithEdit } from '../../containers/Avatar';
|
2022-05-07 02:11:07 +00:00
|
|
|
import { setUser } from '../../actions/login';
|
2020-10-30 16:15:58 +00:00
|
|
|
import * as HeaderButton from '../../containers/HeaderButton';
|
2019-03-12 16:23:06 +00:00
|
|
|
import StatusBar from '../../containers/StatusBar';
|
2022-04-07 14:10:03 +00:00
|
|
|
import { themes } from '../../lib/constants';
|
2022-05-07 02:11:07 +00:00
|
|
|
import { TSupportedThemes, 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';
|
2021-09-13 20:41:05 +00:00
|
|
|
import styles from './styles';
|
2022-05-07 02:11:07 +00:00
|
|
|
import { ProfileStackParamList } from '../../stacks/types';
|
|
|
|
import { Services } from '../../lib/services';
|
2023-04-10 14:59:00 +00:00
|
|
|
import { IApplicationState, IAvatarButton, IBaseScreen, IProfileParams, IUser } from '../../definitions';
|
2022-06-23 19:59:57 +00:00
|
|
|
import { twoFactor } from '../../lib/services/twoFactor';
|
|
|
|
import { TwoFactorMethods } from '../../definitions/ITotp';
|
2022-06-22 12:24:25 +00:00
|
|
|
import { withActionSheet, IActionSheetProvider } from '../../containers/ActionSheet';
|
|
|
|
import { DeleteAccountActionSheetContent } from './components/DeleteAccountActionSheetContent';
|
2022-06-27 19:03:24 +00:00
|
|
|
import ActionSheetContentWithInputAndSubmit from '../../containers/ActionSheet/ActionSheetContentWithInputAndSubmit';
|
2022-05-07 02:11:07 +00:00
|
|
|
|
2022-06-22 12:24:25 +00:00
|
|
|
interface IProfileViewProps extends IActionSheetProvider, IBaseScreen<ProfileStackParamList, 'ProfileView'> {
|
2022-05-07 02:11:07 +00:00
|
|
|
user: IUser;
|
|
|
|
baseUrl: string;
|
|
|
|
Accounts_AllowEmailChange: boolean;
|
|
|
|
Accounts_AllowPasswordChange: boolean;
|
|
|
|
Accounts_AllowRealNameChange: boolean;
|
|
|
|
Accounts_AllowUserAvatarChange: boolean;
|
|
|
|
Accounts_AllowUsernameChange: boolean;
|
|
|
|
Accounts_CustomFields: string;
|
|
|
|
theme: TSupportedThemes;
|
2022-06-22 12:24:25 +00:00
|
|
|
Accounts_AllowDeleteOwnAccount: boolean;
|
|
|
|
isMasterDetail: boolean;
|
2022-05-07 02:11:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IProfileViewState {
|
|
|
|
saving: boolean;
|
|
|
|
name: string;
|
|
|
|
username: string;
|
|
|
|
email: string | null;
|
|
|
|
newPassword: string | null;
|
|
|
|
currentPassword: string | null;
|
|
|
|
customFields: {
|
|
|
|
[key: string | number]: string;
|
|
|
|
};
|
2022-06-23 19:59:57 +00:00
|
|
|
twoFactorCode: null | {
|
|
|
|
twoFactorCode: string;
|
|
|
|
twoFactorMethod: string;
|
|
|
|
};
|
2022-05-07 02:11:07 +00:00
|
|
|
}
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2021-11-10 15:10:34 +00:00
|
|
|
class ProfileView extends React.Component<IProfileViewProps, IProfileViewState> {
|
2022-05-07 02:11:07 +00:00
|
|
|
private name?: TextInput | null;
|
|
|
|
private username?: TextInput | null;
|
|
|
|
private email?: TextInput;
|
|
|
|
private avatarUrl?: TextInput;
|
|
|
|
private newPassword?: TextInput;
|
2021-11-10 15:10:34 +00:00
|
|
|
|
2022-06-22 12:24:25 +00:00
|
|
|
setHeader = () => {
|
|
|
|
const { navigation, isMasterDetail } = this.props;
|
2021-11-10 15:10:34 +00:00
|
|
|
const options: StackNavigationOptions = {
|
2020-06-15 14:00:46 +00:00
|
|
|
title: I18n.t('Profile')
|
|
|
|
};
|
|
|
|
if (!isMasterDetail) {
|
2020-10-30 16:15:58 +00:00
|
|
|
options.headerLeft = () => <HeaderButton.Drawer navigation={navigation} />;
|
2020-06-15 14:00:46 +00:00
|
|
|
}
|
2020-08-21 13:30:11 +00:00
|
|
|
options.headerRight = () => (
|
2021-11-10 15:10:34 +00:00
|
|
|
<HeaderButton.Preferences onPress={() => navigation?.navigate('UserPreferencesView')} testID='preferences-view-open' />
|
2020-08-21 13:30:11 +00:00
|
|
|
);
|
2022-06-22 12:24:25 +00:00
|
|
|
|
|
|
|
navigation.setOptions(options);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-10-23 21:39:48 +00:00
|
|
|
|
2022-06-22 12:24:25 +00:00
|
|
|
constructor(props: IProfileViewProps) {
|
|
|
|
super(props);
|
|
|
|
this.setHeader();
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:10:34 +00:00
|
|
|
state: IProfileViewState = {
|
2019-05-28 13:03:08 +00:00
|
|
|
saving: false,
|
2021-11-10 15:10:34 +00:00
|
|
|
name: '',
|
|
|
|
username: '',
|
|
|
|
email: '',
|
|
|
|
newPassword: '',
|
|
|
|
currentPassword: '',
|
2022-06-23 19:59:57 +00:00
|
|
|
customFields: {},
|
|
|
|
twoFactorCode: null
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2023-04-10 14:59:00 +00:00
|
|
|
componentDidMount() {
|
2018-06-13 01:33:00 +00:00
|
|
|
this.init();
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:10:34 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(nextProps: IProfileViewProps) {
|
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.
|
|
|
|
*/
|
2021-02-26 16:01:45 +00:00
|
|
|
if (!dequal(omit(user, ['status']), omit(nextProps.user, ['status']))) {
|
2018-06-13 01:33:00 +00:00
|
|
|
this.init(nextProps.user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:10:34 +00:00
|
|
|
init = (user?: IUser) => {
|
2018-09-25 19:28:42 +00:00
|
|
|
const { user: userProps } = this.props;
|
2021-09-13 20:41:05 +00:00
|
|
|
const { name, username, emails, customFields } = user || userProps;
|
2018-09-25 19:28:42 +00:00
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
this.setState({
|
2022-04-07 16:27:45 +00:00
|
|
|
name: name as string,
|
2018-06-13 01:33:00 +00:00
|
|
|
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
|
|
|
customFields: customFields || {}
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
|
|
|
formIsChanged = () => {
|
2023-04-10 14:59:00 +00:00
|
|
|
const { name, username, email, newPassword, customFields } = this.state;
|
2018-06-13 01:33:00 +00:00
|
|
|
const { user } = this.props;
|
|
|
|
let customFieldsChanged = false;
|
|
|
|
|
|
|
|
const customFieldsKeys = Object.keys(customFields);
|
|
|
|
if (customFieldsKeys.length) {
|
2021-09-13 20:41:05 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
return !(
|
|
|
|
user.name === name &&
|
|
|
|
user.username === username &&
|
|
|
|
!newPassword &&
|
|
|
|
user.emails &&
|
|
|
|
user.emails[0].address === email &&
|
|
|
|
!customFieldsChanged
|
2018-06-13 01:33:00 +00:00
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2022-06-23 19:59:57 +00:00
|
|
|
submit = async (): Promise<void> => {
|
2018-06-13 01:33:00 +00:00
|
|
|
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
|
|
|
|
2023-04-10 14:59:00 +00:00
|
|
|
const { name, username, email, newPassword, currentPassword, customFields, twoFactorCode } = this.state;
|
2022-05-07 02:11:07 +00:00
|
|
|
const { user, dispatch } = this.props;
|
|
|
|
const params = {} as IProfileParams;
|
2018-06-13 01:33:00 +00:00
|
|
|
|
|
|
|
// Name
|
|
|
|
if (user.name !== name) {
|
2022-09-16 15:04:25 +00:00
|
|
|
params.realname = 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) {
|
2021-11-10 15:10:34 +00:00
|
|
|
params.currentPassword = sha256(currentPassword);
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const requirePassword = !!params.email || newPassword;
|
2022-06-27 19:03:24 +00:00
|
|
|
|
2018-12-12 15:15:10 +00:00
|
|
|
if (requirePassword && !params.currentPassword) {
|
2020-03-03 20:27:38 +00:00
|
|
|
this.setState({ saving: false });
|
2022-06-27 19:03:24 +00:00
|
|
|
this.props.showActionSheet({
|
|
|
|
children: (
|
|
|
|
<ActionSheetContentWithInputAndSubmit
|
|
|
|
title={I18n.t('Please_enter_your_password')}
|
|
|
|
description={I18n.t('For_your_security_you_must_enter_your_current_password_to_continue')}
|
|
|
|
testID='profile-view-enter-password-sheet'
|
|
|
|
placeholder={I18n.t('Password')}
|
|
|
|
onSubmit={(p: string) => {
|
|
|
|
this.props.hideActionSheet();
|
|
|
|
this.setState({ currentPassword: p }, () => this.submit());
|
|
|
|
}}
|
|
|
|
onCancel={this.props.hideActionSheet}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
headerHeight: 225
|
|
|
|
});
|
2020-03-03 20:27:38 +00:00
|
|
|
return;
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-06-23 19:59:57 +00:00
|
|
|
const twoFactorOptions = params.currentPassword
|
|
|
|
? {
|
|
|
|
twoFactorCode: params.currentPassword,
|
|
|
|
twoFactorMethod: TwoFactorMethods.PASSWORD
|
|
|
|
}
|
|
|
|
: null;
|
2018-12-12 15:15:10 +00:00
|
|
|
|
2022-06-23 19:59:57 +00:00
|
|
|
const result = await Services.saveUserProfileMethod(params, customFields, twoFactorCode || twoFactorOptions);
|
|
|
|
|
|
|
|
if (result) {
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_SAVE_CHANGES);
|
2023-06-19 23:41:04 +00:00
|
|
|
if ('realname' in params) {
|
|
|
|
params.name = params.realname;
|
|
|
|
delete params.realname;
|
|
|
|
}
|
2019-06-05 16:29:07 +00:00
|
|
|
if (customFields) {
|
2022-05-07 02:11:07 +00:00
|
|
|
dispatch(setUser({ customFields, ...params }));
|
2019-06-05 16:29:07 +00:00
|
|
|
} else {
|
2022-05-07 02:11:07 +00:00
|
|
|
dispatch(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
|
|
|
}
|
2022-06-23 19:59:57 +00:00
|
|
|
this.setState({ saving: false, currentPassword: null, twoFactorCode: null });
|
|
|
|
} catch (e: any) {
|
|
|
|
if (e?.error === 'totp-invalid' && e?.details.method !== TwoFactorMethods.PASSWORD) {
|
|
|
|
try {
|
|
|
|
const code = await twoFactor({ method: e?.details.method, invalid: e?.error === 'totp-invalid' && !!twoFactorCode });
|
|
|
|
return this.setState({ twoFactorCode: code }, () => this.submit());
|
|
|
|
} catch {
|
|
|
|
// cancelled twoFactor modal
|
|
|
|
}
|
|
|
|
}
|
2020-07-30 13:26:17 +00:00
|
|
|
logEvent(events.PROFILE_SAVE_CHANGES_F);
|
2022-06-23 19:59:57 +00:00
|
|
|
this.setState({ saving: false, currentPassword: null, twoFactorCode: null });
|
2023-04-10 14:59:00 +00:00
|
|
|
this.handleError(e, 'saving_profile');
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2021-09-13 20:41:05 +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;
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.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) {
|
2023-04-10 14:59:00 +00:00
|
|
|
this.handleError(e, 'changing_avatar');
|
2018-06-13 01:33:00 +00:00
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2023-04-10 14:59:00 +00:00
|
|
|
handleError = (e: any, action: string) => {
|
|
|
|
if (e.data && e.data.error.includes('[error-too-many-requests]')) {
|
|
|
|
return showErrorAlert(e.data.error);
|
2020-02-20 18:26:42 +00:00
|
|
|
}
|
2023-04-10 14:59:00 +00:00
|
|
|
if (I18n.isTranslated(e.error)) {
|
|
|
|
return showErrorAlert(I18n.t(e.error));
|
2018-07-17 19:10:27 +00:00
|
|
|
}
|
2023-04-10 14:59:00 +00:00
|
|
|
showErrorAlert(I18n.t('There_was_an_error_while_action', { action: I18n.t(action) }));
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
2023-04-10 14:59:00 +00:00
|
|
|
handleEditAvatar = () => {
|
|
|
|
const { navigation } = this.props;
|
|
|
|
navigation.navigate('ChangeAvatarView', { context: 'profile' });
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-07-30 13:26:17 +00:00
|
|
|
|
2021-11-10 15:10:34 +00:00
|
|
|
renderAvatarButton = ({ key, child, onPress, disabled = false }: IAvatarButton) => {
|
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}
|
2022-08-08 21:02:08 +00:00
|
|
|
>
|
2018-06-13 01:33:00 +00:00
|
|
|
{child}
|
2019-12-04 16:39:53 +00:00
|
|
|
</Touch>
|
|
|
|
);
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-13 01:33:00 +00:00
|
|
|
|
|
|
|
renderCustomFields = () => {
|
|
|
|
const { customFields } = this.state;
|
2022-06-27 18:46:59 +00:00
|
|
|
const { Accounts_CustomFields } = 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') {
|
2021-11-10 15:10:34 +00:00
|
|
|
const options = parsedCustomFields[key].options.map((option: string) => ({ label: option, value: option }));
|
2018-12-12 15:15:10 +00:00
|
|
|
return (
|
|
|
|
<RNPickerSelect
|
|
|
|
key={key}
|
|
|
|
items={options}
|
2021-09-13 20:41:05 +00:00
|
|
|
onValueChange={value => {
|
2021-11-10 15:10:34 +00:00
|
|
|
const newValue: { [key: string]: string } = {};
|
2018-12-12 15:15:10 +00:00
|
|
|
newValue[key] = value;
|
|
|
|
this.setState({ customFields: { ...customFields, ...newValue } });
|
|
|
|
}}
|
2022-08-08 21:02:08 +00:00
|
|
|
value={customFields[key]}
|
|
|
|
>
|
2022-05-18 19:17:42 +00:00
|
|
|
<FormTextInput
|
2021-09-13 20:41:05 +00:00
|
|
|
inputRef={e => {
|
2021-11-10 15:10:34 +00:00
|
|
|
// @ts-ignore
|
2021-09-13 20:41:05 +00:00
|
|
|
this[key] = e;
|
|
|
|
}}
|
2018-12-12 15:15:10 +00:00
|
|
|
label={key}
|
|
|
|
placeholder={key}
|
|
|
|
value={customFields[key]}
|
|
|
|
testID='settings-view-language'
|
|
|
|
/>
|
|
|
|
</RNPickerSelect>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-13 01:33:00 +00:00
|
|
|
return (
|
2022-05-18 19:17:42 +00:00
|
|
|
<FormTextInput
|
2021-09-13 20:41:05 +00:00
|
|
|
inputRef={e => {
|
2021-11-10 15:10:34 +00:00
|
|
|
// @ts-ignore
|
2021-09-13 20:41:05 +00:00
|
|
|
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]}
|
2021-09-13 20:41:05 +00:00
|
|
|
onChangeText={value => {
|
2021-11-10 15:10:34 +00:00
|
|
|
const newValue: { [key: string]: string } = {};
|
2018-06-13 01:33:00 +00:00
|
|
|
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) {
|
2021-11-10 15:10:34 +00:00
|
|
|
// @ts-ignore
|
2018-12-12 15:15:10 +00:00
|
|
|
return this[array[index + 1]].focus();
|
|
|
|
}
|
2022-05-07 02:11:07 +00:00
|
|
|
this.avatarUrl?.focus();
|
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;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2018-06-05 01:17:02 +00:00
|
|
|
|
2020-08-25 16:51:49 +00:00
|
|
|
logoutOtherLocations = () => {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.PL_OTHER_LOCATIONS);
|
2020-08-25 16:51:49 +00:00
|
|
|
showConfirmationAlert({
|
|
|
|
message: I18n.t('You_will_be_logged_out_from_other_locations'),
|
2021-02-01 17:23:21 +00:00
|
|
|
confirmationText: I18n.t('Logout'),
|
2021-09-13 20:41:05 +00:00
|
|
|
onPress: async () => {
|
2020-08-25 16:51:49 +00:00
|
|
|
try {
|
2022-04-28 20:37:25 +00:00
|
|
|
await Services.logoutOtherLocations();
|
2020-08-25 16:51:49 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Logged_out_of_other_clients_successfully') });
|
|
|
|
} catch {
|
2021-02-11 21:44:50 +00:00
|
|
|
logEvent(events.PL_OTHER_LOCATIONS_F);
|
2020-08-25 16:51:49 +00:00
|
|
|
EventEmitter.emit(LISTENER, { message: I18n.t('Logout_failed') });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-09-13 20:41:05 +00:00
|
|
|
};
|
2020-08-25 16:51:49 +00:00
|
|
|
|
2022-06-22 12:24:25 +00:00
|
|
|
deleteOwnAccount = () => {
|
|
|
|
logEvent(events.DELETE_OWN_ACCOUNT);
|
|
|
|
this.props.showActionSheet({
|
|
|
|
children: <DeleteAccountActionSheetContent />,
|
|
|
|
headerHeight: 225
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-06-05 01:17:02 +00:00
|
|
|
render() {
|
2023-04-10 14:59:00 +00:00
|
|
|
const { name, username, email, newPassword, customFields, saving } = 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,
|
2022-06-22 12:24:25 +00:00
|
|
|
Accounts_CustomFields,
|
|
|
|
Accounts_AllowDeleteOwnAccount
|
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}
|
2022-08-08 21:02:08 +00:00
|
|
|
keyboardVerticalOffset={128}
|
|
|
|
>
|
2020-10-30 13:59:44 +00:00
|
|
|
<StatusBar />
|
|
|
|
<SafeAreaView testID='profile-view'>
|
2021-09-13 20:41:05 +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'>
|
2023-04-10 14:59:00 +00:00
|
|
|
<AvatarWithEdit
|
|
|
|
text={user.username}
|
|
|
|
handleEdit={Accounts_AllowUserAvatarChange ? this.handleEditAvatar : undefined}
|
|
|
|
/>
|
2018-06-13 01:33:00 +00:00
|
|
|
</View>
|
2022-05-18 19:17:42 +00:00
|
|
|
<FormTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowRealNameChange}
|
2021-09-13 20:41:05 +00:00
|
|
|
inputStyle={[!Accounts_AllowRealNameChange && styles.disabled]}
|
|
|
|
inputRef={e => {
|
|
|
|
this.name = e;
|
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
label={I18n.t('Name')}
|
|
|
|
placeholder={I18n.t('Name')}
|
|
|
|
value={name}
|
2021-11-10 15:10:34 +00:00
|
|
|
onChangeText={(value: string) => this.setState({ name: value })}
|
2021-09-13 20:41:05 +00:00
|
|
|
onSubmitEditing={() => {
|
2022-05-07 02:11:07 +00:00
|
|
|
this.username?.focus();
|
2021-09-13 20:41:05 +00:00
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
testID='profile-view-name'
|
|
|
|
/>
|
2022-05-18 19:17:42 +00:00
|
|
|
<FormTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowUsernameChange}
|
2021-09-13 20:41:05 +00:00
|
|
|
inputStyle={[!Accounts_AllowUsernameChange && styles.disabled]}
|
|
|
|
inputRef={e => {
|
|
|
|
this.username = e;
|
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
label={I18n.t('Username')}
|
|
|
|
placeholder={I18n.t('Username')}
|
|
|
|
value={username}
|
|
|
|
onChangeText={value => this.setState({ username: value })}
|
2021-09-13 20:41:05 +00:00
|
|
|
onSubmitEditing={() => {
|
2022-05-07 02:11:07 +00:00
|
|
|
this.email?.focus();
|
2021-09-13 20:41:05 +00:00
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
testID='profile-view-username'
|
|
|
|
/>
|
2022-05-18 19:17:42 +00:00
|
|
|
<FormTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowEmailChange}
|
2021-09-13 20:41:05 +00:00
|
|
|
inputStyle={[!Accounts_AllowEmailChange && styles.disabled]}
|
|
|
|
inputRef={e => {
|
2022-05-07 02:11:07 +00:00
|
|
|
if (e) {
|
|
|
|
this.email = e;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
label={I18n.t('Email')}
|
|
|
|
placeholder={I18n.t('Email')}
|
2022-05-07 02:11:07 +00:00
|
|
|
value={email || undefined}
|
2018-06-13 01:33:00 +00:00
|
|
|
onChangeText={value => this.setState({ email: value })}
|
2021-09-13 20:41:05 +00:00
|
|
|
onSubmitEditing={() => {
|
2022-05-07 02:11:07 +00:00
|
|
|
this.newPassword?.focus();
|
2021-09-13 20:41:05 +00:00
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
testID='profile-view-email'
|
|
|
|
/>
|
2022-05-18 19:17:42 +00:00
|
|
|
<FormTextInput
|
2020-02-20 18:26:42 +00:00
|
|
|
editable={Accounts_AllowPasswordChange}
|
2021-09-13 20:41:05 +00:00
|
|
|
inputStyle={[!Accounts_AllowPasswordChange && styles.disabled]}
|
|
|
|
inputRef={e => {
|
2022-05-07 02:11:07 +00:00
|
|
|
if (e) {
|
|
|
|
this.newPassword = e;
|
|
|
|
}
|
2021-09-13 20:41:05 +00:00
|
|
|
}}
|
2018-06-13 01:33:00 +00:00
|
|
|
label={I18n.t('New_Password')}
|
|
|
|
placeholder={I18n.t('New_Password')}
|
2022-05-07 02:11:07 +00:00
|
|
|
value={newPassword || undefined}
|
2018-06-13 01:33:00 +00:00
|
|
|
onChangeText={value => this.setState({ newPassword: value })}
|
|
|
|
onSubmitEditing={() => {
|
2019-11-13 19:53:20 +00:00
|
|
|
if (Accounts_CustomFields && Object.keys(customFields).length) {
|
2021-11-10 15:10:34 +00:00
|
|
|
// @ts-ignore
|
2018-06-13 01:33:00 +00:00
|
|
|
return this[Object.keys(customFields)[0]].focus();
|
|
|
|
}
|
2022-05-07 02:11:07 +00:00
|
|
|
this.avatarUrl?.focus();
|
2018-06-13 01:33:00 +00:00
|
|
|
}}
|
|
|
|
secureTextEntry
|
|
|
|
testID='profile-view-new-password'
|
|
|
|
/>
|
|
|
|
{this.renderCustomFields()}
|
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}
|
|
|
|
/>
|
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'
|
|
|
|
/>
|
2022-06-22 12:24:25 +00:00
|
|
|
{Accounts_AllowDeleteOwnAccount ? (
|
|
|
|
<Button
|
|
|
|
title={I18n.t('Delete_my_account')}
|
|
|
|
type='primary'
|
|
|
|
backgroundColor={themes[theme].dangerColor}
|
|
|
|
onPress={this.deleteOwnAccount}
|
|
|
|
testID='profile-view-delete-my-account'
|
|
|
|
/>
|
|
|
|
) : null}
|
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
|
|
|
|
2022-05-07 02:11:07 +00:00
|
|
|
const mapStateToProps = (state: IApplicationState) => ({
|
2020-02-11 14:09:14 +00:00
|
|
|
user: getUserSelector(state),
|
2022-06-27 19:03:24 +00:00
|
|
|
isMasterDetail: state.app.isMasterDetail,
|
2022-05-07 02:11:07 +00:00
|
|
|
Accounts_AllowEmailChange: state.settings.Accounts_AllowEmailChange as boolean,
|
|
|
|
Accounts_AllowPasswordChange: state.settings.Accounts_AllowPasswordChange as boolean,
|
|
|
|
Accounts_AllowRealNameChange: state.settings.Accounts_AllowRealNameChange as boolean,
|
|
|
|
Accounts_AllowUserAvatarChange: state.settings.Accounts_AllowUserAvatarChange as boolean,
|
|
|
|
Accounts_AllowUsernameChange: state.settings.Accounts_AllowUsernameChange as boolean,
|
|
|
|
Accounts_CustomFields: state.settings.Accounts_CustomFields as string,
|
2022-06-22 12:24:25 +00:00
|
|
|
baseUrl: state.server.server,
|
2022-06-27 19:03:24 +00:00
|
|
|
Accounts_AllowDeleteOwnAccount: state.settings.Accounts_AllowDeleteOwnAccount as boolean
|
2019-08-07 13:51:34 +00:00
|
|
|
});
|
|
|
|
|
2022-06-22 12:24:25 +00:00
|
|
|
export default connect(mapStateToProps)(withTheme(withActionSheet(ProfileView)));
|