1
- import React , { Component } from 'react' ;
2
- import { ScrollView , Text } from 'react-native' ;
3
- import { connect } from 'react-redux' ;
1
+ import React , { Component } from 'react' ;
2
+ import { View , Text , ScrollView } from 'react-native' ;
3
+ import { connect } from 'react-redux' ;
4
4
import PropTypes from 'prop-types' ;
5
5
import Form from './Form' ;
6
- import { create , loading , error } from '../../actions/{{{ lc }}}/create' ;
6
+ import { create , loading , error } from '../../actions/{{{lc}}}/create' ;
7
+ import { Actions } from 'react-native-router-flux' ;
8
+ import { delayRefresh } from '../../utils/helpers' ;
7
9
8
10
class Create extends Component {
9
- static propTypes = {
10
- error : PropTypes . string ,
11
- loading : PropTypes . bool . isRequired ,
12
- created : PropTypes . object ,
13
- create : PropTypes . func . isRequired ,
14
- reset : PropTypes . func . isRequired ,
15
- } ;
16
11
17
12
componentWillUnmount ( ) {
18
13
this . props . reset ( ) ;
19
14
}
20
15
16
+ onSubmit = values => {
17
+ this . props . create ( values ) ;
18
+ Actions . { { { lc } } } List ( ) ;
19
+ delayRefresh ( ) ;
20
+ } ;
21
+
21
22
render ( ) {
23
+
24
+ if ( this . props . created ) return Actions . pop ( ) ;
25
+
26
+ const { viewStyle, textStyle} = styles ;
27
+
22
28
return (
23
- < ScrollView >
24
- < Text > Create component { { lc} } </ Text >
25
- </ ScrollView >
29
+ < View >
30
+ < ScrollView keyboardShouldPersistTaps = 'always' >
31
+ { this . props . error && < View style = { viewStyle } > < Text
32
+ style = { textStyle } > { this . props . error } </ Text > </ View > }
33
+ < Form mySubmit = { values => this . onSubmit ( values ) } />
34
+ </ ScrollView >
35
+ </ View >
26
36
) ;
27
37
}
28
38
}
29
39
30
- const mapStateToProps = ( state ) => {
40
+ const mapStateToProps = state => {
31
41
return {
32
- created : state . { { { lc } } } . create . created ,
33
- error : state . { { { lc } } } . create . error,
34
- loading : state . { { { lc } } } . create . loading ,
35
- } ;
42
+ created : state . { { { lc } } } . create . created ,
43
+ error : state . { { { lc } } } . create . error ,
44
+ loading : state . { { { lc } } } . create . loading ,
45
+ } ;
36
46
} ;
37
47
38
- const mapDispatchToProps = ( dispatch ) => {
48
+ const mapDispatchToProps = dispatch => {
39
49
return {
40
50
create : values => dispatch ( create ( values ) ) ,
41
51
reset : ( ) => {
@@ -45,4 +55,28 @@ const mapDispatchToProps = (dispatch) => {
45
55
} ;
46
56
} ;
47
57
58
+ const styles = {
59
+ viewStyle : {
60
+ borderBottomWidth : 1 ,
61
+ padding : 5 ,
62
+ backgroundColor : '#fff' ,
63
+ justifyContent : 'flex-start' ,
64
+ flexDirection : 'row' ,
65
+ borderColor : '#ddd' ,
66
+ position : 'relative' ,
67
+ } ,
68
+ textStyle : {
69
+ color : 'red' ,
70
+ textAlign : 'center' ,
71
+ } ,
72
+ } ;
73
+
74
+ Create . propTypes = {
75
+ error : PropTypes . string ,
76
+ loading : PropTypes . bool . isRequired ,
77
+ created : PropTypes . object ,
78
+ create : PropTypes . func . isRequired ,
79
+ reset : PropTypes . func . isRequired
80
+ } ;
81
+
48
82
export default connect ( mapStateToProps , mapDispatchToProps ) ( Create ) ;
0 commit comments