bigbuffet-rw/app/gabsocial/features/edit_profile/index.js

154 lines
4.6 KiB
JavaScript
Raw Normal View History

2020-04-21 16:00:05 -07:00
import React from 'react';
import { connect } from 'react-redux';
import { defineMessages, injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Column from '../ui/components/column';
import {
SimpleForm,
FieldsGroup,
TextInput,
2020-04-21 17:22:00 -07:00
Checkbox,
2020-04-22 14:26:44 -07:00
FileChooser,
2020-04-21 16:00:05 -07:00
} from 'gabsocial/features/forms';
2020-04-22 14:26:44 -07:00
import ProfilePreview from './components/profile_preview';
import { Map as ImmutableMap } from 'immutable';
2020-04-21 16:00:05 -07:00
import { patchMe } from 'gabsocial/actions/me';
const messages = defineMessages({
heading: { id: 'column.edit_profile', defaultMessage: 'Edit profile' },
});
const mapStateToProps = state => {
const me = state.get('me');
return {
account: state.getIn(['accounts', me]),
};
};
export default @connect(mapStateToProps)
@injectIntl
class EditProfile extends ImmutablePureComponent {
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
account: ImmutablePropTypes.map,
};
2020-04-21 17:22:00 -07:00
state = {
isLoading: false,
2020-04-21 16:00:05 -07:00
}
2020-04-21 17:22:00 -07:00
getParams = () => {
const { state } = this;
return {
discoverable: state.discoverable,
bot: state.bot,
display_name: state.display_name,
note: state.note,
// avatar: state.avatar,
// header: state.header,
locked: state.locked,
fields_attributes: state.fields_attributes,
};
2020-04-21 16:00:05 -07:00
}
handleSubmit = (event) => {
const { dispatch } = this.props;
2020-04-21 17:22:00 -07:00
dispatch(patchMe(this.getParams())).then(() => {
2020-04-21 16:00:05 -07:00
this.setState({ isLoading: false });
}).catch((error) => {
this.setState({ isLoading: false });
});
this.setState({ isLoading: true });
event.preventDefault();
}
2020-04-21 17:22:00 -07:00
componentWillMount() {
const { account } = this.props;
this.setState(account.toJS());
}
handleCheckboxChange = e => {
this.setState({ [e.target.name]: e.target.checked });
}
handleTextChange = e => {
this.setState({ [e.target.name]: e.target.value });
}
2020-04-21 16:00:05 -07:00
render() {
2020-04-21 17:22:00 -07:00
const { intl } = this.props;
2020-04-21 16:00:05 -07:00
return (
2020-04-21 17:24:57 -07:00
<Column icon='user' heading={intl.formatMessage(messages.heading)} backBtnSlim>
2020-04-21 16:00:05 -07:00
<SimpleForm onSubmit={this.handleSubmit}>
<fieldset disabled={this.state.isLoading}>
<FieldsGroup>
<TextInput
label='Display name'
name='display_name'
2020-04-21 17:22:00 -07:00
value={this.state.display_name}
maxLength={30}
onChange={this.handleTextChange}
2020-04-21 16:00:05 -07:00
/>
<TextInput
label='Bio'
name='note'
2020-04-21 17:22:00 -07:00
value={this.state.note}
onChange={this.handleTextChange}
/>
2020-04-22 14:26:44 -07:00
<div className='fields-row'>
<div className='fields-row__column fields-row__column-6'>
<ProfilePreview
account={ImmutableMap({
url: this.state.url,
header: this.state.header,
avatar: this.state.avatar,
username: this.state.username,
display_name: this.state.display_name,
acct: this.state.acct,
})}
/>
</div>
<div className='fields-row__column fields-group fields-row__column-6'>
<FileChooser
label='Header'
name='header'
hint='PNG, GIF or JPG. At most 2 MB. Will be downscaled to 1500x500px'
/>
<FileChooser
label='Avatar'
name='avatar'
hint='PNG, GIF or JPG. At most 2 MB. Will be downscaled to 400x400px'
/>
</div>
</div>
2020-04-21 17:22:00 -07:00
<Checkbox
label='Lock account'
hint='Requires you to manually approve followers'
name='locked'
checked={this.state.locked}
onChange={this.handleCheckboxChange}
/>
<Checkbox
label='This is a bot account'
hint='This account mainly performs automated actions and might not be monitored'
name='bot'
checked={this.state.bot}
onChange={this.handleCheckboxChange}
2020-04-21 16:00:05 -07:00
/>
</FieldsGroup>
</fieldset>
<div className='actions'>
<button name='button' type='submit' className='btn button button-primary'>Save changes</button>
</div>
</SimpleForm>
</Column>
);
}
}