summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/user/containers/user.new.js
diff options
context:
space:
mode:
Diffstat (limited to 'animism-align/frontend/app/views/user/containers/user.new.js')
-rw-r--r--animism-align/frontend/app/views/user/containers/user.new.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/animism-align/frontend/app/views/user/containers/user.new.js b/animism-align/frontend/app/views/user/containers/user.new.js
new file mode 100644
index 0000000..9d80e0a
--- /dev/null
+++ b/animism-align/frontend/app/views/user/containers/user.new.js
@@ -0,0 +1,76 @@
+import React, { Component } from 'react'
+import { Link } from 'react-router-dom'
+import { connect } from 'react-redux'
+
+import { history } from 'app/store'
+import actions from 'app/actions'
+
+import UserForm from '../components/user.form'
+import UserMenu from '../components/user.menu'
+
+class UserNew extends Component {
+ state = {
+ loading: true,
+ initialData: {},
+ }
+
+ componentDidMount() {
+ this.setState({ loading: false })
+ }
+
+ handleSubmit(data) {
+ console.log(data)
+ actions.user.create(data)
+ .then(res => {
+ console.log(res)
+ if (res.res && res.res.id) {
+ history.push('/users/')
+ }
+ })
+ .catch(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 creating this user.\n" + errorStr)
+ })
+ }
+
+ render() {
+ if (this.state.loading) {
+ return (
+ <div className='row formContainer' />
+ )
+ }
+ return (
+ <div className='row formContainer'>
+ <UserMenu />
+ <UserForm
+ isNew
+ data={this.state.initialData}
+ onSubmit={this.handleSubmit.bind(this)}
+ />
+ </div>
+ )
+ }
+}
+
+const mapStateToProps = state => ({
+ user: state.user,
+})
+
+const mapDispatchToProps = dispatch => ({
+ // uploadActions: bindActionCreators({ ...uploadActions }, dispatch),
+})
+
+export default connect(mapStateToProps, mapDispatchToProps)(UserNew)