TableContainer.js
1.93 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';
import { Table, Button } from 'reactstrap';
import s from './TableContainer.module.scss';
const states = {
sent: 'info',
pending: 'success',
declined: 'danger',
};
class TableContainer extends PureComponent {
static propTypes = {
data: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string,
email: PropTypes.string,
product: PropTypes.string,
price: PropTypes.string,
date: PropTypes.string,
city: PropTypes.string,
status: PropTypes.string,
}),
).isRequired,
}
render() {
const { data } = this.props;
const keys = Object.keys(data[0]).map(i => i.toUpperCase());
keys.shift(); // delete "id" key
return (
<Table className={cx('mb-0', s.table)} borderless responsive>
<thead>
<tr className="text-muted">
{keys.map((key, index) => (
index === 0
? <th key={key} scope="col"><span className="pl-2">{key}</span></th>
: <th key={key} scope="col">{key}</th>
))}
</tr>
</thead>
<tbody className="text-dark">
{
data.map(({ name, email, product, price, date, city, status }) => (
<tr key={name}>
<td className="pl-3 fw-normal">{name}</td>
<td>{email}</td>
<td>{product}</td>
<td>{price}</td>
<td>{date}</td>
<td>{city}</td>
<td>
<Button
color={states[status.toLowerCase()]}
size="xs"
className="px-2"
>
{status}
</Button>
</td>
</tr>
))
}
</tbody>
</Table>
);
}
}
export default TableContainer;