11import React from 'react' ;
2+ import { connect , ConnectedProps } from 'react-redux' ;
23import { Form , Input , Button , Select } from 'antd' ;
34import { PhoneBrand } from 'src/constants/products' ;
4- import { is } from 'immer/dist/internal' ;
5+ import { useHistory } from 'react-router-dom' ;
6+
7+ import { createProduct } from './Product.thunks' ;
8+ import { PATH } from 'src/constants/paths' ;
59const { Option } = Select ;
610
7- export const ProductForm = ( ) => {
8- const onSelectChange = value => {
9- //eslint-disable-next-line
10- console . log ( `selected ${ value } ` ) ;
11- } ;
11+ const mapStateToProps = ( state : AppState ) => ( {
12+ products : state . products . products ,
13+ } ) ;
14+ const mapDispatchToProps = { createProduct } ;
15+ const connector = connect ( mapStateToProps , mapDispatchToProps ) ;
16+ interface Props extends ConnectedProps < typeof connector > { }
17+
18+ export const _ProductForm = ( props : Props ) => {
19+ const { createProduct } = props ;
20+ const history = useHistory ( ) ;
1221 const layout = {
1322 labelCol : { span : 4 } ,
1423 wrapperCol : { span : 16 } ,
1524 } ;
1625
1726 const onFinish = values => {
18- console . log ( values ) ;
27+ createProduct ( values ) ;
28+ history . push ( PATH . HOME ) ;
1929 } ;
2030
2131 const allBrands = Object . values ( PhoneBrand ) . filter (
@@ -63,7 +73,6 @@ export const ProductForm = () => {
6373 style = { { width : 200 } }
6474 placeholder = "Select a brand"
6575 optionFilterProp = "children"
66- onChange = { onSelectChange }
6776 filterOption = { ( input , option ) =>
6877 option ?. children . toLowerCase ( ) . indexOf ( input . toLowerCase ( ) ) >=
6978 0
@@ -89,3 +98,5 @@ export const ProductForm = () => {
8998 </ div >
9099 ) ;
91100} ;
101+
102+ export const ProductForm = connector ( _ProductForm ) ;
0 commit comments