This repository has been archived by the owner on Apr 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
ShipmentsTable.jsx
102 lines (87 loc) · 2.87 KB
/
ShipmentsTable.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React from 'react';
import { connect } from 'react-redux';
import { palette } from 'styles/muiTheme';
import { selectMarker } from 'routes/Dashboard/modules/Dashboard';
import {
Table,
TableBody,
TableHeader,
TableHeaderColumn,
TableRow,
TableRowColumn,
} from 'material-ui/Table';
const moment = require('moment');
const timeFormat = 'MMM Do, h:mm a';
const styles = {
wrapper: {
border: `1px solid ${palette.borderColor}`,
marginBottom: '2rem',
},
header: {
fontWeight: '700',
paddingTop: '1.5rem',
paddingBottom: '0.5rem',
},
meta: {
color: palette.textColor,
fontSize: '0.875rem',
fontWeight: '300',
paddingTop: '0.5rem',
paddingBottom: '0.5rem',
},
};
export class ShipmentsTable extends React.PureComponent {
handleClick = (rowNumber) => this.props.selectMarker('shipment', this.props.shipments[rowNumber]);
render() {
const props = this.props;
return (
<Table
wrapperStyle={styles.wrapper} onCellClick={(rowNumber) => this.handleClick(rowNumber)}
>
<TableHeader displaySelectAll={false} adjustForrowNumberCheckbox={false}>
<TableRow>
<TableHeaderColumn style={styles.meta} colSpan="5">
Active Shipments ({props.shipments.length})
</TableHeaderColumn>
</TableRow>
<TableRow>
<TableHeaderColumn style={styles.header}>Shipment #</TableHeaderColumn>
<TableHeaderColumn style={styles.header}>Status</TableHeaderColumn>
<TableHeaderColumn style={styles.header}>Destination</TableHeaderColumn>
<TableHeaderColumn style={styles.header}>Date Placed</TableHeaderColumn>
<TableHeaderColumn style={styles.header}>Estimated Time of Arrival</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody displayRowCheckbox={false}>
{props.shipments.map(shipment =>
<TableRow
key={shipment.id}
>
<TableRowColumn>{shipment.id}</TableRowColumn>
<TableRowColumn>{shipment.status}</TableRowColumn>
<TableRowColumn>{shipment.toId}</TableRowColumn>
<TableRowColumn>{moment(shipment.createdAt).format(timeFormat)}</TableRowColumn>
<TableRowColumn>
{moment(shipment.estimatedTimeOfArrival).format(timeFormat)}
</TableRowColumn>
</TableRow>
)}
</TableBody>
</Table>
);
}
}
ShipmentsTable.propTypes = {
selectMarker: React.PropTypes.func.isRequired,
shipments: React.PropTypes.array,
};
// ------------------------------------
// Connect Component to Redux
// ------------------------------------
const mapActionCreators = {
selectMarker,
};
const mapStateToProps = (state) => ({
shipments: state.dashboard.shipments,
});
export default connect(mapStateToProps, mapActionCreators)(ShipmentsTable);