2021-11-15 17:20:32 -05:00
|
|
|
import React from 'react';
|
2021-11-15 19:01:10 -05:00
|
|
|
import { useGetProd } from '../api';
|
|
|
|
import './allProducts.css';
|
2021-11-15 17:20:32 -05:00
|
|
|
|
|
|
|
const AllProducts = ( ) => {
|
2021-11-15 19:01:10 -05:00
|
|
|
const allProducts = useGetProd();
|
2021-11-15 17:20:32 -05:00
|
|
|
|
2021-11-15 19:01:10 -05:00
|
|
|
let ProductList = () => {
|
|
|
|
if (allProducts) {
|
|
|
|
return (
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th></th>
|
|
|
|
<th>ID</th>
|
|
|
|
<th>Model #</th>
|
|
|
|
<th>Description</th>
|
|
|
|
<th>Price</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
{ allProducts.map(product => {
|
|
|
|
return (
|
|
|
|
<tr key={product.ID}>
|
|
|
|
<td>[ ]</td>
|
|
|
|
<td>{product.ID}</td>
|
|
|
|
<td>{product.productName}</td>
|
|
|
|
<td>{product.productDesc}</td>
|
|
|
|
<td>${product.price}</td>
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
</tbody>
|
|
|
|
<tfoot></tfoot>
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p> Loading... </p>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-11-15 17:20:32 -05:00
|
|
|
return (
|
|
|
|
<div className="container">
|
|
|
|
<hr />
|
2021-11-15 19:01:10 -05:00
|
|
|
<span className="danger">Fetch product list from https://api.oemautomation.com:3001 </span>
|
|
|
|
<hr />
|
|
|
|
<ProductList />
|
2021-11-15 17:20:32 -05:00
|
|
|
<hr />
|
|
|
|
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AllProducts;
|