|
| 1 | +import React, { Component, PropTypes } from 'react'; |
| 2 | +import { Link } from 'react-router'; |
| 3 | +import { find, keyBy } from 'lodash'; |
| 4 | +import { Button } from 'reactstrap'; |
| 5 | + |
| 6 | +import { ListTable } from '../UI'; |
| 7 | +import { withResourceList } from '../../hocs'; |
| 8 | +import CustomerListFilter from './CustomerListFilter'; |
| 9 | + |
| 10 | +const formatDate = date => (new Date(date)).toLocaleString(); |
| 11 | + |
| 12 | +export class CustomerList extends Component { |
| 13 | + componentWillMount() { |
| 14 | + const { resourceList } = this.props; |
| 15 | + this.props.fetchResourceList({ sort: '-companyName', ...resourceList.params }); |
| 16 | + } |
| 17 | + |
| 18 | + render() { |
| 19 | + const { onFilter } = this.props; |
| 20 | + const columns = [ |
| 21 | + { |
| 22 | + attribute: 'companyName', |
| 23 | + header: 'Company Name', |
| 24 | + rowRender: customer => <Link to={`/customers/${customer.id}`}>{customer.companyName}</Link>, |
| 25 | + sortable: true, |
| 26 | + }, |
| 27 | + { |
| 28 | + attribute: 'contactName', |
| 29 | + header: 'Contact Name', |
| 30 | + rowRender: customer => <Link to={`/customers/${customer.id}`}>{customer.contactName}</Link>, |
| 31 | + sortable: true, |
| 32 | + }, |
| 33 | + { |
| 34 | + attribute: 'createdAt', |
| 35 | + header: 'Created At', |
| 36 | + rowRender: customer => formatDate(customer.confirmedAt), |
| 37 | + sortable: true, |
| 38 | + } |
| 39 | + ]; |
| 40 | + |
| 41 | + return ( |
| 42 | + <div> |
| 43 | + <Button tag={Link} to={'/customers/new'}>New Customer</Button> |
| 44 | + |
| 45 | + <CustomerListFilter |
| 46 | + onSubmit={onFilter}> |
| 47 | + </CustomerListFilter> |
| 48 | + |
| 49 | + <ListTable {...this.props} columns={columns} /> |
| 50 | + </div> |
| 51 | + ); |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +export const mapStateToProps = state => ({ |
| 56 | + filter: get(state, 'form.customerListFilter.values') || {} |
| 57 | +}); |
| 58 | + |
| 59 | +export default withResourceList('customers')(CustomerList); |
0 commit comments