diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2021-03-05 22:35:02 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2021-03-05 22:35:02 +0100 |
| commit | e1cd664c663b960c600a9e4a2f3f11fddbbb4dc8 (patch) | |
| tree | fd616f01b1e489477ed75206cef0e583de81e69b /animism-align/frontend/app/views/user/containers/user.edit.js | |
| parent | 501f0ab74ea7d8b1ee0d5ea4cdc84d200fa04d35 (diff) | |
user pages
Diffstat (limited to 'animism-align/frontend/app/views/user/containers/user.edit.js')
| -rw-r--r-- | animism-align/frontend/app/views/user/containers/user.edit.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/animism-align/frontend/app/views/user/containers/user.edit.js b/animism-align/frontend/app/views/user/containers/user.edit.js new file mode 100644 index 0000000..5d51792 --- /dev/null +++ b/animism-align/frontend/app/views/user/containers/user.edit.js @@ -0,0 +1,70 @@ +import React, { Component } from 'react' +import { connect } from 'react-redux' + +import { history } from 'app/store' +import actions from 'app/actions' + +import { Loader } from 'app/common' + +import UserForm from '../components/user.form' +import UserMenu from '../components/user.menu' + +class UserEdit extends Component { + componentDidMount() { + console.log(this.props.match.params.id) + actions.user.show(this.props.match.params.id) + } + + handleSubmit(data) { + actions.user.update(data) + .then(response => { + // response + console.log(response) + history.push('/users/') + }) + .catch(err => { + console.log(err) + if (!err.errors) { + if (err.error) { + alert(err.error) + return + } + alert("There was an error saving this user.") + return + } + const errorStr = Object.keys(err.errors) + .map(key => ( + err.errors[key].map(error => + key + ": " + error + ).join("\n") + )).join("\n") + alert("There was an error updating this user.\n" + errorStr) + }) + } + + render() { + const { show } = this.props.user + if (show.loading || !show.res) { + return ( + <div className='form'> + <Loader /> + </div> + ) + } + return ( + <div className='row formContainer'> + <UserMenu userActions={this.props.userActions} /> + <UserForm + data={show.res} + onSubmit={this.handleSubmit.bind(this)} + /> + </div> + ) + } +} + +const mapStateToProps = state => ({ + user: state.user, +}) + +export default connect(mapStateToProps)(UserEdit) |
