Add unit tests for backend and refactor few things on frontend
This commit is contained in:
@@ -14,31 +14,16 @@ const type = 'overview';
|
||||
class OrderCentralContainer extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
orders: [],
|
||||
isViewAllOrdersChecked: false
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.props.dispatch(fetchOrders());
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if(nextProps.isViewAllOrdersChecked[type] !== this.state.isViewAllOrdersChecked) {
|
||||
this.setState({
|
||||
isViewAllOrdersChecked: nextProps.isViewAllOrdersChecked[type] || false
|
||||
});
|
||||
this.props.dispatch(fetchOrders(nextProps.isViewAllOrdersChecked[type]));
|
||||
}
|
||||
this.setState({
|
||||
orders: nextProps.orders
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {isLoading} = this.props;
|
||||
const {isLoading, isViewAllOrdersChecked} = this.props;
|
||||
const viewAllOrders = isViewAllOrdersChecked && isViewAllOrdersChecked[type];
|
||||
const orders = viewAllOrders ? this.props.orders : this.props.orders.filter(o => o.isMyOrder);
|
||||
|
||||
return (<Col xl="8" lg="8" md="12" sm="12" xs="12">
|
||||
<WiaasBox id="order-central-gadget" mainTitle={dashboardTexts.labels.ORDER_CENTRAL} customHeader={OrderListHeader} customHeaderParams={type}>
|
||||
@@ -49,8 +34,8 @@ class OrderCentralContainer extends Component {
|
||||
</div>
|
||||
}
|
||||
{
|
||||
(this.state.orders && this.state.orders.length > 0 && !isLoading) ?
|
||||
<OrdersList orders={this.state.orders} isViewAllOrdersChecked={this.props.isViewAllOrdersChecked[type]}/> :
|
||||
(orders.length > 0 && !isLoading) ?
|
||||
<OrdersList orders={orders} showOrderCustomer={viewAllOrders}/> :
|
||||
<div className="dashborad-message">
|
||||
<Link to='/co-market'>{dashboardTexts.labels.NO_ORDERS}</Link>
|
||||
</div>
|
||||
@@ -61,7 +46,7 @@ class OrderCentralContainer extends Component {
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
orders: state.ordersCentralReducer.orders,
|
||||
orders: state.ordersCentralReducer.orders || [],
|
||||
isLoading: state.ordersCentralReducer.isLoading,
|
||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import {dashboardTexts} from '../../../constants/dashboardConstants';
|
||||
|
||||
class OrderItem extends Component {
|
||||
render() {
|
||||
const {order, isViewAllOrdersChecked} = this.props;
|
||||
const {order, showOrderCustomer} = this.props;
|
||||
|
||||
return (
|
||||
<WiaasTableRow className={'order-central-row line-' + order.status}>
|
||||
@@ -16,7 +16,7 @@ class OrderItem extends Component {
|
||||
</WiaasTableCol>
|
||||
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.dateCreated}</WiaasTableCol>
|
||||
{
|
||||
isViewAllOrdersChecked &&
|
||||
showOrderCustomer &&
|
||||
<WiaasTableCol header={dashboardTexts.tableHeaders.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>
|
||||
}
|
||||
<WiaasTableCol header={dashboardTexts.tableHeaders.REFERENCE}>{order.reference}</WiaasTableCol>
|
||||
|
||||
@@ -8,13 +8,13 @@ class OrdersList extends Component {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
isViewAllOrdersChecked: this.props.isViewAllOrdersChecked || false
|
||||
showOrderCustomer: this.props.showOrderCustomer || false
|
||||
};
|
||||
this.getHeaderForOrders = this.getHeaderForOrders.bind(this);
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.setState({isViewAllOrdersChecked: nextProps.isViewAllOrdersChecked});
|
||||
this.setState({showOrderCustomer: nextProps.showOrderCustomer});
|
||||
}
|
||||
|
||||
getHeaderForOrders() {
|
||||
@@ -27,7 +27,7 @@ class OrdersList extends Component {
|
||||
dashboardTexts.tableHeaders.STATUS,
|
||||
''
|
||||
];
|
||||
if(this.state.isViewAllOrdersChecked) {
|
||||
if(this.state.showOrderCustomer) {
|
||||
headers.splice(2, 0, dashboardTexts.tableHeaders.PLACED_BY);
|
||||
headers.join();
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class OrdersList extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const {orders, isViewAllOrdersChecked} = this.props;
|
||||
const {orders, showOrderCustomer} = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -46,7 +46,7 @@ class OrdersList extends Component {
|
||||
{
|
||||
orders &&
|
||||
orders.map((order, index) =>
|
||||
<OrderItem key={'order-' + order.number} order={order} isViewAllOrdersChecked={isViewAllOrdersChecked}/>
|
||||
<OrderItem key={'order-' + order.number} order={order} showOrderCustomer={showOrderCustomer}/>
|
||||
)
|
||||
}
|
||||
</WiaasTableBody>
|
||||
|
||||
Reference in New Issue
Block a user