-
Notifications
You must be signed in to change notification settings - Fork 1
/
RecipeCreatePage.js
57 lines (43 loc) · 1.55 KB
/
RecipeCreatePage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React from 'react';
import { Link } from 'react-router';
import { initialize } from 'redux-form';
import { connect } from 'react-redux';
import { submitRecipe } from '../../actions/recipes-actions';
import RecipeForm from '../forms/RecipeForm.react';
import { fetchPackages } from '../../actions/packages-actions';
import { fetchTags } from '../../actions/tags-actions';
import { redirectIfNotLoggedIn } from '../../utils/helpers';
class RecipeCreatePage extends React.Component {
componentWillMount() {
let { dispatch } = this.props;
dispatch( fetchPackages() );
dispatch( fetchTags() );
}
componentDidUpdate() {
redirectIfNotLoggedIn(this.props, '/recipes');
}
handleSubmit(data) {
let { dispatch } = this.props;
dispatch( submitRecipe(data) );
}
handleEditorChange(data) {
let { dispatch } = this.props;
dispatch( initialize('recipeForm', data) );
}
handleFieldChange(data) {
let { dispatch } = this.props;
dispatch( initialize('recipeForm', data) );
}
render() {
let { packages, tags } = this.props;
return (
<div id="recipe-create-page">
<h2>Create</h2>
<div className="container">
<RecipeForm onSubmit={this.handleSubmit.bind(this)} onEditorChange={this.handleEditorChange.bind(this)} onFieldChange={this.handleFieldChange.bind(this)} packagesItems={packages.items} tagsItems={tags.items} />
</div>
</div>
);
}
}
export default connect(state => ({user: state.login.user, packages: state.packages, tags: state.tags}))(RecipeCreatePage);