Advertisement
enkf

Untitled

Jan 23rd, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.09 KB | None | 0 0
  1. import React from 'react';
  2. import {
  3. StyleSheet,
  4. View,
  5. Text,
  6. TouchableOpacity,
  7. BackHandler,
  8. Image,
  9. ScrollView,
  10. ActivityIndicator,
  11. FlatList,
  12. } from 'react-native';
  13. import AsyncStorage from '@react-native-community/async-storage';
  14. import {
  15. Container,
  16. Header,
  17. CardItem,
  18. Left,
  19. Body,
  20. Thumbnail,
  21. } from 'native-base';
  22. import { withNavigation } from 'react-navigation';
  23. import Axios from 'axios';
  24.  
  25. class Home extends React.Component {
  26.  
  27. constructor(props) {
  28. super(props);
  29. this.state = {
  30. isLoading: false,
  31. id: '',
  32. card_member:'',
  33. member_code: '',
  34. referral_code: '',
  35. name: 'Bob',
  36. place: '',
  37. date_of_birth: '',
  38. religion: '',
  39. address:'',
  40. phone_number: '081284232952',
  41. phone_home: '',
  42. phone_office: '',
  43. image: '',
  44. email: '',
  45. password: '',
  46. token: '',
  47. data : [],
  48. renders: []
  49.  
  50. };
  51. }
  52.  
  53. ComponentWillMount() {
  54. BackHandler.addEventListener('hardwareBackPress', () => {
  55. if (!this.onMainScreen()) {
  56. this.goBack();
  57. return true;
  58. }
  59. return false;
  60. });
  61. }
  62.  
  63.  
  64. async componentDidMount(){
  65. await AsyncStorage.getItem('token')
  66. console.log(headers);
  67. // api profile
  68. const url = 'http://192.168.56.1/vzuu/public/api/members'
  69. headers = {
  70. // 'Content-Type' : 'application/json',
  71. 'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImQwMGRlM2QwNjlkMjQ1YmM0NDZhOTIwZDQ4YTM4OTlmYzE4NWY0MWRiMWIyN2M5YTg4MzcyYTk3N2Y1Y2IxMGM1MTY0NTA3MmRmOWI0ZDc3In0.eyJhdWQiOiI1IiwianRpIjoiZDAwZGUzZDA2OWQyNDViYzQ0NmE5MjBkNDhhMzg5OWZjMTg1ZjQxZGIxYjI3YzlhODgzNzJhOTc3ZjVjYjEwYzUxNjQ1MDcyZGY5YjRkNzciLCJpYXQiOjE1Nzk4MzcxMjcsIm5iZiI6MTU3OTgzNzEyNywiZXhwIjoxNjExNDU5NTI3LCJzdWIiOiI1Iiwic2NvcGVzIjpbXX0.RmSj4UX1HvVQiku7wkTCvbS910eYm1lNWelY9H5ib-NTWGTBvSkP0Ev7Av6m_u-uvdjP8PzuNfpL6Yo8qPYX83S8fw5oyXDb96d0S2FmIunZMzFXjbCdDoWKKipucMjTtrLGOfyAvnRjkstnwcDRgobmdEuX5E-Lzm27MZvriPLZiBvMG50QgwSzvldpzx9MRKz_Pkb_Fx53f2wKRCvFo5Xz1eTDXjSk_M-syiB2RLwuQ1ID3EmubhOC67NfCGd9fFWb4z5Sn5vXBttxvgMP7AmjGrn2Up_vbsyLLu-bYmlOMpZCLfBig3ipD_txBgA8Lm5aDfb7FHb-A1UFagvTChj0DyLg-4NzGe8oqCqNqBagt8a98dAe5iA5s5PDt_Eydk39ieElErpW8lAvrVsyhVvAh6LD3TFbdX2saHZxSy99RoVJLMFNpZKfAdxCGa235lB5NrNL_Qix-32KeGCGy7Tz2UhQWdQaDMBGXJaSJV48MNEMgNCSFlXMVb-r8oh6pDDfp8BTuofXGmg-31moJcpZFu8RO4GYgOvlbH3mib3YsOsjNsCMwKmVuaTEWDGbIWh2SemMUofODHfG0THimaCAopBMKCB2rs4MG3I-E6dbRdc6xZUKAox-xWZnH1YzqKSh8x8Lp8iB1PIWhOtAL9CO1IkCOKLL1hhs124kVM4'
  72. }
  73. fetch(url, headers, {method:'GET'})
  74. .then(data=>data.json())
  75. .then(res=> {
  76. AsyncStorage.setItem('token', res.success.token)
  77. console.log(res);
  78. // dari selesai fetching api profile
  79. setTimeout(()=>{this.setState({loading:false})},1000)
  80. this.setState({
  81. data: res.results.members,
  82. renders: res.results.members.data,
  83. })
  84. console.log(this.state.renders);
  85. })
  86. .catch(err=>console.warn({err}))
  87. }
  88.  
  89. render() {
  90. return (
  91. <Container>
  92. <View>
  93. <Header style={{ backgroundColor: '#E91E63' }} />
  94. {this.state.isLoading
  95. ? <ActivityIndicator color='#E91E63' size='large' />
  96. :
  97. <ScrollView>
  98.  
  99. <View style={{ flex: 1, alignItems: 'center' }}>
  100. <Text style={{ fontSize: 16 }}>{this.state.curTime}</Text>
  101. </View>
  102. <CardItem>
  103. <View style={{ marginHorizontal: 10 }}></View>
  104. <FlatList
  105. data={this.state.renders}
  106. renderItem={({ item }) => (
  107. <View style={{flex: 1}}>
  108. <Left>
  109. {/* <Thumbnail
  110. style={{ width: 80, height: 80 }}
  111. source={{uri : this.state.image}}
  112. /> */}
  113. {/* <Body> */}
  114. <Text style={styles.text}>{item.name}</Text>
  115. {/* <Text style={styles.text}>{item.phone_number}</Text> */}
  116. {/* <Text>Jumlah Point</Text> */}
  117. {/* </Body> */}
  118. </Left>
  119. </View>
  120. )}
  121. keyExtractor={item => item.id}
  122. />
  123. </CardItem>
  124. <View
  125. style={{
  126. flexDirection: 'row',
  127. flexWrap: 'wrap',
  128. marginHorizontal: 50,
  129. marginTop: 50,
  130. }}></View>
  131. <View
  132. style={{
  133. flexDirection: 'row',
  134. flexWrap: 'wrap',
  135. marginHorizontal: 18,
  136. marginTop: 18,
  137. }}>
  138. <View
  139. style={{
  140. justifyContent: 'space-between',
  141. flexDirection: 'row',
  142. width: '100%',
  143. marginBottom: 18,
  144. }}>
  145. <View>
  146. <TouchableOpacity onPress={() => this.props.navigation.navigate('treatment')}>
  147. <View
  148. style={{
  149. width: 100,
  150. height: 100,
  151. borderWidth: 1,
  152. borderColor: '#EFEFEF',
  153. borderRadius: 18,
  154. }}>
  155. <Image
  156. source={require('../asset/images/color/service.png')}
  157. style={{ height: 80, width: 100, flex: 1 }}
  158. />
  159. </View>
  160. <Text
  161. style={{
  162. fontSize: 12,
  163. fontWeight: 'bold',
  164. textAlign: 'center',
  165. color: '#E91E63',
  166. }}>
  167. Treatment
  168. </Text>
  169. </TouchableOpacity>
  170. </View>
  171. <View>
  172. <TouchableOpacity onPress={() => this.props.navigation.navigate('booking')}>
  173. <View
  174. style={{
  175. width: 100,
  176. height: 100,
  177. borderWidth: 1,
  178. borderColor: '#EFEFEF',
  179. borderRadius: 18,
  180. }}>
  181. <Image
  182. source={require('../asset/images/color/booking.png')}
  183. style={{ height: 80, width: 100, flex: 1 }}
  184. />
  185. </View>
  186. <Text
  187. style={{
  188. fontSize: 12,
  189. fontWeight: 'bold',
  190. textAlign: 'center',
  191. color: '#E91E63',
  192. }}>
  193. Booking
  194. </Text>
  195. </TouchableOpacity>
  196. </View>
  197. <View>
  198. <TouchableOpacity onPress={() => this.props.navigation.navigate('promotion')}>
  199. <View
  200. style={{
  201. width: 100,
  202. height: 100,
  203. borderWidth: 1,
  204. borderColor: '#EFEFEF',
  205. borderRadius: 18,
  206. }}>
  207. <Image
  208. source={require('../asset/images/color/promo.png')}
  209. style={{ height: 80, width: 100, flex: 1 }}
  210. />
  211. </View>
  212. <Text
  213. style={{
  214. fontSize: 12,
  215. fontWeight: 'bold',
  216. textAlign: 'center',
  217. color: '#E91E63',
  218. }}>
  219. Promotion
  220. </Text>
  221. </TouchableOpacity>
  222. </View>
  223. </View>
  224. </View>
  225.  
  226. <View
  227. style={{
  228. flexDirection: 'row',
  229. flexWrap: 'wrap',
  230. marginHorizontal: 18,
  231. marginTop: 18,
  232. }}>
  233. <View
  234. style={{
  235. justifyContent: 'space-between',
  236. flexDirection: 'row',
  237. width: '100%',
  238. marginBottom: 18,
  239. }}>
  240. <View>
  241. <TouchableOpacity onPress={() => this.props.navigation.navigate('point')}>
  242. <View
  243. style={{
  244. width: 100,
  245. height: 100,
  246. borderWidth: 1,
  247. borderColor: '#EFEFEF',
  248. borderRadius: 18,
  249. }}>
  250. <Image
  251. source={require('../asset/images/color/point.png')}
  252. style={{ height: 80, width: 100, flex: 1 }}
  253. />
  254. </View>
  255. <Text
  256. style={{
  257. fontSize: 12,
  258. fontWeight: 'bold',
  259. textAlign: 'center',
  260. color: '#E91E63',
  261. }}>
  262. Point
  263. </Text>
  264. </TouchableOpacity>
  265. </View>
  266. <View>
  267. <TouchableOpacity>
  268. <View
  269. style={{
  270. width: 100,
  271. height: 100,
  272. borderWidth: 1,
  273. borderColor: '#EFEFEF',
  274. borderRadius: 18,
  275. }}>
  276. <Image
  277. source={require('../asset/images/color/spin.png')}
  278. style={{ height: 80, width: 100, flex: 1 }}
  279. />
  280. </View>
  281. <Text
  282. style={{
  283. fontSize: 12,
  284. fontWeight: 'bold',
  285. textAlign: 'center',
  286. color: '#E91E63',
  287. }}>
  288. Spin
  289. </Text>
  290. </TouchableOpacity>
  291. </View>
  292. <View>
  293. <TouchableOpacity onPress={() => this.props.navigation.navigate('contact')}>
  294. <View
  295. style={{
  296. width: 100,
  297. height: 100,
  298. borderWidth: 1,
  299. borderColor: '#EFEFEF',
  300. borderRadius: 18,
  301. }}>
  302. <Image
  303. source={require('../asset/images/color/contact.png')}
  304. style={{ height: 80, width: 100, flex: 1 }}
  305. />
  306. </View>
  307. <Text
  308. style={{
  309. fontSize: 12,
  310. fontWeight: 'bold',
  311. textAlign: 'center',
  312. color: '#E91E63',
  313. }}>
  314. Contact
  315. </Text>
  316. </TouchableOpacity>
  317. </View>
  318. </View>
  319. </View>
  320.  
  321. </ScrollView>
  322. }
  323. </View>
  324. </Container>
  325. );
  326. }
  327. }
  328.  
  329.  
  330. export default withNavigation(Home);
  331. const styles = StyleSheet.create({
  332. container: {
  333. flex: 1,
  334. justifyContent: 'center',
  335. alignItems: 'center',
  336. },
  337. text: { fontSize: 18, fontWeight:'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  338. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement