@@ -8,15 +8,10 @@ class ProductColorEdit extends Component {
88 super ( props ) ;
99
1010 console . log ( "color edit" , props )
11-
12- let currentProduct = this . props ? this . props . products . products . filter ( product => product . attributes . id === parseInt ( this . props . match . params . id ) ) [ 0 ] : null
13- console . log ( "currentProduct" , currentProduct )
14-
15- // debugger;
1611
1712 this . state = {
18- color_name : "" ,
19- available_qty : "" ,
13+ color_name : ` ${ this . props . color ? this . props . color . color_name : "" } ` ,
14+ available_qty : ` ${ this . props . color ? this . props . color . available_qty : "" } ` ,
2015 }
2116 }
2217
@@ -29,23 +24,32 @@ class ProductColorEdit extends Component {
2924
3025 handleSubmit = ( e ) => {
3126 e . preventDefault ( ) ;
32- // let product_id = this.props.match.params.id
33- // let businessId = this.props.product.attributes.business_id
34- // // console.log(business_id)
35- // // console.log(product_id)
36- // let color = {...this.state, product_id}
37- // // console.log("color" , color)
38- // this.props.createColor(color)
39- // this.props.history.push(`/businesses/${businessId}/products/${product_id}`);
40- // this.setState({
41- // color_name: "",
42- // available_qty: "",
43- // })
27+ let product_id = this . props . color . product_id
28+ console . log ( product_id )
29+
30+ let businessId = this . props . productId . attributes . business_id
31+ let color_id = this . props . color . id
32+
33+ let color = { ...this . state , color_id, product_id}
34+ console . log ( "color" , color )
35+
36+ this . props . editColor ( color ) ;
37+
38+ this . props . history . push ( `/businesses/${ businessId } /products/${ product_id } ` ) ;
39+ // this.props.history.push(`/businesses`);
40+ this . setState ( {
41+ color_name : "" ,
42+ available_qty : "" ,
43+ } )
4444 }
4545
4646
4747
4848 render ( ) {
49+
50+ const { loggedIn } = this . props ;
51+ if ( ! loggedIn ) return < Redirect to = '/' />
52+
4953 return (
5054 < div className = "container-form" >
5155 < div className = "middle-container" >
@@ -57,14 +61,14 @@ class ProductColorEdit extends Component {
5761 < div className = "label" >
5862 < label htmlFor = "color_name" > Color name: </ label >
5963 </ div >
60- < input type = "text" name = "color_name" id = "color_name" placeholder = "Enter Color Name" onChange = { this . handleChange } required />
64+ < input type = "text" name = "color_name" id = "color_name" placeholder = "Enter Color Name" value = { this . state . color_name } onChange = { this . handleChange } required />
6165 </ div >
6266
6367 < div className = "row" >
6468 < div className = "label" >
6569 < label htmlFor = "available_qty" > Available Quantity: </ label >
6670 </ div >
67- < input type = "text" name = "available_qty" id = "available_qty" placeholder = "available qty" onChange = { this . handleChange } required />
71+ < input type = "text" name = "available_qty" id = "available_qty" placeholder = "available qty" value = { this . state . available_qty } onChange = { this . handleChange } required />
6872 </ div >
6973
7074 < div className = "row" >
@@ -81,9 +85,10 @@ class ProductColorEdit extends Component {
8185
8286const mapStateToProps = state => {
8387 return {
84- products : state . productReducer ,
85- loggedIn : ! ! state . currentUser
86- }
87- }
88+ loggedIn : ! ! state . currentUser ,
89+ businesses : state . businessReducer ,
90+ } ;
91+ }
92+
8893
89- export default connect ( mapStateToProps ) ( ProductColorEdit ) ;
94+ export default connect ( mapStateToProps , { editColor } ) ( ProductColorEdit ) ;
0 commit comments