// Edit account parameters. import React from 'react'; import { FormattedMessage } from 'react-intl'; import { parsePhoneNumber } from 'libphonenumber-js/mobile'; import AvatarUpload from '../widgets/avatar-upload.jsx'; import BadgeList from '../widgets/badge-list.jsx'; import { makeImageUrl } from '../lib/blob-helpers.js'; import { MAX_TITLE_LENGTH, MAX_TOPIC_DESCRIPTION_LENGTH } from '../config.js'; import CredentialEdit from '../widgets/credential-edit.jsx'; function _clip(str, length) { return str && str.substring(0, length); } export default class AccountSettingsView extends React.Component { constructor(props) { super(props); const me = this.props.tinode.getMeTopic(); this.state = { fullName: _clip(me.public ? me.public.fn : undefined, MAX_TITLE_LENGTH), description: _clip(me.public ? me.public.note : undefined, MAX_TOPIC_DESCRIPTION_LENGTH), avatar: makeImageUrl(me.public ? me.public.photo : null), credentials: me.getCredentials() || [], credEdit: undefined }; } componentDidMount() { const me = this.props.tinode.getMeTopic(); me.onCredsUpdated = _ => this.setState({credentials: me.getCredentials()}); } componentWillUnmount() { const me = this.props.tinode.getMeTopic(); me.onCredsUpdated = null; } render() { if (this.state.credEdit) { return ( this.setState({credEdit: undefined})} onError={this.props.onError} /> ); } const credentials = []; this.state.credentials.forEach((cred, idx) => { if (!['email', 'tel'].includes(cred.meth)) { // Skip unknown methods. return ; } let val = cred.val if (cred.meth == 'tel') { const number = parsePhoneNumber(cred.val); val = number ? number.formatInternational() : cred.val; } credentials.push(
{e.preventDefault(); this.setState({credEdit: cred});}}>{val} { cred.done ? null : <> pending  {e.preventDefault(); this.props.onCredDelete(cred.meth, cred.val);}}> delete }
); }); if (credentials.length > 0) { // Add title as the first element. credentials.unshift( ); } return (
{e.preventDefault(); this.props.onNavigate('general');}}> edit 
{this.state.fullName}
  {this.props.myUserId}
{this.state.description ?
{this.state.description}
: null}
{credentials}
{e.preventDefault(); this.props.onNavigate('notif');}}> notifications  {e.preventDefault(); this.props.onNavigate('security');}}> security  {e.preventDefault(); this.props.onNavigate('support');}}> contact_support 
); } };