Advertisement
Guest User

Untitled

a guest
Jan 8th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. import React from 'react';
  2. import {StyleSheet, Text, View, ScrollView, TouchableOpacity} from 'react-native';
  3.  
  4. import {Card, Button} from 'react-native-elements';
  5. import TextInput from 'react-native-material-textinput';
  6. import DatePicker from 'react-native-datepicker';
  7. import { postUserAccount } from '../services/accountservices';
  8.  
  9. export default class Register extends React.Component {
  10.  
  11. constructor(props) {
  12. super(props);
  13. this.state = {
  14. accounts: [{
  15. account_id: '',
  16. name: '',
  17. nik: '',
  18. birthdate: '',
  19. address: '',
  20. username: '',
  21. password: '',
  22. phonenumber: '',
  23. balance: '',
  24. status: ''
  25.  
  26. }]
  27. }
  28. }
  29.  
  30. updateValue(text, field){
  31. if(field=='name'){
  32. this.setState({
  33. name:text,
  34. })
  35. }else if (field=='nik'){
  36. this.setState({
  37. nik:text
  38. })
  39. }else if (field=='birthdate'){
  40. this.setState({
  41. birthdate: text
  42. })
  43. }else if(field=='address'){
  44. this.setState({
  45. address: text
  46. })
  47. }else if(field=='username'){
  48. this.setState({
  49. username:text
  50. })
  51. }else if(field=='password'){
  52. this.setState({
  53. password:text
  54. })
  55. }else if (field=='phonenumber'){
  56. this.setState({
  57. phonenumber:text
  58. })
  59. }
  60. }
  61.  
  62. submit()
  63. {
  64. let accounts={}
  65. accounts.name=this.state.name,
  66. accounts.nik=this.state.nik,
  67. accounts.birthdate=this.state.birthdate,
  68. accounts.address=this.state.address,
  69. accounts.username=this.state.username,
  70. accounts.password=this.state.password,
  71. accounts.phonenumber=this.state.phonenumber
  72.  
  73. var url = 'http://192.168.1.23:3000/account';
  74.  
  75. fetch(url, {
  76. method: 'POST', // or 'PUT'
  77. body: JSON.stringify(accounts), // data can be `string` or {object}!
  78. headers:{
  79. 'Content-Type': 'application/json'
  80. }
  81. }).then(res => res.json())
  82. .then(response => console.log('Success:', JSON.stringify(response)))
  83. .catch(error => console.error('Error:', error));
  84. }
  85.  
  86. render() {
  87. return (
  88. <View style={styles.container}>
  89. {/*<View style={styles.circle}/>*/}
  90. <ScrollView>
  91. <Card title={'Register Account'}>
  92.  
  93. {/*<ValidateTextInput*/}
  94. {/*errorItem={this.state.errorText}*/}
  95. {/*typeInput={"name"}*/}
  96. {/*// styleIcon={{*/}
  97. {/*// color: 'red'*/}
  98. {/*// }}*/}
  99. {/*onChangeTextInput={(text) => {*/}
  100.  
  101. {/*this._onProcessTextChange(text);*/}
  102. {/*this.updateValue(text, 'name');*/}
  103. {/*}}*/}
  104. {/*hiddenIcon={false}*/}
  105. {/*typeErrorView={"bottomInput"}*/}
  106. {/*hiddenIconErrorView={true}*/}
  107. {/*/>*/}
  108. <TextInput
  109. label='Name'
  110. labelActiveColor={'#fff'}
  111. placeholder={'Enter Your Name'}
  112. onChangeText={(text) => this.updateValue(text, 'name')}
  113. required
  114. />
  115. <TextInput
  116. label='NIK'
  117. labelActiveColor={'#fff'}
  118. placeholder={'Enter Your NIK'}
  119. onChangeText={(text) => this.updateValue(text, 'nik')}
  120. />
  121. <Text>Date Of Birth</Text>
  122. <DatePicker
  123. // label={'Date Of Birth'}
  124. style={{width: 350}}
  125. birthdate={this.state.birthdate}
  126. mode="date"
  127. format="DD-MM-YYYY"
  128. confirmBtnText="Confirm"
  129. cancelBtnText="Cancel"
  130. customStyles={{
  131. // dateIcon: {
  132. // position: 'absolute',
  133. // right: 0,
  134. // top: 4,
  135. // marginLeft: 0
  136. // },
  137. dateInput: {
  138. marginRight: 18
  139. }
  140. // ... You can check the source to find the other keys.
  141. }}
  142.  
  143. onDateChange={(text) => {
  144. this.updateValue(text, 'birthdate')}}
  145.  
  146. />
  147. <TextInput
  148. label='Address'
  149. labelActiveColor={'#fff'}
  150. onChangeText={(text) => this.updateValue(text, 'address')}
  151. />
  152. <TextInput
  153. label='Email'
  154. labelActiveColor={'#fff'}
  155. onChangeText={(text) => this.updateValue(text, 'username')}
  156. keyboardType={"email-address"}
  157. />
  158. <TextInput
  159. label='Password'
  160. labelActiveColor={'#fff'}
  161. onChangeText={(text) => this.updateValue(text, 'password')}
  162. secureTextEntry={true}
  163. />
  164. <TextInput
  165. label='Phone Number'
  166. labelActiveColor={'#fff'}
  167. onChangeText={(text) => this.updateValue(text, 'phonenumber')}
  168. />
  169. </Card>
  170. </ScrollView>
  171. <Button buttonStyle={styles.submitButton} title={'Submit'} onPress={() => this.submit()}/>
  172. </View>
  173. );
  174. }
  175.  
  176. createAccount() {
  177. const data = this.state.accounts;
  178. console.log(data);
  179. postUserAccount(data);
  180. }
  181.  
  182.  
  183.  
  184. // handleSubmit = event => {
  185. // event.preventDefault();
  186. // const accounts = {
  187. // accounts: {
  188. // this.state.accounts
  189. // }
  190. // };
  191. // }
  192. }
  193.  
  194. const styles = StyleSheet.create({
  195. container: {
  196. flex: 1,
  197. backgroundColor: '#EAFFDA',
  198. padding: 2,
  199. },
  200. circle: {
  201. margin: 10,
  202. backgroundColor: '#14b9ff',
  203. borderRadius: 100,
  204. borderColor: '#D0DB97',
  205. width: 200,
  206. height: 200,
  207. alignSelf: 'center'
  208. },
  209. input: {
  210. margin: 2,
  211. height: 40,
  212. borderColor: '#14b9ff',
  213. },
  214. submitButton: {
  215. backgroundColor: '#4D4861',
  216. padding: 10,
  217. margin: 2,
  218. height: 50,
  219. // width: 120,
  220. alignItems: 'flex-end',
  221. borderRadius: 25,
  222. },
  223. submitButtonText: {
  224. color: 'white',
  225. textAlign: 'center'
  226. },
  227. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement