@@ -12,7 +12,8 @@ const mapStateToProps = state => {
1212 return {
1313 serverUrl : state . serverUrl ,
1414 user : state . user ,
15- links : state . links
15+ links : state . links ,
16+ product : state . departments . products . selected
1617 }
1718}
1819
@@ -27,7 +28,6 @@ class Departments extends Component {
2728
2829 this . handleDepartmentChange = this . handleDepartmentChange . bind ( this ) ;
2930 this . handleRemoveOnClick = this . handleRemoveOnClick . bind ( this ) ;
30- // this.handleProductChange=this.handleProductChange.bind(this);
3131 this . handleDepartmentAdd = this . handleDepartmentAdd . bind ( this ) ;
3232 this . getUnassignedProducts = this . getUnassignedProducts . bind ( this ) ;
3333 }
@@ -58,15 +58,13 @@ class Departments extends Component {
5858 } ) ;
5959 }
6060
61- // handleProductChange(e) {
62- // const productId = e.target.value,
63- // product = this.state.products.filter((product) => productId==product._id)[0];
64- // this.setState({ product:product});
65- // }
66-
6761 handleDepartmentAdd ( e , departmentId ) {
68- const product = this . state . product ,
69- departments = product . departments || [ ] ;
62+ const product = this . props . product ;
63+ if ( ! product ) {
64+ console . warn ( 'No product selected in Products List.' ) ;
65+ return ;
66+ }
67+ const departments = product . departments || [ ] ;
7068
7169 departments . push ( departmentId ) ;
7270 console . log ( product . _id ) ;
@@ -154,5 +152,6 @@ export default connect(mapStateToProps)(Departments);
154152
155153Departments . propTypes = {
156154 serverUrl : PropTypes . string ,
157- links : PropTypes . array
155+ links : PropTypes . array ,
156+ product : PropTypes . object
158157}
0 commit comments