Commit ef9b1fd0 authored by Matija Obreza's avatar Matija Obreza
Browse files

SelectPartner component is self-sustainable

parent 7a460efa
import * as React from 'react';
import {withStyles} from 'material-ui/styles';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import {log} from 'utilities/debug';
import {Page} from 'model/common.model';
import {Partner} from 'model/partner.model';
import {promiseLoadPartners} from 'actions/partner';
import Input from 'material-ui/Input';
import FormControl from 'ui/common/forms/FormControl';
......@@ -22,17 +26,38 @@ const styles = (theme) => ({
interface ISelectPartnerProps extends React.ClassAttributes<any> {
classes: any;
input: any;
partners: Partner[];
label: string;
editable?: boolean;
required?: boolean;
meta?: any;
promiseLoadPartners: any;
}
class SelectPartner extends React.Component<ISelectPartnerProps, any> {
public constructor(props: any) {
super(props);
this.state = {
partners: props.partners || [],
};
}
public componentWillMount() {
const { promiseLoadPartners } = this.props;
promiseLoadPartners(0, 50).then((data) => new Page<Partner>(data, (dl) => new Partner(dl)))
.then((paged) => {
this.setState({
partners: paged.content,
});
});
}
public handleChange = ({target: {value}}) => {
const { editable, input, partners } = this.props;
const { editable, input } = this.props;
const { partners } = this.state;
log(`Partner selection editable=${editable}`, value);
const p = partners.find((p) => p.uuid === value);
if (editable === undefined || editable) {
......@@ -41,7 +66,8 @@ class SelectPartner extends React.Component<ISelectPartnerProps, any> {
}
public render() {
const {classes, input, partners, label, editable, required, meta } = this.props;
const {classes, input, label, editable, required, meta } = this.props;
const { partners } = this.state;
const allowsEdit = editable === undefined || editable;
......@@ -66,4 +92,13 @@ class SelectPartner extends React.Component<ISelectPartnerProps, any> {
}
}
export default withStyles(styles)(SelectPartner);
const mapStateToProps = (state) => ({
partners: state.partner.myPartners,
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
promiseLoadPartners,
}, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(SelectPartner));
......@@ -3,7 +3,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 {TextField} from 'ui/common/text-field';
import {MarkdownField} from 'ui/catalog/markdown';
......@@ -21,14 +20,13 @@ interface ILoginContainerProps extends React.ClassAttributes<any> {
initialValues: any;
classes: any;
uuid: string;
partners: Partner[];
}
class BasicInfoStep extends React.Component<ILoginContainerProps, any> {
public render() {
const {partners, initialValues, handleSubmit} = this.props;
const {initialValues, handleSubmit} = this.props;
return (
<form onSubmit={ handleSubmit } className="p-20 m-20 even-row">
......@@ -37,7 +35,6 @@ class BasicInfoStep extends React.Component<ILoginContainerProps, any> {
component={ SelectPartner }
label="Select Partner"
placeholder="Partner"
partners={ partners }
editable={ ! (initialValues.uuid && initialValues.version) }
validate={ [ Validators.required ] }
/>
......
......@@ -67,7 +67,6 @@ class BasicInfoStep extends React.Component<IDatasetProps, any> {
}
const mapStateToProps = (state, ownProps) => ({
myPartners: state.partner.myPartners,
dataset: state.datasets.currentDataset,
stillLoading: ownProps.stillLoading,
location: ownProps.location,
......
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