Advertisement
enkf

Untitled

Jan 13th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {StyleSheet, View, Text, TextInput, ActivityIndicator, Image } from 'react-native';
  3. import AsyncStorage from '@react-native-community/async-storage';
  4. import { Button,CardItem } 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. isLoading: false,
  14. id:'',
  15. treatment_id: '',
  16. title: '',
  17. desc: '',
  18. image:'',
  19. token: '',
  20. promotionsSource: []
  21. }
  22. }
  23.  
  24. async componentDidMount() {
  25. const token = await AsyncStorage.getItem('token')
  26. Axios({
  27. method: 'get',
  28. url: 'http://192.168.56.1/vzuu/public/api/promotions',
  29. dataType: 'json',
  30. headers: {
  31. 'Accept': 'application/json',
  32. 'Content-Type': 'application/json',
  33. 'Authorization': 'Bearer ' + token,
  34. },
  35. })
  36. .then(response => {
  37. var transaction = [];
  38. for (var i = 0; i < response.data.results.promotions.length; i++) {
  39. transaction.push([
  40. response.data.results.promotions[i].id,
  41. response.data.results.promotions[i].treatment_id,
  42. response.data.results.promotions[i].title,
  43. response.data.results.promotions[i].desc,
  44. response.data
  45. ]);
  46. }
  47. this.setState({
  48. promotionsSource: promotions,
  49. })
  50. });
  51. console.log(this.state.data);
  52.  
  53. Axios({
  54. method: 'get',
  55. url: 'http://192.168.56.1/vzuu/public/api/treatments',
  56. dataType: 'json',
  57. headers: {
  58. 'Accept': 'application/json',
  59. 'Content-Type': 'application/json',
  60. // 'Authorization': 'Bearer ' + token,
  61. },
  62. })
  63. .then(response => {
  64.  
  65. this.setState({ promotionsSource: response.data.results.treatments });
  66. });
  67. console.log(this.state.data);
  68. }
  69.  
  70. render() {
  71. if (this.state.isLoading) {
  72. return (
  73. <View style={{flex: 1, paddingTop: 20}}>
  74. <ActivityIndicator />
  75. </View>
  76. );
  77. }
  78. return(
  79. <View>
  80. <CardItem>
  81. <Image />
  82. </CardItem>
  83. <CardItem>
  84. <Text />
  85. </CardItem>
  86. </View>
  87. )
  88. }
  89. }
  90.  
  91. export default Promotions;
  92. const styles = StyleSheet.create({
  93. container: {
  94. flex: 1,
  95. justifyContent: 'center',
  96. alignItems: 'center'
  97. },
  98. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement