Skip to content

Commit

Permalink
Formatted dates to human readable. #23
Browse files Browse the repository at this point in the history
  • Loading branch information
jollopre committed Jun 3, 2017
1 parent 71ad854 commit fdb3c66
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
25 changes: 15 additions & 10 deletions client/src/Utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
export default function debounce(func, wait) {
let timeout = null;
return function() {
const ctx = this;
const args = arguments;
const later = function() {
timeout = null;
func.apply(ctx, args);
export default class Utils {
static debounce(func, wait) {
let timeout = null;
return function() {
const ctx = this;
const args = arguments;
const later = function() {
timeout = null;
func.apply(ctx, args);
}
clearTimeout(timeout);
timeout = setTimeout(later, wait || 200);
}
clearTimeout(timeout);
timeout = setTimeout(later, wait || 200);
}
static dateToHumanReadableString(iso8601) {
return new Date(iso8601).toString();
}
}
5 changes: 3 additions & 2 deletions client/src/components/OrderList.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Table, Alert } from 'react-bootstrap';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import { RoutesHelper } from '../Routes';
import Utils from '../Utils.js';

export default class OrderList extends Component {
render() {
Expand All @@ -18,8 +19,8 @@ export default class OrderList extends Component {
return (
<tr key={value.id}>
<td>{value.id}</td>
<td>{value.created_at}</td>
<td>{value.updated_at}</td>
<td>{Utils.dateToHumanReadableString(value.created_at)}</td>
<td>{Utils.dateToHumanReadableString(value.updated_at)}</td>
<td>
<Link to={RoutesHelper.order_path(`${value.id}`)}>Show</Link>
</td>
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/OrderShow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Customer from './Customer';
import Utils from '../Utils.js';
import { Row, Col } from 'react-bootstrap';
import { Panel } from 'react-bootstrap';

Expand All @@ -14,9 +15,9 @@ export default class OrderShow extends Component {
<Col xs={6}>
<dl className="dl-horizontal">
<dt>Created At</dt>
<dd>{order.created_at}</dd>
<dd>{Utils.dateToHumanReadableString(order.created_at)}</dd>
<dt>Updated At</dt>
<dd>{order.updated_at}</dd>
<dd>{Utils.dateToHumanReadableString(order.updated_at)}</dd>
</dl>
</Col>
<Col xs={6}>
Expand Down
6 changes: 3 additions & 3 deletions client/src/containers/OrderContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import FeatureValueService from '../services/FeatureValueService';
import OrderShow from '../components/OrderShow';
import Create from '../components/OrderItem/Create';
import List from '../components/OrderItem/List';
import debounce from '../Utils';
import Utils from '../Utils';
import { Grid, Row, Col } from 'react-bootstrap';

export default class OrderContainer extends Component {
constructor(props) {
super(props);
this.state = { order: null, products:null };
this.addOrderItem = this.addOrderItem.bind(this);
this.onChangeFeatureValue = debounce(this.onChangeFeatureValue.bind(this), 1000);
this.onChangeOrderItemQuantity = debounce(this.onChangeOrderItemQuantity.bind(this), 1000);
this.onChangeFeatureValue = Utils.debounce(this.onChangeFeatureValue.bind(this), 1000);
this.onChangeOrderItemQuantity = Utils.debounce(this.onChangeOrderItemQuantity.bind(this), 1000);
}
addOrderItem(product_id) {
OrderItemService.create(this.state.order.id, product_id)
Expand Down

0 comments on commit fdb3c66

Please sign in to comment.