1 | import React, { useState, useEffect } from 'react';
|
---|
2 | import styles from '../../css/ProfileCss/orderHistory.module.css';
|
---|
3 |
|
---|
4 | const OrderCard = () => {
|
---|
5 | const [orders, setOrders] = useState([]);
|
---|
6 |
|
---|
7 | useEffect(() => {
|
---|
8 | const token = localStorage.getItem('token');
|
---|
9 |
|
---|
10 | fetch('http://localhost:8080/api/orders/finished', {
|
---|
11 | method: 'GET',
|
---|
12 | headers: {
|
---|
13 | 'Authorization': `Bearer ${token}`
|
---|
14 | }
|
---|
15 | })
|
---|
16 | .then(response => response.json())
|
---|
17 | .then(data => {
|
---|
18 | setOrders(data);
|
---|
19 | })
|
---|
20 | .catch(error => {
|
---|
21 | console.error('Error fetching orders:', error);
|
---|
22 | });
|
---|
23 | }, []);
|
---|
24 |
|
---|
25 | return (
|
---|
26 | <div>
|
---|
27 | {orders.map(order => {
|
---|
28 | const addressParts = order.address.split(';');
|
---|
29 | const address = addressParts[0] || "Unknown address";
|
---|
30 | const number = addressParts[1] || "Unknown number";
|
---|
31 | const floor = addressParts[2] || "Unknown floor";
|
---|
32 |
|
---|
33 | return (
|
---|
34 | <div key={order.id} className={styles.orderCard}>
|
---|
35 | <div className={styles.orderDescription}>
|
---|
36 | <p>
|
---|
37 | <strong>Order id:</strong> {order.id} <br />
|
---|
38 | <strong>Address:</strong> {address} <br />
|
---|
39 | <strong>Number:</strong> {number} <br />
|
---|
40 | <strong>Floor:</strong> {floor} <br />
|
---|
41 | <strong>Delivery Person:</strong> {order.deliveryPersonName} {order.deliveryPersonSurname} <br />
|
---|
42 | <strong>Rating:</strong> {order.rating || "No rating"} <br />
|
---|
43 | <strong>Review:</strong> {order.review || "No review"} <br />
|
---|
44 | </p>
|
---|
45 | </div>
|
---|
46 | </div>
|
---|
47 | );
|
---|
48 | })}
|
---|
49 | </div>
|
---|
50 | );
|
---|
51 | };
|
---|
52 |
|
---|
53 | export default OrderCard;
|
---|