Skip to content

Commit

Permalink
Combining REDUCERS in [reducers/order.js] & [reducers/burgerBuilder.js]
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch-sriram committed Aug 28, 2020
1 parent c4299ca commit f521ec4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 29 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,4 @@ Dependency Installation: **`npm i --save redux-thunk`**
10. The Order **`REDUCER`**: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/c96dbb6ba4f585e6bb6bfd895b1979d4cba912ae)
11. Working on Order **`ACTIONS`**: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/d24c2cc486b23d0bc3d4d481c5451df39a48aa41)
12. Redirect in `<ContactData />` to Improve UX: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/e114f5c158cd8a4383d643137b1b91e48471ccf7)
13. Combining REDUCERS in **`\[./store/reducers/order.js\]`** & **`\[./store/reducers/burgerBuilder.js\]`**: [Commit Details]()
6 changes: 3 additions & 3 deletions src/containers/BurgerBuilder/BurgerBuilder.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ class BurgerBuilder extends Component {
// REDUX STORE SETUP
const mapStateToProps = state => {
return {
ings: state.ingredients,
price: state.totalPrice,
error: state.error,
ings: state.burgerBuilder.ingredients,
price: state.burgerBuilder.totalPrice,
error: state.burgerBuilder.error,
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/containers/Checkout/Checkout.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Checkout extends Component {
}

const mapStateToProps = state => {
return { ings: state.ingredients };
return { ings: state.burgerBuilder.ingredients };
}

export default connect(mapStateToProps)(Checkout);
25 changes: 3 additions & 22 deletions src/containers/Checkout/ContactData/ContactData.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,25 +140,6 @@ class ContactData extends Component {
};

this.props.onOrderBurger(order);

// this.setState({ loading: true }, () => {

// axios
// .post("/orders.json", order)
// .then(response => {
// this.setState({ loading: false }, () => {
// this.props.history.push("/");
// console.log(response);
// return response;
// });
// })
// .catch(error => {
// this.setState({ loading: false }, () => {
// console.log(error);
// return error;
// });
// });
// });
};

// RIGHT WAY FOR VALIDATION USING INTERPOLATION
Expand Down Expand Up @@ -232,9 +213,9 @@ class ContactData extends Component {

const mapStateToProps = state => {
return {
ings: state.ingredients,
price: state.totalPrice,
loading: state.loading,
ings: state.burgerBuilder.ingredients,
price: state.burgerBuilder.totalPrice,
loading: state.order.loading,
};
}

Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware, compose } from 'redux';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import thunk from 'redux-thunk';

import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import burgerBuilderReducer from './store/reducers/burgerBuilder';
import orderReducer from './store/reducers/order';

const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(burgerBuilderReducer, composeEnhancers(applyMiddleware(thunk)));

// REDUCER SETUP - Combining Reducers
const rootReducer = combineReducers({
burgerBuilder: burgerBuilderReducer,
order: orderReducer,
});

const store = createStore(rootReducer, composeEnhancers(applyMiddleware(thunk)));

// NOTE: The <Provider /> should wrap all components to be rendered on the DOM.
const app = (
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const purchaseBurgerAsync = orderData => (
.post("/orders.json", orderData)
.then(response => {
console.log(response.data);
dispatch(purchaseBurgerSuccess(response.data, orderData));
dispatch(purchaseBurgerSuccess(response.data.name, orderData));
})
.catch(error => {
dispatch(purchaseBurgerFail(error));
Expand Down

0 comments on commit f521ec4

Please sign in to comment.