Advertisement
enkf

Untitled

Jan 17th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {StyleSheet, View, Text, TextInput, ActivityIndicator, Image, ScrollView } from 'react-native';
  3. import AsyncStorage from '@react-native-community/async-storage';
  4. import { Button, CardItem, Card } from 'native-base'
  5. import Axios from 'axios';
  6.  
  7.  
  8.  
  9. class Promotions extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. id:'',
  14. treatment_id: '',
  15. title: '',
  16. desc: '',
  17. image:'',
  18. status:'',
  19. token: '',
  20. promotionsSource: []
  21. }
  22. }
  23.  
  24.  
  25.  
  26. async componentDidMount () {
  27. const token = await AsyncStorage.getItem('token')
  28. Axios({
  29. method: 'get',
  30. url: 'http://192.168.56.1/vzuu/public/api/promotions',
  31. dataType: 'json',
  32. headers: {
  33. 'Accept': 'application/json',
  34. 'Content-Type': 'application/json',
  35. 'Authorization': 'Bearer ' + token,
  36. },
  37. })
  38. .then(response => {
  39. var promotion = [];
  40. for (var i = 0; i < response.data.results.promotions.length; i++) {
  41. promotion.push([
  42. response.data.results.promotions[i].id,
  43. response.data.results.promotions[i].treatment_id,
  44. response.data.results.promotions[i].title,
  45. response.data.results.promotions[i].desc,
  46. response.data.results.promotions[i].image,
  47. response.data.results.promotions[i].status,
  48. response.data
  49. ]);
  50. }
  51. this.setState({
  52. promotionsSource: promotions,
  53. })
  54. });
  55. console.log(this.state.data);
  56.  
  57. Axios({
  58. method: 'get',
  59. url: 'http://192.168.56.1/vzuu/public/api/treatments',
  60. dataType: 'json',
  61. headers: {
  62. 'Accept': 'application/json',
  63. 'Content-Type': 'application/json',
  64. // 'Authorization': 'Bearer ' + token,
  65. },
  66. })
  67. .then(response => {
  68.  
  69. this.setState({ promotionsSource: response.data.results.treatments });
  70. });
  71. console.log(this.state.data);
  72. }
  73.  
  74. render() {
  75.  
  76. return(
  77. <ScrollView>
  78. <View style={{ padding: 14, }}>
  79. <Card>
  80. <Image style={styles.img} source={require('../../asset/images/diskon.png')} />
  81. <Text
  82. style={styles.text}>
  83. {this.props.name}
  84. </Text>
  85. </Card>
  86. <Card>
  87. <Image style={styles.img} source={require('../../asset/images/diskon.png')} />
  88. <Text
  89. style={styles.text}>
  90. Get Promotion Discount Treatment Up 50%
  91. </Text>
  92. </Card>
  93. </View>
  94. </ScrollView>
  95. )
  96. }
  97. }
  98.  
  99. export default Promotions;
  100. const styles = StyleSheet.create({
  101. container: { flex: 1, justifyContent: 'center', alignItems: 'center' },
  102. img: {width: 370, height: 200},
  103. text: { fontSize: 18, fontWeight: 'bold', color: '#E91E63', alignItems: 'center', justifyContent: 'center' }
  104. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement