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 EpisodeForm from '../components/episode.form' import EpisodeMenu from '../components/episode.menu' class EpisodeNew extends Component { state = { loading: true, initialData: {}, project: {}, } 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 = this.props.project.lookup[project_id] this.setState({ loading: false, initialData: { project_id }, project, }) console.log(this.props.match.params.project_id) } handleSubmit(data) { console.log(data) actions.episode.create(data) .then(res => { console.log(res) if (res.res && res.res.id) { history.push('/') } }) .catch(err => { console.error('error') }) } render() { if (this.state.loading) { return (
) } return (
) } } const mapStateToProps = state => ({ episode: state.episode, project: state.project.index, }) const mapDispatchToProps = dispatch => ({ // uploadActions: bindActionCreators({ ...uploadActions }, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(EpisodeNew)