Advertisement
Guest User

Untitled

a guest
Jan 11th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.90 KB | None | 0 0
  1. import React, {Component} from 'react'
  2. import {
  3. View,
  4. TextInput,
  5. Button,
  6. Text,
  7. StyleSheet,
  8. ScrollView,
  9. Image,
  10. KeyboardAvoidingView,
  11. TouchableOpacity
  12. } from 'react-native'
  13. import {postCustomer} from '../register/serviceRegister'
  14. import IconAntDesign from "../login/loginContainer";
  15. import LogoComponent from "./logo";
  16. import RadioForm, {RadioButton, RadioButtonInput, RadioButtonLabel} from 'react-native-simple-radio-button';
  17. import axios from "axios";
  18.  
  19.  
  20.  
  21. export default class RegisterSection extends Component{
  22. constructor(props){
  23. super(props)
  24. this.state={
  25. user:{
  26. firstname:'',
  27. lastname:'',
  28. gender:'',
  29. phonenumber:'',
  30. address:'',
  31. nationality:'',
  32. username:'',
  33. password:'',
  34. email:''
  35. }
  36. }
  37.  
  38. }
  39.  
  40.  
  41. handleFirst(value, key){
  42. if(key){
  43. if(key === 'firstname'){
  44. this.setState({user: {...this.state.user, firstname:value}});
  45. }else if (key === 'lastname'){
  46. this.setState({user:{...this.state.user, lastname:value}})
  47. }else if (key === 'gender'){
  48. this.setState({user:{...this.state.user,gender:value}});
  49. }else if (key === 'phonenumber'){
  50. this.setState({user:{...this.state.user, phonenumber:value}});
  51. }else if (key === 'address'){
  52. this.setState({user:{...this.state.user, address:value}});
  53. }else if (key === 'nationality'){
  54. this.setState({user:{...this.state.user,nationality:value}});
  55. }else if (key === 'username'){
  56. this.setState({user:{...this.state.user, username:value}});
  57. }else if (key === 'password'){
  58. this.setState({user:{...this.state.user, password:value}});
  59. }else{
  60. this.setState({user:{...this.state.user, email:value}})
  61. }
  62. }
  63. }
  64.  
  65. // postCustomer = async () => {
  66. // const data = this.state.user;
  67. // await postCustomer(data)
  68. // console.log(data);
  69. // }
  70. // goToScreenLogin = () =>{
  71. // this.props.navigation.navigate('LoginScreen');
  72. // }
  73.  
  74. postCustomer = async () => {
  75. const data = this.state.user;
  76. const URL = `http://192.168.1.9:3000/register`;
  77. return axios({
  78. method: 'POST',
  79. url: URL,
  80. headers: {
  81. 'Content-Type': 'application/json'
  82. },
  83. data: data,
  84. })
  85. .then(res => {
  86. console.log('Status', res.data.status);
  87. console.log('Message', res.data.message);
  88.  
  89. if(res.data.status == 404){
  90. alert('Account number not found');
  91. }else if(res.data.status == 500){
  92. alert('Your data is insufficient');
  93. }else{
  94. this.props.navigation.navigate('LoginScreen');
  95. alert(' successed');
  96. }
  97. })
  98. .catch(error => {
  99. console.log('Error', error.response.data);
  100. })
  101.  
  102. }
  103.  
  104. render(){
  105. var radio_props = [
  106. {label: 'Male', value: "M" },
  107. {label: 'Female', value: "F" },
  108. ];
  109.  
  110. return(
  111.  
  112. <ScrollView>
  113. <KeyboardAvoidingView style={styles.container}>
  114.  
  115. < View style={styles.cardLogin} behavior="position">
  116. <LogoComponent/>
  117. <Text style={{fontSize:20, marginTop:15}}>Sign Up</Text>
  118. <View style={{flexDirection: 'row'}}>
  119.  
  120.  
  121. <TextInput
  122. value = {this.state.user.firstname}
  123. style ={styles.input2}
  124. placeholder="First Name"
  125. placeholderTextColor = "#d8d8d8"
  126. onChangeText = {(text)=>(this.handleFirst(text,'firstname'))}
  127. />
  128.  
  129. <TextInput
  130. value = {this.state.user.lastname}
  131. style ={styles.input3}
  132. placeholder="Last Name"
  133. placeholderTextColor = "#d8d8d8"
  134. onChangeText = {(text)=>(this.handleFirst(text,'lastname'))}
  135. />
  136. </View>
  137. <RadioForm
  138. radio_props={radio_props}
  139. initial={0}
  140. formHorizontal={true}
  141. labelHorizontal={true}
  142. buttonColor={'#646FE4'}
  143. animation={true}
  144. style ={styles.inputRadio}
  145. buttonSize={15}
  146.  
  147. onPress={(text) => {this.handleFirst(text,'gender')}}
  148. />
  149. <TextInput
  150. value = {this.state.user.phonenumber}
  151. style ={styles.input}
  152. placeholder ='phonenumber'
  153. onChangeText = {(text)=>(this.handleFirst(text,'phonenumber'))}
  154. />
  155. <TextInput
  156. value = {this.state.user.address}
  157. style ={styles.input}
  158. placeholder ='address'
  159. onChangeText = {(text)=>(this.handleFirst(text,'address'))}
  160. />
  161. <TextInput
  162. value = {this.state.user.nationality}
  163. style ={styles.input}
  164. placeholder ='nationality'
  165. onChangeText = {(text)=>(this.handleFirst(text,'nationality'))}
  166. />
  167. <TextInput
  168. value = {this.state.user.email}
  169. style ={styles.input}
  170. placeholder ='email'
  171. onChangeText = {(text)=>(this.handleFirst(text,'email'))}
  172. />
  173. <TextInput
  174. value = {this.state.user.password}
  175. style ={styles.input}
  176. placeholder ='password'
  177. onChangeText = {(text)=>(this.handleFirst(text,'password'))}
  178. />
  179.  
  180. <TextInput
  181. value = {this.state.user.username}
  182. style ={styles.input}
  183. placeholder ='username'
  184. onChangeText = {(text)=>(this.handleFirst(text,'username'))}
  185. />
  186.  
  187. <View>
  188. <TouchableOpacity
  189. style = {styles.submitButton}
  190. onPress={()=> this.postCustomer()}>
  191. <Text style = {styles.submitButtonText}> Sign Up </Text>
  192. </TouchableOpacity>
  193. {/*<Text style={{marginTop:4, marginLeft: 40}}>OR</Text>*/}
  194. {/*<TouchableOpacity*/}
  195. {/*style = {styles.submitButton2}*/}
  196. {/*onPress={()=> this.goToScreenLogin()}>*/}
  197. {/*<Text style = {styles.submitButtonText}> Sign In </Text>*/}
  198. {/*</TouchableOpacity>*/}
  199. </View>
  200.  
  201.  
  202.  
  203. </View>
  204.  
  205.  
  206. </KeyboardAvoidingView>
  207. </ScrollView>
  208.  
  209. )
  210. }
  211.  
  212. }
  213. const styles = StyleSheet.create({
  214. cardLogin:{
  215. marginTop:100,
  216. backgroundColor:"#F7F8FD",
  217. width:"93%" ,
  218. height: 700,
  219. marginVertical: "10%",
  220. borderRadius:10,
  221. elevation: 10,
  222. alignItems: "center",
  223. shadowColor: '#646FE4'
  224.  
  225. },
  226. input: {
  227.  
  228. marginTop:15,
  229. height: 40,
  230. borderColor: '#646FE4',
  231. borderBottomWidth:1,
  232. width:300,
  233. padding: 9,
  234. elevation:0.3
  235.  
  236.  
  237.  
  238. },
  239. inputRadio: {
  240.  
  241. marginTop:15,
  242. height: 40,
  243. borderColor: '#646FE4',
  244. borderBottomWidth:1,
  245. width:300,
  246. padding: 9,
  247. elevation:0.3,
  248. justifyContent: 'space-between'
  249.  
  250.  
  251.  
  252. },
  253. input2: {
  254.  
  255. marginTop:30,
  256. height: 40,
  257. borderColor: '#646FE4',
  258. borderBottomWidth:1,
  259. width:150,
  260. padding: 9,
  261. borderRightWidth: 1,
  262. elevation:0.5
  263.  
  264. },
  265. input3: {
  266.  
  267. marginTop:30,
  268. height: 40,
  269. borderColor: '#646FE4',
  270. borderBottomWidth:1,
  271. width:150,
  272. padding: 9,
  273. elevation:0.5
  274.  
  275. },
  276. submitButton: {
  277. backgroundColor: '#646FE4',
  278. padding: 10,
  279. marginTop: 40,
  280. height: 40,
  281. borderRadius:5,
  282. elevation: 6,
  283. shadowColor: '#000000',
  284.  
  285.  
  286. },
  287. submitButton2: {
  288. backgroundColor: '#172B4D',
  289. padding: 10,
  290. marginTop: 10,
  291. height: 40,
  292. borderRadius:10,
  293. elevation: 6,
  294. shadowColor: '#000000',
  295.  
  296.  
  297. },
  298. submitButtonText:{
  299. color: 'white',
  300. textAlign: 'center',
  301. width:80
  302.  
  303.  
  304. },
  305.  
  306. container: {
  307.  
  308. width:'100%',
  309. height:'100%',
  310. backgroundColor:'#646FE4',
  311. marginBottom:15,
  312. alignItems: "center",
  313. elevation:20
  314.  
  315.  
  316. },
  317. headerComponent:{
  318. alignItems: 'center'
  319. },
  320. imageStyle:{
  321.  
  322. marginTop:100,
  323. width:60,
  324. height:60,
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331. }
  332. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement