Commit bda5bf1b authored by Darrick Yong's avatar Darrick Yong

fix getAll route

parent e4329ba7
......@@ -16,7 +16,8 @@ const App = ({ orders, fetchOrders }) => {
setFetchAttempted(true);
fetchOrders();
}
}, [fetchOrders, fetchAttempted]);
setOrdersToShow(orders);
}, [orders, fetchOrders, fetchAttempted]);
return (
<div className="app">
......
......@@ -22,19 +22,19 @@ const updateOrder = (order) => ({
export const fetchOrders = () => (dispatch) => {
OrderAPIUtil.getOrders()
.then(res => {
dispatch(receiveOrders(res))
dispatch(receiveOrders(res.data))
});
}
export const createOrder = (order) => (dispatch) =>
OrderAPIUtil.createOrder(order)
.then(res => {
dispatch(receiveOrder(res))
dispatch(receiveOrder(res.data))
});
export const editOrder = (order) => (dispatch) => {
OrderAPIUtil.editOrder(order)
.then(res => {
dispatch(updateOrder(res))
dispatch(updateOrder(res.data))
});
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ const OrderIndex = ({
}
const mapStateToProps = (state, ownProps) => {
debugger;
// debugger;
return {
orders: ownProps.orders,
}
......
......@@ -20,9 +20,9 @@ const OrdersReducer = (oldState = initialState, action) => {
byId: {},
allIds: [],
};
Object.keys(action.orders).forEach( wareId => {
orderState.allIds.push(wareId);
orderState.byId[wareId] = action.orders[wareId];
action.orders.forEach( order => {
orderState.allIds.push(order.id);
orderState.byId[order.id] = order;
})
return orderState;
case RECEIVE_ORDER:
......
// import axios from 'axios';
import axios from 'axios';
const RECEIVED = "RECEIVED";
// const FULFILLED = "FULFILLED";
// const CANCELLED = "CANCELLED";
const sampleGetAll = {
const sampleGetAll = [
// allIds: ["1", "2", "3"],
// byId: {
1: {
{
id: "1",
orderId: "o1",
status: RECEIVED,
......@@ -28,7 +28,7 @@ const sampleGetAll = {
},
],
},
2: {
{
id: "2",
orderId: "o2",
status: RECEIVED,
......@@ -49,7 +49,7 @@ const sampleGetAll = {
},
],
},
3: {
{
id: "3",
orderId: "o3",
status: RECEIVED,
......@@ -71,7 +71,7 @@ const sampleGetAll = {
],
},
// },
};
];
const sampleNew = {
id: "4",
......@@ -86,9 +86,9 @@ const createNewPromise = new Promise( (resolve, reject) => {
resolve(sampleNew)
})
export const getOrders = () => {
return getAllPromise;
};
// export const getOrders = () => {
// return getAllPromise;
// };
export const createOrder = (order) => {
return createNewPromise;
......@@ -100,6 +100,6 @@ export const editOrder = (order) => {
})
}
// export const getOrders =() => {
// return axios.get("http://localhost:8080/api/orders");
// }
\ No newline at end of file
export const getOrders =() => {
return axios.get("http://localhost:8080/api/orders");
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment