2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-03-27 22:57:03 +00:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
2020-04-24 04:17:27 +01:00
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-07-17 21:25:05 +01:00
|
|
|
import { saveUserProfileInformation } from '../../actions/user'
|
2020-04-24 04:17:27 +01:00
|
|
|
import { me } from '../../initial_state'
|
2020-03-27 22:57:03 +00:00
|
|
|
import Button from '../button'
|
2020-07-17 21:25:05 +01:00
|
|
|
import Block from '../block'
|
2020-04-24 04:17:27 +01:00
|
|
|
import Divider from '../divider'
|
2020-07-17 21:25:05 +01:00
|
|
|
import FileInput from '../file_input'
|
2020-04-24 04:17:27 +01:00
|
|
|
import Input from '../input'
|
2020-07-17 21:25:05 +01:00
|
|
|
import Switch from '../switch'
|
|
|
|
import Heading from '../heading'
|
2020-04-24 04:17:27 +01:00
|
|
|
import Textarea from '../textarea'
|
2020-03-27 22:57:03 +00:00
|
|
|
|
|
|
|
class EditProfileModal extends ImmutablePureComponent {
|
|
|
|
|
2020-07-17 21:25:05 +01:00
|
|
|
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 })
|
|
|
|
}
|
|
|
|
|
2020-09-01 20:54:17 +01:00
|
|
|
handleLockedChange = (locked) => {
|
|
|
|
this.setState({ locked })
|
2020-07-17 21:25:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleOnClose = () => {
|
|
|
|
this.props.onClose()
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnSave = () => {
|
|
|
|
const { account } = this.props
|
|
|
|
const {
|
|
|
|
avatarSrc,
|
|
|
|
bioValue,
|
|
|
|
displayNameValue,
|
|
|
|
headerSrc,
|
|
|
|
locked,
|
|
|
|
} = this.state
|
|
|
|
|
2020-07-22 16:27:26 +01:00
|
|
|
const isVerified = account.get('is_verified')
|
2020-07-17 21:25:05 +01:00
|
|
|
|
|
|
|
const obj = {}
|
|
|
|
obj.locked = locked
|
2020-07-22 16:27:26 +01:00
|
|
|
if (!isVerified && account.get('display_name_plain') !== displayNameValue) obj.displayName = displayNameValue
|
2020-07-17 21:25:05 +01:00
|
|
|
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
|
|
|
|
|
2020-11-21 21:11:53 +00:00
|
|
|
this.props.onSave(obj, this.handleOnClose)
|
|
|
|
//this.handleOnClose()
|
2020-03-27 22:57:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-07-17 21:25:05 +01:00
|
|
|
const { intl, account } = this.props
|
|
|
|
const {
|
|
|
|
avatarSrc,
|
|
|
|
bioValue,
|
|
|
|
displayNameValue,
|
|
|
|
headerSrc,
|
|
|
|
locked,
|
|
|
|
} = this.state
|
|
|
|
|
2020-07-22 16:27:26 +01:00
|
|
|
const isVerified = account.get('is_verified')
|
2020-03-27 22:57:03 +00:00
|
|
|
|
|
|
|
return (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div style={{ width: '440px' }} className={[_s.d, _s.modal].join(' ')}>
|
2020-07-17 21:25:05 +01:00
|
|
|
<Block>
|
2020-12-30 17:22:56 +00:00
|
|
|
<div className={[_s.d, _s.flexRow, _s.aiCenter, _s.jcCenter, _s.borderBottom1PX, _s.borderColorSecondary, _s.h53PX, _s.pr10].join(' ')}>
|
2020-07-17 21:25:05 +01:00
|
|
|
<Button
|
|
|
|
backgroundColor='none'
|
|
|
|
title={intl.formatMessage(messages.close)}
|
2020-08-18 21:43:06 +01:00
|
|
|
className={[_s.mrAuto, _s.w60PX, _s.pl0].join(' ')}
|
2020-07-17 21:25:05 +01:00
|
|
|
onClick={this.handleOnClose}
|
|
|
|
color='secondary'
|
|
|
|
icon='close'
|
|
|
|
iconSize='10px'
|
2020-04-24 04:17:27 +01:00
|
|
|
/>
|
2020-07-17 21:25:05 +01:00
|
|
|
<Heading size='h2'>
|
|
|
|
{intl.formatMessage(messages.edit_profile)}
|
|
|
|
</Heading>
|
|
|
|
<Button
|
2020-12-30 17:22:56 +00:00
|
|
|
radiusSmall
|
2020-07-17 21:25:05 +01:00
|
|
|
title={intl.formatMessage(messages.save)}
|
2020-08-18 21:43:06 +01:00
|
|
|
className={[_s.mlAuto, _s.w60PX].join(' ')}
|
2020-07-17 21:25:05 +01:00
|
|
|
onClick={this.handleOnSave}
|
|
|
|
>
|
|
|
|
{intl.formatMessage(messages.save)}
|
|
|
|
</Button>
|
|
|
|
</div>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.maxH80VH, _s.overflowYScroll].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC, _s.aiCenter].join(' ')}>
|
2020-07-17 21:25:05 +01:00
|
|
|
<FileInput
|
|
|
|
width='440px'
|
|
|
|
height='180px'
|
|
|
|
id='cover-photo'
|
|
|
|
onChange={this.handleCoverPhotoChange}
|
|
|
|
file={headerSrc}
|
|
|
|
/>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.mtNeg50PX, _s.aiCenter, _s.jcCenter].join(' ')}>
|
2020-07-17 21:25:05 +01:00
|
|
|
<FileInput
|
|
|
|
width='132px'
|
|
|
|
height='132px'
|
|
|
|
id='profile-photo'
|
|
|
|
file={avatarSrc}
|
|
|
|
className={[_s.circle, _s.border6PX, _s.borderColorWhite, _s.bgPrimary].join(' ')}
|
|
|
|
onChange={this.handleProfilePhotoChange}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.py5, _s.px15, _s.mt5, _s.mb15, _s.w100PC].join(' ')}>
|
2020-07-17 21:25:05 +01:00
|
|
|
{
|
2020-07-22 16:27:26 +01:00
|
|
|
!isVerified &&
|
2020-08-17 21:07:16 +01:00
|
|
|
<React.Fragment>
|
2020-07-17 21:25:05 +01:00
|
|
|
<Input
|
|
|
|
id='display-name'
|
|
|
|
title='Display name'
|
2020-12-17 06:34:00 +00:00
|
|
|
maxLength={30}
|
2020-07-17 21:25:05 +01:00
|
|
|
value={displayNameValue}
|
|
|
|
onChange={this.handleDisplayNameChange}
|
|
|
|
onBlur={this.handleDisplayNameBlur}
|
|
|
|
/>
|
|
|
|
<Divider isInvisible />
|
2020-08-17 21:07:16 +01:00
|
|
|
</React.Fragment>
|
2020-07-17 21:25:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
<Textarea
|
|
|
|
title='Bio'
|
|
|
|
value={bioValue}
|
|
|
|
disabled={false}
|
2020-12-17 06:34:00 +00:00
|
|
|
maxLength={500}
|
2020-07-17 21:25:05 +01:00
|
|
|
onChange={this.handleBioChange}
|
|
|
|
placeholder='Add your bio...'
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Divider isInvisible />
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.px10].join(' ')}>
|
2020-07-17 21:25:05 +01:00
|
|
|
<Switch
|
|
|
|
label='Private account'
|
|
|
|
checked={locked}
|
|
|
|
onChange={this.handleLockedChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-04-24 04:17:27 +01:00
|
|
|
</div>
|
2020-07-17 21:25:05 +01:00
|
|
|
</Block>
|
|
|
|
</div>
|
2020-03-27 22:57:03 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 18:07:47 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
edit_profile: { id: 'account.edit_profile', defaultMessage: 'Edit profile' },
|
|
|
|
headerPhoto: { id: 'header_photo', defaultMessage: 'Header photo' },
|
|
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
|
|
|
save: { id: 'lightbox.save', defaultMessage: 'Save' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
account: state.getIn(['accounts', me]),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2020-11-21 21:11:53 +00:00
|
|
|
onSave: (data, closer) => dispatch(saveUserProfileInformation(data, closer)),
|
2020-08-18 18:07:47 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
EditProfileModal.propTypes = {
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
onSave: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(EditProfileModal))
|