Advertisement
enkf

Untitled

Jan 23rd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.11 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: '',
  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 eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjcyYTRlNzZlMGE5OGFkMTdkMWQ3YjA3Njg3ZmZiMTA5MzcxYmJkMGE1MzA5NTc1ZTQzNjgxMDY1YzA3MTcxODNjODRiMWNkNWY5MGJkMGJkIn0.eyJhdWQiOiIzIiwianRpIjoiNzJhNGU3NmUwYTk4YWQxN2QxZDdiMDc2ODdmZmIxMDkzNzFiYmQwYTUzMDk1NzVlNDM2ODEwNjVjMDcxNzE4M2M4NGIxY2Q1ZjkwYmQwYmQiLCJpYXQiOjE1Nzk3NzI5ODQsIm5iZiI6MTU3OTc3Mjk4NCwiZXhwIjoxNjExMzk1Mzg0LCJzdWIiOiI1Iiwic2NvcGVzIjpbXX0.kWvYb3CDSa4-wpFIGUy_5dabvwWVWO09yhQOMw6P4J8a6HbhZUC4hsuiawC2zlXkZIr24qbN6Fg119Klfbap_2k2z-0-dilSS49ZLE3kiRWtsc_Iffe7GTUyTVzT3bM63riHvzlwEwNCeIVO0FtT5tQ0XLie5QOfkkjODtoBydLtn_s3NJdcUey-XbC84O8tQzw3iG65onQCXXIYmukLm79mwEXP3hmEFp8ffRinVQQ6JvS0YJl_v5vLLBXvkKcOzMZwJBG1Y-tQ7YELi85_AwomZjhKTb0bje8GdkT29Kgcz8vUzGG0mREoxnPwS3f6QRaLB_Y9ZaL56_LTpi_v3xqhIaX3bsgDdHG81L-LR8hgQePpSD1JgKy-Kn1mXeLoGPqLUFHBZDfxDYWEvORrYAut-aFaox03_12qo86qn1R3MxTFtBhZ8zqa5-EIwS5ALX-j8omz-Gu36yXJwUXTD4mrGvlQKxFqK5ijtbHyRxGwZxe-2GNbKxHTDl80hDIFTEK9rEgsneIeA8cuh-yJNSEKYSZXxSEBBUeXJDYneZg-eD1aWe7SKynw3v0H1i5h-WA5dl17jNSoFxFY4OsdZ59vXS_x6pVuEkSwFTa8X7958gpgaghPZLqyNDOr4SVAEY5haFnk2zhCdqpjdY37K6MhdgDjyTU0Vd77ItDX_7c'
  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.  
  79. // dari selesai fetching api profile
  80. setTimeout(()=>{this.setState({loading:false})},1000)
  81. this.setState({
  82. data: res.results.members,
  83. renders: res.results.members.data,
  84. })
  85. console.log(this.state.renders);
  86. })
  87. .catch(err=>console.warn({err}))
  88. }
  89.  
  90. render() {
  91. return (
  92. <Container>
  93. <View>
  94. <Header style={{ backgroundColor: '#E91E63' }} />
  95. {this.state.isLoading
  96. ? <ActivityIndicator color='#E91E63' size='large' />
  97. :
  98. <ScrollView>
  99.  
  100. <View style={{ flex: 1, alignItems: 'center' }}>
  101. <Text style={{ fontSize: 16 }}>{this.state.curTime}</Text>
  102. </View>
  103. <CardItem>
  104. <View style={{ marginHorizontal: 10 }}></View>
  105. <FlatList
  106. data={this.state.renders}
  107. renderItem={({ item }) => (
  108. <View style={{flex: 1}}>
  109. <Left>
  110. {/* <Thumbnail
  111. style={{ width: 80, height: 80 }}
  112. source={{uri : this.state.image}}
  113. /> */}
  114. {/* <Body> */}
  115. <Text style={styles.text}>{item.name}</Text>
  116. {/* <Text style={styles.text}>{item.phone_number}</Text> */}
  117. {/* <Text>Jumlah Point</Text> */}
  118. {/* </Body> */}
  119. </Left>
  120. </View>
  121. )}
  122. // keyExtractor={item => item.name}
  123. />
  124. </CardItem>
  125. <View
  126. style={{
  127. flexDirection: 'row',
  128. flexWrap: 'wrap',
  129. marginHorizontal: 50,
  130. marginTop: 50,
  131. }}></View>
  132. <View
  133. style={{
  134. flexDirection: 'row',
  135. flexWrap: 'wrap',
  136. marginHorizontal: 18,
  137. marginTop: 18,
  138. }}>
  139. <View
  140. style={{
  141. justifyContent: 'space-between',
  142. flexDirection: 'row',
  143. width: '100%',
  144. marginBottom: 18,
  145. }}>
  146. <View>
  147. <TouchableOpacity onPress={() => this.props.navigation.navigate('treatment')}>
  148. <View
  149. style={{
  150. width: 100,
  151. height: 100,
  152. borderWidth: 1,
  153. borderColor: '#EFEFEF',
  154. borderRadius: 18,
  155. }}>
  156. <Image
  157. source={require('../asset/images/color/service.png')}
  158. style={{ height: 80, width: 100, flex: 1 }}
  159. />
  160. </View>
  161. <Text
  162. style={{
  163. fontSize: 12,
  164. fontWeight: 'bold',
  165. textAlign: 'center',
  166. color: '#E91E63',
  167. }}>
  168. Treatment
  169. </Text>
  170. </TouchableOpacity>
  171. </View>
  172. <View>
  173. <TouchableOpacity onPress={() => this.props.navigation.navigate('booking')}>
  174. <View
  175. style={{
  176. width: 100,
  177. height: 100,
  178. borderWidth: 1,
  179. borderColor: '#EFEFEF',
  180. borderRadius: 18,
  181. }}>
  182. <Image
  183. source={require('../asset/images/color/booking.png')}
  184. style={{ height: 80, width: 100, flex: 1 }}
  185. />
  186. </View>
  187. <Text
  188. style={{
  189. fontSize: 12,
  190. fontWeight: 'bold',
  191. textAlign: 'center',
  192. color: '#E91E63',
  193. }}>
  194. Booking
  195. </Text>
  196. </TouchableOpacity>
  197. </View>
  198. <View>
  199. <TouchableOpacity onPress={() => this.props.navigation.navigate('promotion')}>
  200. <View
  201. style={{
  202. width: 100,
  203. height: 100,
  204. borderWidth: 1,
  205. borderColor: '#EFEFEF',
  206. borderRadius: 18,
  207. }}>
  208. <Image
  209. source={require('../asset/images/color/promo.png')}
  210. style={{ height: 80, width: 100, flex: 1 }}
  211. />
  212. </View>
  213. <Text
  214. style={{
  215. fontSize: 12,
  216. fontWeight: 'bold',
  217. textAlign: 'center',
  218. color: '#E91E63',
  219. }}>
  220. Promotion
  221. </Text>
  222. </TouchableOpacity>
  223. </View>
  224. </View>
  225. </View>
  226.  
  227. <View
  228. style={{
  229. flexDirection: 'row',
  230. flexWrap: 'wrap',
  231. marginHorizontal: 18,
  232. marginTop: 18,
  233. }}>
  234. <View
  235. style={{
  236. justifyContent: 'space-between',
  237. flexDirection: 'row',
  238. width: '100%',
  239. marginBottom: 18,
  240. }}>
  241. <View>
  242. <TouchableOpacity onPress={() => this.props.navigation.navigate('point')}>
  243. <View
  244. style={{
  245. width: 100,
  246. height: 100,
  247. borderWidth: 1,
  248. borderColor: '#EFEFEF',
  249. borderRadius: 18,
  250. }}>
  251. <Image
  252. source={require('../asset/images/color/point.png')}
  253. style={{ height: 80, width: 100, flex: 1 }}
  254. />
  255. </View>
  256. <Text
  257. style={{
  258. fontSize: 12,
  259. fontWeight: 'bold',
  260. textAlign: 'center',
  261. color: '#E91E63',
  262. }}>
  263. Point
  264. </Text>
  265. </TouchableOpacity>
  266. </View>
  267. <View>
  268. <TouchableOpacity>
  269. <View
  270. style={{
  271. width: 100,
  272. height: 100,
  273. borderWidth: 1,
  274. borderColor: '#EFEFEF',
  275. borderRadius: 18,
  276. }}>
  277. <Image
  278. source={require('../asset/images/color/spin.png')}
  279. style={{ height: 80, width: 100, flex: 1 }}
  280. />
  281. </View>
  282. <Text
  283. style={{
  284. fontSize: 12,
  285. fontWeight: 'bold',
  286. textAlign: 'center',
  287. color: '#E91E63',
  288. }}>
  289. Spin
  290. </Text>
  291. </TouchableOpacity>
  292. </View>
  293. <View>
  294. <TouchableOpacity onPress={() => this.props.navigation.navigate('contact')}>
  295. <View
  296. style={{
  297. width: 100,
  298. height: 100,
  299. borderWidth: 1,
  300. borderColor: '#EFEFEF',
  301. borderRadius: 18,
  302. }}>
  303. <Image
  304. source={require('../asset/images/color/contact.png')}
  305. style={{ height: 80, width: 100, flex: 1 }}
  306. />
  307. </View>
  308. <Text
  309. style={{
  310. fontSize: 12,
  311. fontWeight: 'bold',
  312. textAlign: 'center',
  313. color: '#E91E63',
  314. }}>
  315. Contact
  316. </Text>
  317. </TouchableOpacity>
  318. </View>
  319. </View>
  320. </View>
  321.  
  322. </ScrollView>
  323. }
  324. </View>
  325. </Container>
  326. );
  327. }
  328. }
  329.  
  330.  
  331. export default withNavigation(Home);
  332. const styles = StyleSheet.create({
  333. container: {
  334. flex: 1,
  335. justifyContent: 'center',
  336. alignItems: 'center',
  337. },
  338. text: { fontSize: 18, fontWeight:'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  339. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement