Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2. import {Field, reduxForm as form} from 'redux-form';
  3. import {Dimensions,ScrollView,StyleSheet,View} from 'react-native';
  4. import {
  5.     Button,
  6.     FormLabel,
  7.     FormInput,
  8. } from 'react-native-elements';
  9. import { connect } from 'react-redux';
  10. import Spinner from 'react-native-loading-spinner-overlay';
  11. import { Grid, Col, Row, List, ListItem, InputGroup, Input, Text } from 'native-base';
  12.  
  13. import {signupUser} from '../actions/UserActions';
  14. import ErrorBox from '../components/ErrorBox';
  15. import cs from '../constants/SharedStyles';
  16.  
  17. const renderInput = ({ meta, input: { onChange, ...restInput }}) => {
  18.   const border = (meta.touched && meta.error) ? cs.borderError : cs.borderP2;
  19.   return (
  20.     <Row style={[border, cs.borderBWidth1]}>
  21.       <Input
  22.           stackedLabel
  23.           autoCorrect={false}
  24.           autoCapitalize="none"
  25.           onChangeText={onChange}
  26.           style={[cs.color000, cs.pl0, cs.f405]}
  27.           {...restInput}
  28.       />
  29.     </Row>
  30.   )
  31. }
  32.  
  33. /**
  34.  * Signup Screen
  35.  */
  36. @form({
  37.   form: 'signup',
  38.   validate: (values) => {
  39.     const errors = {};
  40.  
  41.     if (!values.email) {
  42.       errors.email = 'Email is required';
  43.     } else if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
  44.       errors.email = 'Invalid email address';
  45.     }
  46.  
  47.     return errors;
  48.   }
  49. })
  50. @connect((state) => {
  51.   return {
  52.     error: state.user.error,
  53.   }
  54. }, { signupUser })
  55. class SignupScreen extends Component {
  56.     static route = {
  57.         navigationBar: {
  58.             visible: false
  59.         }
  60.     }
  61.  
  62.     signupUser = (formProps) => {
  63.       this.props.signupUser(formProps);
  64.     }
  65.  
  66.     renderError = (error) => {
  67.         return <ErrorBox message={error} />;
  68.     }
  69.  
  70.     render = () => {
  71.         const {handleSubmit, pristine, submitting} = this.props;
  72.  
  73.         return (
  74.             <View animation="zoomInUp" style={[cs.container, cs.bgP4]}>
  75.                 <ScrollView style={{marginTop:50}}>
  76.                     <View style={[cs.ml4, cs.mr4]}>
  77.                         <Grid>
  78.                             <Row>
  79.                                 <Text style={[cs.f2, cs.fw4, cs.color000]}>
  80.                                     Sign Up
  81.                                 </Text>
  82.                             </Row>
  83.                         </Grid>
  84.                         <Grid style={[cs.mt3]}>
  85.                             <Row>
  86.                                 <Text style={[cs.f5, cs.fw4, cs.color000]}>
  87.                                     First Name
  88.                                 </Text>
  89.                             </Row>
  90.                             <Row style={[cs.borderP2, cs.borderBWidth1]}>
  91.                                 <Field type="text" component={renderInput} name="first_name" />
  92.                             </Row>
  93.                             <Row style={[cs.mt2]}>
  94.                                 <Text style={[cs.f5, cs.fw4, cs.color000]}>
  95.                                     Last Name
  96.                                 </Text>
  97.                             </Row>
  98.                             <Row style={[cs.borderP2, cs.borderBWidth1]}>
  99.                                 <Field type="email" component={renderInput} name="last_name" />
  100.                             </Row>
  101.                             <Row style={[cs.mt2]}>
  102.                                 <Text style={[cs.f5, cs.fw4, cs.color000]}>
  103.                                     Email
  104.                                 </Text>
  105.                             </Row>
  106.                             <Row style={[cs.borderP2, cs.borderBWidth1]}>
  107.                                 <Field type="text" component={renderInput} name="email" autocapitalize="none" />
  108.                             </Row>
  109.                             <Row style={[cs.mt2]}>
  110.                                 <Text style={[cs.f5, cs.fw4, cs.color000]}>
  111.                                     Phone
  112.                                 </Text>
  113.                             </Row>
  114.                             <Row style={[cs.borderP2, cs.borderBWidth1]}>
  115.                                 <Field type="text" component={renderInput} name="phone" autocapitalize="none" />
  116.                             </Row>
  117.                             <Row style={[cs.mt2]}>
  118.                                 <Text style={[cs.f5, cs.fw4, cs.color000]}>
  119.                                     Password
  120.                                 </Text>
  121.                             </Row>
  122.                             <Row style={[cs.borderP2, cs.borderBWidth1]}>
  123.                                 <Field type="password" component={renderInput} name="password" autocapitalize="none" />
  124.                             </Row>
  125.                             {this.renderError(this.props.error)}
  126.                         </Grid>
  127.                         <Grid style={[cs.bg000, cs.radius5, cs.shadow1, cs.mt2]} onPress={handleSubmit(this.signupUser.bind(this))}>
  128.                             <Row style={[cs.pl2, cs.pr2]}>
  129.                                 <Col style={[cs.pt105, cs.pb105]}>
  130.                                     <Row style={[cs.selfCenter]}>
  131.                                         <Text style={[cs.colorP2, cs.fw5, cs.f405]}>
  132.                                             Get Started
  133.                                         </Text>
  134.                                     </Row>
  135.                                 </Col>
  136.                             </Row>
  137.                             <Spinner visible={submitting} />
  138.                         </Grid>
  139.                         <Grid>
  140.                             <Row style={[cs.mt2, cs.ml4, cs.mr4]}>
  141.                                 <Text style={[cs.f6, cs.fw5, cs.color000, cs.tc]}>
  142.                                     By clicking "Get Started" I agree to the terms of service
  143.                                 </Text>
  144.                             </Row>
  145.                         </Grid>
  146.                     </View>
  147.                 </ScrollView>
  148.             </View>
  149.         );
  150.     }
  151. }
  152.  
  153. export default SignupScreen
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement