create adapter for orders object and use it to accomodate for displaying
This commit is contained in:
@@ -4,7 +4,9 @@ import {
|
||||
REQUEST_ORDERS,
|
||||
RECEIVE_ORDERS
|
||||
} from '../../constants/dashboardConstants';
|
||||
import SaburlyAdapter from '../../helpers/SaburlyAdapter';
|
||||
const htmlClient = new HtmlClient();
|
||||
const saburlyAdapter = new SaburlyAdapter();
|
||||
|
||||
export const requestOrders = () => ({
|
||||
type: REQUEST_ORDERS,
|
||||
@@ -21,13 +23,13 @@ export const fetchOrders = (viewAllOrders) => {
|
||||
return dispatch => {
|
||||
dispatch(requestOrders());
|
||||
return htmlClient.fetch({
|
||||
url: `${API_SERVER}/dashboards/api/getOrderCentralInfo`,
|
||||
method: 'post',
|
||||
data: {
|
||||
viewAllOrders
|
||||
}
|
||||
url: `${API_SERVER}/wp-json/wc/v2/orders`,
|
||||
method: 'get'
|
||||
})
|
||||
.then(response => {
|
||||
const transformedOrdersArray = saburlyAdapter.transformOrdersArray(response.data);
|
||||
dispatch(recieveOrders(transformedOrdersArray));
|
||||
})
|
||||
.then(response => dispatch(recieveOrders(response.data)))
|
||||
.catch(error => {
|
||||
htmlClient.onError(error, dispatch);
|
||||
});
|
||||
|
||||
28
frontend/src/helpers/SaburlyAdapter.js
Normal file
28
frontend/src/helpers/SaburlyAdapter.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import moment from 'moment';
|
||||
|
||||
const transformOrderInArray = (order) => {
|
||||
let newOrderObject = {
|
||||
idOrder: order.id,
|
||||
orderNumber: order.number,
|
||||
orderDate: moment(order.date_created).format("Do MMM, YYYY"),
|
||||
reference: 'reference field',
|
||||
assignedTo: 'assigned to',
|
||||
fixedPrice: order.total,
|
||||
recurringPrice: 0,
|
||||
status: order.status,
|
||||
currency: order.currency
|
||||
}
|
||||
return newOrderObject;
|
||||
}
|
||||
|
||||
class SaburlyAdapter {
|
||||
|
||||
transformOrdersArray(orders) {
|
||||
return orders.map(order => {
|
||||
return transformOrderInArray(order);
|
||||
});
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
export default SaburlyAdapter;
|
||||
Reference in New Issue
Block a user