1
1
import * as React from 'react' ;
2
2
import { connect } from 'react-redux' ;
3
3
import MetaAction from '../store/meta/MetaAction' ;
4
- import { reduxForm , Field , FormProps , FormErrors } from 'redux-form' ;
5
- import IStore from '../interfaces/IStore' ;
4
+ import { reduxForm , Field , FormProps , FormErrors , InjectedFormProps } from 'redux-form' ;
6
5
import { Dispatch } from 'redux' ;
7
- import IContactForm from '../interfaces/IContactForm' ;
8
- import IMetaReducerState from '../interfaces/reducers/IMetaReducerState' ;
9
- import IAction from '../interfaces/IAction' ;
6
+ import IMetaReducerState from '../interfaces/store/reducers/IMetaReducerState' ;
7
+ import IStore from '../interfaces/store/IStore' ;
8
+ import IContactForm from '../interfaces/views/IContactForm' ;
9
+ import CustomField from './CustomField' ;
10
10
11
- const mapStateToProps = ( state : IStore ) => ( { } ) ;
11
+ interface IStateToProps extends InjectedFormProps < IContactForm > { }
12
+
13
+ interface IDispatchToProps {
14
+ setMeta : ( meta : IMetaReducerState ) => void ;
15
+ }
16
+
17
+ const mapStateToProps = ( state : IStore ) : IStateToProps => ( {
12
18
13
- const mapDispatchToProps = ( dispatch : Dispatch < any > ) => ( {
14
- setMeta : ( meta : IMetaReducerState ) : IAction < IMetaReducerState > => dispatch ( MetaAction . setMeta ( meta ) ) ,
15
19
} ) ;
16
20
17
- interface IContactProps extends FormProps {
18
- setMeta : ( meta : IMetaReducerState ) => IAction < IMetaReducerState > ;
19
- }
21
+ const mapDispatchToProps = ( dispatch : Dispatch < any > ) : IDispatchToProps => ( {
22
+ setMeta : ( meta : IMetaReducerState ) => dispatch ( MetaAction . setMeta ( meta ) ) ,
23
+ } ) ;
20
24
21
- class Contact extends React . Component < IContactProps , { } > {
25
+ class Contact extends React . Component < IStateToProps & IDispatchToProps , { } > {
22
26
23
27
private _handleSubmitHandler : Function = ( formData : IContactForm ) => this . _onFormSubmit ( formData ) ;
24
28
@@ -37,7 +41,7 @@ class Contact extends React.Component<IContactProps, {}> {
37
41
</ div >
38
42
< form onSubmit = { handleSubmit ( this . _handleSubmitHandler ) } >
39
43
< div className = "form-group" >
40
- < Field
44
+ < CustomField
41
45
component = { this . _renderInputField }
42
46
label = "Name"
43
47
name = "name"
@@ -46,7 +50,7 @@ class Contact extends React.Component<IContactProps, {}> {
46
50
/>
47
51
</ div >
48
52
< div className = "form-group" >
49
- < Field
53
+ < CustomField
50
54
component = { this . _renderInputField }
51
55
label = "Email"
52
56
name = "email"
@@ -61,14 +65,14 @@ class Contact extends React.Component<IContactProps, {}> {
61
65
</ small >
62
66
</ div >
63
67
< div className = "form-group" >
64
- < Field
68
+ < CustomField
65
69
label = { 'Example select' }
66
70
name = "exampleSelect1"
67
71
component = { this . _renderSelect }
68
72
/>
69
73
</ div >
70
74
< div className = "form-group" >
71
- < Field
75
+ < CustomField
72
76
component = { this . _renderTextArea }
73
77
label = "Message"
74
78
name = "message"
@@ -78,20 +82,20 @@ class Contact extends React.Component<IContactProps, {}> {
78
82
< fieldset className = "form-group" >
79
83
< legend > { 'Code Quality' } </ legend >
80
84
81
- < Field
85
+ < CustomField
82
86
component = { this . _renderRadio }
83
87
label = "This code is awesome!"
84
88
name = "codeQualityRadio"
85
89
option = "1"
86
90
checked = { true }
87
91
/>
88
- < Field
92
+ < CustomField
89
93
component = { this . _renderRadio }
90
94
label = "This code is ok."
91
95
name = "codeQualityRadio"
92
96
option = "2"
93
97
/>
94
- < Field
98
+ < CustomField
95
99
component = { this . _renderRadio }
96
100
label = "This code is bad."
97
101
name = "codeQualityRadio"
@@ -100,7 +104,7 @@ class Contact extends React.Component<IContactProps, {}> {
100
104
/>
101
105
</ fieldset >
102
106
< div className = "form-check" >
103
- < Field
107
+ < CustomField
104
108
component = { this . _renderCheckbox }
105
109
label = "Did you star my repo?"
106
110
name = "starred"
@@ -250,4 +254,4 @@ export default reduxForm({
250
254
251
255
return errors ;
252
256
} ,
253
- } ) ( connect ( mapStateToProps , mapDispatchToProps ) ( Contact ) ) ;
257
+ } ) ( connect < IStateToProps , IDispatchToProps , { } > ( mapStateToProps , mapDispatchToProps ) ( Contact ) ) ;
0 commit comments