-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSalesHistory.js
More file actions
48 lines (41 loc) · 1.22 KB
/
SalesHistory.js
File metadata and controls
48 lines (41 loc) · 1.22 KB
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
import React, { useEffect, useState } from 'react';
import { fetchSalesHistory } from '../utils/api';
const SalesHistory = () => {
const [sales, setSales] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const getSalesHistory = async () => {
try {
const data = await fetchSalesHistory();
setSales(data);
} catch (err) {
setError('Failed to fetch sales history');
} finally {
setLoading(false);
}
};
getSalesHistory();
}, []);
if (loading) {
return <div>Loading...</div>;
}
if (error) {
return <div>{error}</div>;
}
return (
<div>
<h2>Your Sales History</h2>
<ul>
{sales.map((sale) => (
<li key={sale.id}>
<h3>{sale.itemTitle}</h3>
<p>Sold for: ₹{sale.price}</p>
<p>Date: {new Date(sale.date).toLocaleDateString()}</p>
</li>
))}
</ul>
</div>
);
};
export default SalesHistory;