From f16779219a6700a8f3de7e29afc7cd82e59ca3e9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Apr 2020 19:22:00 -0500 Subject: [PATCH] Improve profile editor --- app/gabsocial/features/edit_profile/index.js | 61 ++++++++++++++++---- app/gabsocial/features/forms/index.js | 16 ++--- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/app/gabsocial/features/edit_profile/index.js b/app/gabsocial/features/edit_profile/index.js index 16a774a83..7ef9e3706 100644 --- a/app/gabsocial/features/edit_profile/index.js +++ b/app/gabsocial/features/edit_profile/index.js @@ -9,6 +9,7 @@ import { SimpleForm, FieldsGroup, TextInput, + Checkbox, } from 'gabsocial/features/forms'; import { patchMe } from 'gabsocial/actions/me'; @@ -33,21 +34,27 @@ class EditProfile extends ImmutablePureComponent { account: ImmutablePropTypes.map, }; - constructor(props) { - super(props); - this.state = { isLoading: false }; + state = { + isLoading: false, } - getFormData = (form) => { - return Object.fromEntries( - new FormData(form).entries() - ); + 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, + }; } handleSubmit = (event) => { const { dispatch } = this.props; - const formData = this.getFormData(event.target); - dispatch(patchMe(formData)).then(() => { + dispatch(patchMe(this.getParams())).then(() => { this.setState({ isLoading: false }); }).catch((error) => { this.setState({ isLoading: false }); @@ -56,8 +63,21 @@ class EditProfile extends ImmutablePureComponent { event.preventDefault(); } + 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 }); + } + render() { - const { account, intl } = this.props; + const { intl } = this.props; return ( @@ -67,12 +87,29 @@ class EditProfile extends ImmutablePureComponent { + + diff --git a/app/gabsocial/features/forms/index.js b/app/gabsocial/features/forms/index.js index b05d9809e..6bb5a0412 100644 --- a/app/gabsocial/features/forms/index.js +++ b/app/gabsocial/features/forms/index.js @@ -48,6 +48,7 @@ export class Checkbox extends ImmutablePureComponent { static propTypes = { label: PropTypes.string, + name: PropTypes.string, checked: PropTypes.bool, onChange: PropTypes.func, } @@ -57,7 +58,7 @@ export class Checkbox extends ImmutablePureComponent { } render() { - const { label, checked, onChange } = this.props; + const { label, name, checked, onChange } = this.props; const id = uuidv4(); return ( @@ -70,6 +71,7 @@ export class Checkbox extends ImmutablePureComponent {