@dhirajpatil2025/report1chart 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +11 -13
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -7,27 +7,29 @@ import {
|
|
|
7
7
|
StyleSheet,
|
|
8
8
|
} from 'react-native';
|
|
9
9
|
|
|
10
|
-
const ReportChart = ({ baseUrl,
|
|
10
|
+
const ReportChart = ({ baseUrl, height = 200 }) => {
|
|
11
11
|
const [loading, setLoading] = useState(false);
|
|
12
12
|
const [chartData, setChartData] = useState([]);
|
|
13
13
|
const [active, setActive] = useState(null);
|
|
14
14
|
const [error, setError] = useState(null);
|
|
15
15
|
|
|
16
|
+
const buttons = [
|
|
17
|
+
{ label: 'Revenue', endpoint: '/revenue-trend' },
|
|
18
|
+
{ label: 'Orders', endpoint: '/orders-trend' },
|
|
19
|
+
{ label: 'Shipments', endpoint: '/shipments-trend' },
|
|
20
|
+
];
|
|
21
|
+
|
|
16
22
|
const fetchData = async (btn) => {
|
|
17
23
|
try {
|
|
18
24
|
setActive(btn.label);
|
|
19
25
|
setLoading(true);
|
|
20
26
|
setError(null);
|
|
21
27
|
|
|
22
|
-
const res = await fetch(baseUrl
|
|
23
|
-
headers: {
|
|
24
|
-
Authorization: `Bearer ${token}`,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
+
const res = await fetch(`${baseUrl}${btn.endpoint}`);
|
|
28
29
|
const json = await res.json();
|
|
29
30
|
|
|
30
|
-
//
|
|
31
|
+
// Expecting:
|
|
32
|
+
// { labels: [...], values: [...] }
|
|
31
33
|
const formatted = json.labels.map((label, i) => ({
|
|
32
34
|
name: label,
|
|
33
35
|
value: json.values[i],
|
|
@@ -59,13 +61,9 @@ const ReportChart = ({ baseUrl, token, buttons = [], height = 200 }) => {
|
|
|
59
61
|
))}
|
|
60
62
|
</View>
|
|
61
63
|
|
|
62
|
-
{/* 🔄 LOADING */}
|
|
63
64
|
{loading && <ActivityIndicator size="large" />}
|
|
64
|
-
|
|
65
|
-
{/* ❌ ERROR */}
|
|
66
65
|
{error && <Text style={styles.error}>{error}</Text>}
|
|
67
66
|
|
|
68
|
-
{/* 📊 CHART */}
|
|
69
67
|
{!loading && chartData.length > 0 && (
|
|
70
68
|
<View style={[styles.chart, { height }]}>
|
|
71
69
|
{chartData.map((item, index) => (
|
|
@@ -98,7 +96,7 @@ const styles = StyleSheet.create({
|
|
|
98
96
|
marginHorizontal: 4,
|
|
99
97
|
paddingVertical: 8,
|
|
100
98
|
borderRadius: 6,
|
|
101
|
-
backgroundColor: '#
|
|
99
|
+
backgroundColor: '#e0e0e0',
|
|
102
100
|
alignItems: 'center',
|
|
103
101
|
},
|
|
104
102
|
activeBtn: {
|