File size: 1,683 Bytes
1e92f2d |
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 |
import axios from 'axios';
import React, { useEffect, useState } from 'react';
import { Table } from 'react-bootstrap';
import TableLoader from '../../Shared/TableOrder/TableOrder';
import Order from './Order';
import './OrderList.css'
const OrderList = () => {
const [orders, setOrders] = useState([]);
const [isUpdated, setIsUpdated] = useState(false);
useEffect(() => {
axios.get('https://immense-river-40491.herokuapp.com/orders')
.then(res => setOrders(res.data))
},[isUpdated])
const handleAction = (id, status) => {
setIsUpdated(true)
axios.patch(`https://immense-river-40491.herokuapp.com/statusUpdate/${id}`, {status: status })
.then(res => res.data && setIsUpdated(false))
}
return (
<div className="px-2">
{
orders.length === 0 ?
<TableLoader/>
:
<div className="orderList">
<Table hover>
<thead>
<tr>
<th>Name</th>
<th>Email ID</th>
<th>Service</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{
orders.map(order => <Order key={order._id} order={order} handleAction={handleAction}/>)
}
</tbody>
</Table>
</div>
}
</div>
);
};
export default OrderList; |