-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPurchaseHistory.js
More file actions
49 lines (43 loc) · 1.49 KB
/
PurchaseHistory.js
File metadata and controls
49 lines (43 loc) · 1.49 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
49
import React, { useEffect, useState } from 'react';
import { fetchPurchaseHistory } from '../utils/api';
import ReviewSystem from './ReviewSystem';
const PurchaseHistory = () => {
const [purchases, setPurchases] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
const getPurchaseHistory = async () => {
try {
const data = await fetchPurchaseHistory();
setPurchases(data);
} catch (error) {
console.error('Error fetching purchase history:', error);
} finally {
setLoading(false);
}
};
getPurchaseHistory();
}, []);
if (loading) {
return <div>Loading...</div>;
}
return (
<div className="purchase-history">
<h2>Your Purchase History</h2>
{purchases.length === 0 ? (
<p>You have not made any purchases yet.</p>
) : (
<ul>
{purchases.map((purchase) => (
<li key={purchase.id}>
<h3>{purchase.itemTitle}</h3>
<p>Price: ₹{purchase.price}</p>
<p>Date: {new Date(purchase.date).toLocaleDateString()}</p>
<ReviewSystem purchaseId={purchase.id} />
</li>
))}
</ul>
)}
</div>
);
};
export default PurchaseHistory;