Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import { StyleSheet, View, Text, StatusBar, TouchableOpacity } from 'react-native';
  3. import { Field, reduxForm } from 'redux-form';
  4. import { connect } from 'react-redux';
  5. import { compose } from 'redux';
  6.  
  7. import Logo from '../components/Logo';
  8. import Form from '../components/From';
  9. import InputText from '../components/InputText';
  10.  
  11. import { Actions } from 'react-native-router-flux';
  12.  
  13. const styles = StyleSheet.create({
  14. container: {
  15. flexGrow: 1,
  16. backgroundColor: '#455a64',
  17. alignItems: 'center',
  18. justifyContent: 'center',
  19. },
  20. signupTextCont: {
  21. flexGrow: 1,
  22. alignItems: 'flex-end',
  23. justifyContent: 'center',
  24. marginVertical: 16,
  25. flexDirection: 'row'
  26. },
  27. signUpText: {
  28. color: '#fff',
  29. fontSize: 16,
  30.  
  31. },
  32. signBtn: {
  33. color: '#fff',
  34. fontSize: 16,
  35. fontWeight: 'bold',
  36. },
  37. button: {
  38. width: 100,
  39. backgroundColor: '#1c313a',
  40. borderRadius: 25,
  41. marginVertical: 10,
  42. paddingVertical: 16,
  43.  
  44. },
  45. buttonText: {
  46. fontSize: 16,
  47. fontWeight: 'bold',
  48. color: '#fff',
  49. textAlign: 'center',
  50. },
  51.  
  52. inputBox: {
  53. width: 300,
  54. backgroundColor: 'rgba(255, 255, 255, 0.3)',
  55. borderRadius: 25,
  56. paddingHorizontal: 16,
  57. fontSize: 16,
  58. color: '#fff',
  59. marginVertical: 10,
  60.  
  61. },
  62.  
  63. errorText: {
  64. color: '#DC143C',
  65. fontSize: 14,
  66. paddingHorizontal: 16,
  67. paddingBottom: 8
  68. }
  69. });
  70.  
  71.  
  72. class Signup extends Component {
  73.  
  74. goBack() {
  75. Actions.pop();
  76. }
  77.  
  78. createNewUser = (values) => {
  79. this.props.dispatch(this.createNewUser(values));
  80. }
  81.  
  82. onSubmit = (values) => {
  83. this.createNewUser(values);
  84. }
  85.  
  86. renderTextInput = (field) => {
  87. const { meta: { touched, error }, label, secureTextEntry, maxLength, keyboardType, placeholder, input: { onChange, ...restInput } } =
  88. field;
  89. return (
  90. <View>
  91. <InputText
  92. onChangeText={onChange}
  93. maxLength={maxLength}
  94. placeholder={placeholder}
  95. keyboardType={keyboardType}
  96. secureTextEntry={secureTextEntry}
  97. label={label}
  98. {...restInput} />
  99. {(touched && error) && <Text style={styles.errorText}>{error}</Text>}
  100. </View>
  101. )
  102. }
  103.  
  104.  
  105.  
  106. render() {
  107. const { handleSubmit } = this.props
  108. return (
  109. <View style={styles.container}>
  110. <Logo />
  111. {/* <Form type="Signup" onAuthButtonPress={this.createNewUser} /> */}
  112.  
  113. <Field
  114. name="name"
  115. placeholder="Name"
  116. component={this.renderTextInput} />
  117. <Field
  118. name="email"
  119. placeholder="Email"
  120. component={this.renderTextInput} />
  121. <Field
  122. name="password"
  123. placeholder="Password"
  124. secureTextEntry={true}
  125. component={this.renderTextInput} />
  126. <TouchableOpacity style={styles.button} onPress={handleSubmit(this.onSubmit)}>
  127. <Text style={styles.buttonText}>Signup</Text>
  128. </TouchableOpacity>
  129. <View style={styles.signupTextCont}>
  130. <Text style={styles.signUpText}>Already have an account? </Text>
  131. <TouchableOpacity onPress={this.goBack}><Text style={styles.signBtn}>Login</Text></TouchableOpacity>
  132. </View>
  133. </View>
  134. )
  135. }
  136. }
  137.  
  138. const validate = (values) => {
  139. const errors = {};
  140. if (!values.name) {
  141. errors.name = "Name is required"
  142. }
  143. if (!values.email) {
  144. errors.email = "Email is required"
  145. }
  146. if (!values.password) {
  147. errors.password = "Password is required"
  148. }
  149.  
  150. return errors;
  151.  
  152. }
  153.  
  154. mapDispatchToProps = (dispatch) => ({
  155. dispatch
  156. });
  157.  
  158. export default compose (
  159. connect(null, mapDispatchToProps),
  160. reduxForm({
  161. form: "register",
  162. validate
  163. })
  164. )(Signup);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement