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' ;
44import PropTypes from 'prop-types' ;
55import 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' ;
79
810class 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- } ;
1611
1712 componentWillUnmount ( ) {
1813 this . props . reset ( ) ;
1914 }
2015
16+ onSubmit = values => {
17+ this . props . create ( values ) ;
18+ Actions . { { { lc } } } List ( ) ;
19+ delayRefresh ( ) ;
20+ } ;
21+
2122 render ( ) {
23+
24+ if ( this . props . created ) return Actions . pop ( ) ;
25+
26+ const { viewStyle, textStyle} = styles ;
27+
2228 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 >
2636 ) ;
2737 }
2838}
2939
30- const mapStateToProps = ( state ) => {
40+ const mapStateToProps = state => {
3141 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+ } ;
3646} ;
3747
38- const mapDispatchToProps = ( dispatch ) => {
48+ const mapDispatchToProps = dispatch => {
3949 return {
4050 create : values => dispatch ( create ( values ) ) ,
4151 reset : ( ) => {
@@ -45,4 +55,28 @@ const mapDispatchToProps = (dispatch) => {
4555 } ;
4656} ;
4757
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+
4882export default connect ( mapStateToProps , mapDispatchToProps ) ( Create ) ;
0 commit comments