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>
|
||||
|
||||
@@ -12,14 +12,14 @@ class OrdersDataContainer extends Component {
|
||||
this.props.dispatch(getActiveOrders());
|
||||
this.props.dispatch(getHistoryOrders());
|
||||
}
|
||||
|
||||
hasCurrentCustomerOrders(orders) {
|
||||
return orders.some((order) => order.isMyOrder);
|
||||
}
|
||||
|
||||
render() {
|
||||
const {activeOrders, historyOrders, type, isLoading} = this.props;
|
||||
const orders = type ? type === 'active' ? activeOrders : historyOrders : {};
|
||||
const {activeOrders, historyOrders, type, isLoading, isViewAllOrdersChecked} = this.props;
|
||||
let orders = type ? type === 'active' ? activeOrders : historyOrders : [];
|
||||
const viewAllOrders = isViewAllOrdersChecked && isViewAllOrdersChecked[type];
|
||||
if (!viewAllOrders) {
|
||||
// show only current customer orders
|
||||
orders = orders.filter(o => o.isMyOrder);
|
||||
}
|
||||
const mainTitleOrder = type.charAt(0).toUpperCase() + type.slice(1);
|
||||
|
||||
return (
|
||||
@@ -33,10 +33,10 @@ class OrdersDataContainer extends Component {
|
||||
</div>
|
||||
}
|
||||
{ (orders && !isLoading) &&
|
||||
<OrderList orders={orders} type={type}/>
|
||||
<OrderList orders={orders} type={type} showOrderCustomer={viewAllOrders}/>
|
||||
}
|
||||
{
|
||||
((orders && orders.length === 0 && !isLoading) || (orders && !this.hasCurrentCustomerOrders(orders))) &&
|
||||
!isLoading && orders.length === 0 &&
|
||||
<Alert color="info">{orderTexts.labels.NO_RECORDS}</Alert>
|
||||
}
|
||||
</WiaasBox>
|
||||
@@ -47,9 +47,10 @@ class OrdersDataContainer extends Component {
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
activeOrders: state.ordersReducer.activeOrders,
|
||||
historyOrders: state.ordersReducer.historyOrders,
|
||||
isLoading: state.ordersReducer.isLoading
|
||||
activeOrders: state.ordersReducer.activeOrders || [],
|
||||
historyOrders: state.ordersReducer.historyOrders || [],
|
||||
isLoading: state.ordersReducer.isLoading,
|
||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(OrdersDataContainer);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import React, {Component} from 'react';
|
||||
import {connect} from 'react-redux';
|
||||
import OrderListItem from './OrderListItem.jsx';
|
||||
import {WiaasTable, WiaasTableHeader, WiaasTableBody} from '../../../mainComponents/table/WiaasTable.jsx';
|
||||
import {orderTexts} from '../../../constants/ordersConstants';
|
||||
@@ -34,7 +33,7 @@ class OrderList extends Component {
|
||||
''
|
||||
];
|
||||
|
||||
if(this.props.isCompanyAdmin && this.props.isViewAllOrdersChecked[type]) {
|
||||
if(this.props.showOrderCustomer) {
|
||||
activeOrdersHeader.splice(2, 0, orderTexts.headers.PLACED_BY);
|
||||
activeOrdersHeader.join();
|
||||
historyOrdersHeader.splice(2, 0, orderTexts.headers.PLACED_BY);
|
||||
@@ -45,7 +44,7 @@ class OrderList extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const {orders, type, isCompanyAdmin, isViewAllOrdersChecked} = this.props;
|
||||
const {orders, type} = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
@@ -53,11 +52,7 @@ class OrderList extends Component {
|
||||
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
|
||||
<WiaasTableBody>
|
||||
{
|
||||
orders &&
|
||||
orders.map((order, index) =>
|
||||
(order.isMyOrder || (isCompanyAdmin && isViewAllOrdersChecked[type])) &&
|
||||
<OrderListItem key={order.id} order={order} type={type} />
|
||||
)
|
||||
orders.map(order => <OrderListItem key={order.id} order={order} type={type} />)
|
||||
}
|
||||
</WiaasTableBody>
|
||||
</WiaasTable>
|
||||
@@ -65,9 +60,4 @@ class OrderList extends Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
isCompanyAdmin: true, //state.auth.isCompanyAdmin,
|
||||
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
|
||||
});
|
||||
export default connect(mapStateToProps)(OrderList);
|
||||
export default OrderList;
|
||||
|
||||
@@ -64,7 +64,7 @@ class OrderPackage extends Component {
|
||||
<div className="package-name">{orderPackage.quantity} x {orderPackage.name}</div>
|
||||
</WiaasTableCol>
|
||||
<WiaasTableCol header="Price">
|
||||
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.price).toLocaleString()} {orderPackage.packageCurrency && orderPackage.packageCurrency.currency} {' '}
|
||||
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.price).toLocaleString()} {order.currency} {' '}
|
||||
({orderPackage.paymentType})
|
||||
</WiaasTableCol>
|
||||
<WiaasTableCol header="Services and support">
|
||||
|
||||
Reference in New Issue
Block a user