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 VenueForm from '../components/venue.form' import VenueMenu from '../components/venue.menu' class VenueNew extends Component { state = { loading: true, initialData: {}, } componentDidMount() { this.ready() } componentDidUpdate(prevProps) { if (this.props.project.lookup !== prevProps.project.lookup) { this.ready() } } ready() { if (!this.props.project.lookup) return const { project_id } = this.props.match.params const project = parseInt(this.props.project.lookup[project_id]) this.setState({ loading: false, initialData: { project_id }, project, }) } handleSubmit(data) { console.log(data) actions.venue.create(data) .then(res => { console.log(res) if (res.res && res.res.id) { history.push(`/project/${res.res.project_id}/venues/`) } }) .catch(err => { console.error('error') }) } render() { if (this.state.loading) { return (
) } return (
) } } const mapStateToProps = state => ({ project: state.project.index, }) export default connect(mapStateToProps)(VenueNew)