-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcartcomponent.js
109 lines (104 loc) · 3.03 KB
/
cartcomponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Component } from 'react';
import { StyleSheet,ScrollView,View,Text ,Image,TouchableOpacity,AsyncStorage} from 'react-native';
import {Card} from 'react-native-elements';
import axios from 'axios';
import { baseUrl } from '../shared/baseURL';
export default class Cart extends Component {
constructor(props) {
super(props);
this.state = {
Cartdata: undefined,
isLoading: true,
email: undefined
};
this.getemail = this.getemail.bind(this)
}
getemail = async () => {
try {
var emailaddress= await AsyncStorage.getItem("user_email");
console.log(emailaddress);
} catch (error) {
console.log('error');
}
}
componentDidMount() {
//this.getemail();
var config = {
method: 'post',
url: baseUrl+'cart/get',
data: {
EmailAddress: window.user_email
},
headers: { Authorization: `Bearer ${ window.myvar }`}
};
axios(config)
.then( response => {
this.setState({ Cartdata: response.data });
console.log(this.state.Cartdata);
this.setState({ isLoading: false });
});
}
render()
{
const {navigate} =this.props.navigation;
const { isLoading} = this.state;
if (isLoading) {
return (
<Text>Loading User Cart...</Text>
);
}
return (
<View style={style.container}>
<ScrollView >
{
this.state.Cartdata.data.map(item =>(
<View style={{ width:360}}>
<Card >
<Image source={require('./images/Dell.jpg')} style={{width:150,height:110,alignSelf:'center'}} />
<Text style={{color:'#883cad',fontSize:16,fontWeight: 'bold'}}>{item.Title}</Text>
<View
style={{ paddingTop: 10 ,borderBottomColor: 'silver', borderBottomWidth: 1, }}
/>
<Text style={{paddingTop: 2,alignSelf:'center'}}>{item.Price}</Text>
<TouchableOpacity style={style.button} onPress={() => navigate('Checkout')}>
<Text style={style.buttonstyle} >
CHECKOUT
</Text>
</TouchableOpacity>
</Card>
</View> ))
}
</ScrollView>
</View>
);
}
}
const style= StyleSheet.create(
{
container:{
backgroundColor: '#fff',
flex:1,
alignItems: 'center',
justifyContent: 'center'
},
button:
{
height: 40,
width:130,
marginVertical: 10,
fontSize: 16,
borderWidth: 0.5,
borderRadius: 25,
borderColor: '#883cad',
backgroundColor: '#883cad',
alignItems: 'center',
justifyContent: 'center',
alignSelf:'center'
},
buttonstyle:
{
fontSize:16,
fontWeight:'500',
color:'#fff'
}
});