-
Notifications
You must be signed in to change notification settings - Fork 323
/
OrderListScreen.jsx
73 lines (70 loc) · 2.08 KB
/
OrderListScreen.jsx
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
import { Table, Button } from 'react-bootstrap';
import { FaTimes } from 'react-icons/fa';
import Message from '../../components/Message';
import Loader from '../../components/Loader';
import { useGetOrdersQuery } from '../../slices/ordersApiSlice';
import { Link } from 'react-router-dom';
const OrderListScreen = () => {
const { data: orders, isLoading, error } = useGetOrdersQuery();
return (
<>
<h1>Orders</h1>
{isLoading ? (
<Loader />
) : error ? (
<Message variant='danger'>
{error?.data?.message || error.error}
</Message>
) : (
<Table striped bordered hover responsive className='table-sm'>
<thead>
<tr>
<th>ID</th>
<th>USER</th>
<th>DATE</th>
<th>TOTAL</th>
<th>PAID</th>
<th>DELIVERED</th>
<th></th>
</tr>
</thead>
<tbody>
{orders.map((order) => (
<tr key={order._id}>
<td>{order._id}</td>
<td>{order.user && order.user.name}</td>
<td>{order.createdAt.substring(0, 10)}</td>
<td>${order.totalPrice}</td>
<td>
{order.isPaid ? (
order.paidAt.substring(0, 10)
) : (
<FaTimes style={{ color: 'red' }} />
)}
</td>
<td>
{order.isDelivered ? (
order.deliveredAt.substring(0, 10)
) : (
<FaTimes style={{ color: 'red' }} />
)}
</td>
<td>
<Button
as={Link}
to={`/order/${order._id}`}
variant='light'
className='btn-sm'
>
Details
</Button>
</td>
</tr>
))}
</tbody>
</Table>
)}
</>
);
};
export default OrderListScreen;