Guest User

Untitled

a guest
Apr 30th, 2018
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.61 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { View, StyleSheet, Text } from "react-native";
  3.  
  4. import ScreenConstants from "../../../models/navigation/ScreenConstants";
  5. import IconTextField from "../../../components/textfields/IconTextField";
  6. import BasicButton from "../../../components/buttons/BasicButton";
  7.  
  8. import User from "../../../models/user";
  9.  
  10. import NavigationBarView from "../../navigationBar/NavigationBarView";
  11.  
  12. import { KeyboardAwareScrollView } from "react-native-keyboard-aware-scroll-view";
  13.  
  14. import Images from "../../../assets/images";
  15. import Fonts from "../../../assets/fonts";
  16. import Colors from "../../../assets/colors";
  17. import { SimpleModalView, ModalViewType } from "../../modals/simpleModalView";
  18.  
  19. class SignUpDeveloperScreen extends Component {
  20. state = {
  21. isEditing: false,
  22. confirmPassword: __DEV__ ? "123456" : "",
  23. user: __DEV__
  24. ? User.create({
  25. firstName: "Adrian",
  26. lastName: "Piedra",
  27. email: "adrian@zipdev.co",
  28. password: "123456",
  29. role: "Developer"
  30. })
  31. : User.create({ role: "Developer" }),
  32. messageModal: {
  33. isVisible: false,
  34. message: ""
  35. }
  36. };
  37.  
  38. onFocusHandler = () => {
  39. this.setState({
  40. isEditing: true
  41. });
  42. };
  43.  
  44. onEndEditingHandler = () => {
  45. this.setState({
  46. isEditing: false
  47. });
  48. };
  49.  
  50. signUpHandler = () => {
  51. const {
  52. firstName,
  53. lastName,
  54. password,
  55. phoneNumber,
  56. email
  57. } = this.state.user;
  58.  
  59. const firstNameIsValid = firstName !== "";
  60. if (!firstNameIsValid) {
  61. alert("Please insert your first name.");
  62. return;
  63. }
  64.  
  65. const passwordIsEqual = password === this.state.confirmPassword;
  66. if (!passwordIsEqual) {
  67. alert("Password does not match the confirm password.");
  68. return;
  69. }
  70.  
  71. const passwordIsntLongEnough = password.length >= 6;
  72. if (!passwordIsntLongEnough) {
  73. alert("Password should have 6 characters or more.");
  74. return;
  75. }
  76.  
  77. const isValidEmail = this.state.user.validateEmail();
  78. if (!isValidEmail) {
  79. alert("Please insert a valid email.");
  80. return;
  81. }
  82.  
  83. this.state.user
  84. .signUp()
  85. .then(document => {
  86. this.setState({
  87. messageModal: {
  88. isVisible: true,
  89. message:
  90. "We have received your application. Check your email for a confirmation.",
  91. kindOfMessage: ModalViewType.SUCCESS_ALERT,
  92. buttons: [
  93. {
  94. text: "OK",
  95. onPress: () =>
  96. this.setState({ messageModal: { isVisible: false } })
  97. }
  98. ]
  99. }
  100. });
  101. })
  102. .catch(error => {
  103. this.setState({
  104. messageModal: {
  105. isVisible: true,
  106. message: error.message,
  107. kindOfMessage: ModalViewType.ERROR_ALERT,
  108. buttons: [
  109. {
  110. text: "OK",
  111. onPress: () =>
  112. this.setState({ messageModal: { isVisible: false } })
  113. }
  114. ]
  115. }
  116. });
  117. });
  118. };
  119.  
  120. render() {
  121. return (
  122. <View style={styles.content}>
  123. <SimpleModalView
  124. isVisible={this.state.messageModal.isVisible}
  125. message={this.state.messageModal.message}
  126. kindOfMessage={this.state.messageModal.kindOfMessage}
  127. buttons={this.state.messageModal.buttons}
  128. />
  129. <NavigationBarView
  130. navigator={this.props.navigator}
  131. leftTitle="Create Developer Account"
  132. />
  133. <KeyboardAwareScrollView
  134. scrollEnabled={this.state.isEditing}
  135. resetScrollToCoords={{ x: 0, y: 0 }}
  136. contentContainerStyle={styles.scrollContainer}
  137. showsVerticalScrollIndicator={false}
  138. >
  139. <Text style={styles.title}>Basic Information</Text>
  140. <IconTextField
  141. style={[styles.textfield]}
  142. iconName="account-outline"
  143. textFieldProps={{
  144. clearButtonMode: "while-editing",
  145. placeholder: "First Name",
  146. value: this.state.user.firstName,
  147. onChangeText: val => {
  148. this.state.user.setFirstName(val);
  149. },
  150. onFocus: this.onFocusHandler,
  151. onEndEditing: this.onEndEditingHandler
  152. }}
  153. />
  154. <IconTextField
  155. style={[styles.textfield]}
  156. iconName="account-outline"
  157. textFieldProps={{
  158. clearButtonMode: "while-editing",
  159. placeholder: "Last Name",
  160. value: this.state.user.lastName,
  161. onChangeText: val => {
  162. this.state.user.setLastName(val);
  163. },
  164. onFocus: this.onFocusHandler,
  165. onEndEditing: this.onEndEditingHandler
  166. }}
  167. />
  168. <IconTextField
  169. style={[styles.textfield]}
  170. iconName="email-outline"
  171. textFieldProps={{
  172. clearButtonMode: "while-editing",
  173. placeholder: "E-mail",
  174. value: this.state.user.email,
  175. onChangeText: val => {
  176. this.state.user.setEmail(val);
  177. },
  178. keyboardType: "email-address",
  179. onFocus: this.onFocusHandler,
  180. onEndEditing: this.onEndEditingHandler
  181. }}
  182. />
  183. <IconTextField
  184. style={[styles.textfield]}
  185. iconName="phone"
  186. textFieldProps={{
  187. clearButtonMode: "while-editing",
  188. placeholder: "Phone Number",
  189. value: this.state.user.phoneNumber,
  190. onChangeText: val => {
  191. this.state.user.setPhone(val);
  192. },
  193. keyboardType: "numeric",
  194. onFocus: this.onFocusHandler,
  195. onEndEditing: this.onEndEditingHandler
  196. }}
  197. />
  198. <IconTextField
  199. style={[styles.textfield]}
  200. iconName="lock-outline"
  201. textFieldProps={{
  202. clearButtonMode: "while-editing",
  203. placeholder: "Password",
  204. value: this.state.user.password,
  205. onChangeText: val => {
  206. this.state.user.setPassword(val);
  207. },
  208. secureTextEntry: true,
  209. onFocus: this.onFocusHandler,
  210. onEndEditing: this.onEndEditingHandler
  211. }}
  212. />
  213. <IconTextField
  214. style={[styles.textfield]}
  215. iconName="lock-outline"
  216. textFieldProps={{
  217. clearButtonMode: "while-editing",
  218. placeholder: "Confirm Password",
  219. value: this.state.user.password,
  220. onChangeText: val => {
  221. this.setState({ confirmPassword: val });
  222. },
  223. onFocus: this.onFocusHandler,
  224. secureTextEntry: true,
  225. onEndEditing: this.onEndEditingHandler
  226. }}
  227. />
  228. </KeyboardAwareScrollView>
  229. <View style={styles.buttonContainer}>
  230. <BasicButton onPress={this.signUpHandler} style={styles.button}>
  231. Confirm
  232. </BasicButton>
  233. </View>
  234. </View>
  235. );
  236. }
  237. }
  238.  
  239. const styles = StyleSheet.create({
  240. content: {
  241. backgroundColor: Colors.PURPLE_BROWN,
  242. flex: 1
  243. },
  244. scrollContainer: {
  245. flex: 1,
  246. alignItems: "center"
  247. },
  248. title: {
  249. textAlign: "left",
  250. color: Colors.WHITE_TEXT,
  251. fontFamily: Fonts.robotoLight,
  252. width: "70%",
  253. marginTop: 10
  254. },
  255. textfield: {
  256. width: "70%",
  257. height: 40,
  258. marginTop: 15
  259. },
  260. buttonContainer: {
  261. alignItems: "center"
  262. },
  263. button: {
  264. width: "70%",
  265. height: 40,
  266. marginBottom: 15
  267. }
  268. });
  269.  
  270. export default SignUpDeveloperScreen;
Add Comment
Please, Sign In to add comment