import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import { defineMessages, injectIntl } from 'react-intl' import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePropTypes from 'react-immutable-proptypes' import { saveUserProfileInformation } from '../../actions/user' import { me } from '../../initial_state' import Button from '../button' import Block from '../block' import Divider from '../divider' import FileInput from '../file_input' import Input from '../input' import Switch from '../switch' import Heading from '../heading' import Textarea from '../textarea' class EditProfileModal extends ImmutablePureComponent { state = { avatarSrc: this.props.account ? this.props.account.get('avatar_static') : undefined, bioValue: this.props.account ? this.props.account.get('note_plain') : '', displayNameValue: this.props.account ? this.props.account.get('display_name_plain') : '', headerSrc: this.props.account ? this.props.account.get('header_static') : undefined, locked: this.props.account ? this.props.account.get('locked') : false, } componentDidUpdate (prevProps) { if (prevProps.account !== this.props.account) { if (this.props.account) { this.setState({ avatarSrc: this.props.account.get('avatar_static'), bioValue: this.props.account.get('note_plain'), displayNameValue: this.props.account.get('display_name_plain'), headerSrc: this.props.account.get('header_static'), locked: this.props.account.get('locked'), }) } else { this.setState({ avatarSrc: undefined, bioValue: '', displayNameValue: '', headerSrc: undefined, locked: false, }) } } } handleCoverPhotoChange = (e) => { try { this.setState({ headerSrc: e.target.files[0] }) } catch (error) { // } } handleProfilePhotoChange = (e) => { try { this.setState({ avatarSrc: e.target.files[0] }) } catch (error) { // } } handleDisplayNameChange = (value) => { this.setState({ displayNameValue: value }) } handleBioChange = (value) => { this.setState({ bioValue: value }) } handleLockedChange = (locked) => { this.setState({ locked }) } handleOnClose = () => { this.props.onClose() } handleOnSave = () => { const { account } = this.props const { avatarSrc, bioValue, displayNameValue, headerSrc, locked, } = this.state const isVerified = account.get('is_verified') const obj = {} obj.locked = locked if (!isVerified && account.get('display_name_plain') !== displayNameValue) obj.displayName = displayNameValue if (account.get('note_plain') !== bioValue) obj.note = bioValue if (account.get('avatar_static') !== avatarSrc) obj.avatar = avatarSrc if (account.get('header_static') !== headerSrc) obj.header = headerSrc this.props.onSave(obj, this.handleOnClose) //this.handleOnClose() } render() { const { intl, account } = this.props const { avatarSrc, bioValue, displayNameValue, headerSrc, locked, } = this.state const isVerified = account.get('is_verified') return (