From e1cd664c663b960c600a9e4a2f3f11fddbbb4dc8 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 5 Mar 2021 22:35:02 +0100 Subject: user pages --- .../app/views/user/containers/user.edit.js | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 animism-align/frontend/app/views/user/containers/user.edit.js (limited to 'animism-align/frontend/app/views/user/containers/user.edit.js') 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 ( +
+ +
+ ) + } + return ( +
+ + +
+ ) + } +} + +const mapStateToProps = state => ({ + user: state.user, +}) + +export default connect(mapStateToProps)(UserEdit) -- cgit v1.2.3-70-g09d2