-
Notifications
You must be signed in to change notification settings - Fork 0
/
order-list.js
125 lines (112 loc) · 3.62 KB
/
order-list.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React from 'react';
import { Avatar, Button, Icon, Layout, ListItem, MenuItem, OverflowMenu, Text } from '@ui-kitten/components';
import { RefreshControl, StyleSheet, ToastAndroid, View } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import Reactotron from 'reactotron-react-native'
import axios from 'axios';
import { ScrollView } from 'react-native-gesture-handler';
var baseUrl = "https://standtogetherforchange.org";
const InstallButton = (props) => (
<Icon
style={styles.icon}
fill='#8F9BB3'
name='arrow-down-outline'
/>
);
const ItemImage = (props, order) => (
<Avatar
{...props}
style={[props.style, { tintColor: null }]}
source={order.ImagePath ? { uri: baseUrl + '/' + order.ImagePath } : require('./assets/image-background.jpg')}
/>
);
export const ViewOrdersScreen = ({ navigation, route }) => {
const [orders, setOrders] = React.useState([]);
const [userCategory, setUserCategory] = React.useState("");
const [refreshing, setRefreshing] = React.useState(false);
const fetchData = async () => {
let session = await AsyncStorage.getItem('@session');
session = JSON.parse(session);
const id = session.id;
setUserCategory(session.userCategory);
const params = {
target: 'orders',
userCategory: session.userCategory,
id
};
Reactotron.log({ params });
try {
// get the data from the api
const response = await axios({
method: 'get',
url: `${baseUrl}/api.php`,
params: params,
});
Reactotron.log({
response, params
});
// convert the data to json
if (response.status === 200) {
// set state with the result
setOrders(response.data);
} else {
// Reactotron.log(response);
throw new Error("An error has occurred");
}
} catch (error) {
Reactotron.log({ error });
console.error(error);
}
}
React.useEffect(() => {
// call the function
fetchData();
}, []);
const _onRefresh = () => {
setRefreshing(true);
fetchData().then(() => {
setRefreshing(false);
});
}
return (
<ScrollView
refreshControl={
<RefreshControl
refreshing={refreshing}
onRefresh={_onRefresh}
/>
}
>
{Array.isArray(orders) && orders.map((order, index) => (
<ListItem
key={index}
title={`${order.ProductName}`}
description={order.Quantity}
accessoryLeft={(props) => ItemImage(props, order)}
accessoryRight={() => (
<>
<Text category='s1'>RWF {order.Quantity * order.Price}</Text>
<Text category='s1'>{order?.payment?.apiResult?.status}</Text>
</>
)}
onPress={() => navigation.navigate('OrderDetails', { order, userCategory })}
/>
))}
</ScrollView>
);
}
const styles = StyleSheet.create({
icon: {
width: 32,
height: 32,
},
container: {
flex: 1,
flexDirection: 'row',
},
layout: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
});