Commit 03119dae authored by Matija Obreza's avatar Matija Obreza
Browse files

CropSelector uses crops available in state

parent 0c48bb80
import * as React from 'react';
import { connect } from 'react-redux';
import { translate } from 'react-i18next';
import Grid from 'material-ui/Grid';
......@@ -52,4 +53,10 @@ const CropSelector = ({t, fields, crops, onSave, label}: ICropSelectorProps) =>
</FormControl>
);
export default translate()(CropSelector);
const mapStateToProps = (state) => ({
crops: state.crop.list,
});
export default connect(mapStateToProps, null)(translate()(CropSelector));
......@@ -4,7 +4,6 @@ import {Field, reduxForm, FieldArray} from 'redux-form';
import {DATASET_BASIC_INFO_FORM} from 'constants/datasets';
import languages from 'data/Languages';
import {Partner} from 'model/partner.model';
import {Crop} from 'model/crop.model';
import {TextField} from 'ui/common/text-field';
import {MarkdownField} from 'ui/catalog/markdown';
......@@ -22,7 +21,6 @@ interface ILoginContainerProps extends React.ClassAttributes<any> {
classes: any;
uuid: string;
partners: Partner[];
crops: Crop[];
}
class BasicInfoStep extends React.Component<ILoginContainerProps, any> {
......@@ -33,7 +31,7 @@ class BasicInfoStep extends React.Component<ILoginContainerProps, any> {
public render() {
const {partners, initialValues, crops} = this.props;
const {partners, initialValues} = this.props;
return (
<form className="p-20 m-20 even-row">
......@@ -99,7 +97,6 @@ class BasicInfoStep extends React.Component<ILoginContainerProps, any> {
/>
<FieldArray
name="crops"
crops={ crops }
component={ CropSelector }
label="Crops"
onSave={ this.save }
......
......@@ -8,21 +8,17 @@ import {log} from 'utilities/debug';
import BasicInfoForm from './BasicInfoForm';
import {Dataset} from 'model/dataset.model';
import {saveDataset} from 'actions/dataset';
import {listCrops} from 'actions/crop';
import {loadMyPartners} from 'actions/partner';
import {Partner} from 'model/partner.model';
import {Crop} from 'model/crop.model';
interface IDatasetProps extends React.ClassAttributes<any> {
uuid: string;
dataset: Dataset;
saveDataset: (dataset: Dataset) => Promise<Dataset>;
listCrops: () => any;
loadMyPartners: any;
myPartners: Partner[];
crops: Crop[];
}
class BasicInfoStep extends React.Component<IDatasetProps, any> {
......@@ -30,13 +26,11 @@ class BasicInfoStep extends React.Component<IDatasetProps, any> {
protected static needs = [];
public componentWillMount() {
const {myPartners, loadMyPartners, listCrops} = this.props;
const {myPartners, loadMyPartners} = this.props;
if (!myPartners || myPartners.length === 0) {
loadMyPartners();
}
listCrops();
}
protected handleSubmit = (values: Dataset) => {
......@@ -48,7 +42,7 @@ class BasicInfoStep extends React.Component<IDatasetProps, any> {
}
public render() {
const {myPartners, dataset, crops} = this.props;
const {myPartners, dataset} = this.props;
if (! dataset) {
return null;
......@@ -59,7 +53,6 @@ class BasicInfoStep extends React.Component<IDatasetProps, any> {
onSubmit={ this.handleSubmit }
initialValues={ dataset }
partners={ myPartners }
crops={ crops }
/>
);
}
......@@ -68,13 +61,11 @@ class BasicInfoStep extends React.Component<IDatasetProps, any> {
const mapStateToProps = (state, ownProps) => ({
myPartners: state.partner.myPartners,
dataset: state.datasets.currentDataset,
crops: state.crop.list,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
saveDataset,
loadMyPartners,
listCrops,
}, dispatch);
export default connect(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment