Commit bda5bf1b authored by Darrick Yong's avatar Darrick Yong

fix getAll route

parent e4329ba7
...@@ -16,7 +16,8 @@ const App = ({ orders, fetchOrders }) => { ...@@ -16,7 +16,8 @@ const App = ({ orders, fetchOrders }) => {
setFetchAttempted(true); setFetchAttempted(true);
fetchOrders(); fetchOrders();
} }
}, [fetchOrders, fetchAttempted]); setOrdersToShow(orders);
}, [orders, fetchOrders, fetchAttempted]);
return ( return (
<div className="app"> <div className="app">
......
...@@ -22,19 +22,19 @@ const updateOrder = (order) => ({ ...@@ -22,19 +22,19 @@ const updateOrder = (order) => ({
export const fetchOrders = () => (dispatch) => { export const fetchOrders = () => (dispatch) => {
OrderAPIUtil.getOrders() OrderAPIUtil.getOrders()
.then(res => { .then(res => {
dispatch(receiveOrders(res)) dispatch(receiveOrders(res.data))
}); });
} }
export const createOrder = (order) => (dispatch) => export const createOrder = (order) => (dispatch) =>
OrderAPIUtil.createOrder(order) OrderAPIUtil.createOrder(order)
.then(res => { .then(res => {
dispatch(receiveOrder(res)) dispatch(receiveOrder(res.data))
}); });
export const editOrder = (order) => (dispatch) => { export const editOrder = (order) => (dispatch) => {
OrderAPIUtil.editOrder(order) OrderAPIUtil.editOrder(order)
.then(res => { .then(res => {
dispatch(updateOrder(res)) dispatch(updateOrder(res.data))
}); });
} }
\ No newline at end of file
...@@ -23,7 +23,7 @@ const OrderIndex = ({ ...@@ -23,7 +23,7 @@ const OrderIndex = ({
} }
const mapStateToProps = (state, ownProps) => { const mapStateToProps = (state, ownProps) => {
debugger; // debugger;
return { return {
orders: ownProps.orders, orders: ownProps.orders,
} }
......
...@@ -20,9 +20,9 @@ const OrdersReducer = (oldState = initialState, action) => { ...@@ -20,9 +20,9 @@ const OrdersReducer = (oldState = initialState, action) => {
byId: {}, byId: {},
allIds: [], allIds: [],
}; };
Object.keys(action.orders).forEach( wareId => { action.orders.forEach( order => {
orderState.allIds.push(wareId); orderState.allIds.push(order.id);
orderState.byId[wareId] = action.orders[wareId]; orderState.byId[order.id] = order;
}) })
return orderState; return orderState;
case RECEIVE_ORDER: case RECEIVE_ORDER:
......
// import axios from 'axios'; import axios from 'axios';
const RECEIVED = "RECEIVED"; const RECEIVED = "RECEIVED";
// const FULFILLED = "FULFILLED"; // const FULFILLED = "FULFILLED";
// const CANCELLED = "CANCELLED"; // const CANCELLED = "CANCELLED";
const sampleGetAll = { const sampleGetAll = [
// allIds: ["1", "2", "3"], // allIds: ["1", "2", "3"],
// byId: { // byId: {
1: { {
id: "1", id: "1",
orderId: "o1", orderId: "o1",
status: RECEIVED, status: RECEIVED,
...@@ -28,7 +28,7 @@ const sampleGetAll = { ...@@ -28,7 +28,7 @@ const sampleGetAll = {
}, },
], ],
}, },
2: { {
id: "2", id: "2",
orderId: "o2", orderId: "o2",
status: RECEIVED, status: RECEIVED,
...@@ -49,7 +49,7 @@ const sampleGetAll = { ...@@ -49,7 +49,7 @@ const sampleGetAll = {
}, },
], ],
}, },
3: { {
id: "3", id: "3",
orderId: "o3", orderId: "o3",
status: RECEIVED, status: RECEIVED,
...@@ -71,7 +71,7 @@ const sampleGetAll = { ...@@ -71,7 +71,7 @@ const sampleGetAll = {
], ],
}, },
// }, // },
}; ];
const sampleNew = { const sampleNew = {
id: "4", id: "4",
...@@ -86,9 +86,9 @@ const createNewPromise = new Promise( (resolve, reject) => { ...@@ -86,9 +86,9 @@ const createNewPromise = new Promise( (resolve, reject) => {
resolve(sampleNew) resolve(sampleNew)
}) })
export const getOrders = () => { // export const getOrders = () => {
return getAllPromise; // return getAllPromise;
}; // };
export const createOrder = (order) => { export const createOrder = (order) => {
return createNewPromise; return createNewPromise;
...@@ -100,6 +100,6 @@ export const editOrder = (order) => { ...@@ -100,6 +100,6 @@ export const editOrder = (order) => {
}) })
} }
// export const getOrders =() => { export const getOrders =() => {
// return axios.get("http://localhost:8080/api/orders"); return axios.get("http://localhost:8080/api/orders");
// } }
\ No newline at end of file \ 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