Skip to content

Commit

Permalink
Connecting <ContactData /> Container & Order ACTIONS
Browse files Browse the repository at this point in the history
  • Loading branch information
Ch-sriram committed Aug 27, 2020
1 parent 1e8826e commit 61c94b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,4 @@ Dependency Installation: **`npm i --save redux-thunk`**
6. Initializing `ingredients` in the `<BurgerBuilder />` Component: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/c53894fff653877d267a8980e8ec466c926f36bd)
7. Changing the Order of our `ingredients` Manually: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/88607a0746a07e9c5021f56d7b8126d7487cd239)
8. Adding **`ACTIONS`** for Orders: [Commit Details](https://github.com/Ch-sriram/burger-builder/commit/ed60d4643fe02ef0684b9d1ec9271645e01b9da0)
9. Connecting `<ContactData />` Container & Order ACTIONS: [Commit Details]()
42 changes: 26 additions & 16 deletions src/containers/Checkout/ContactData/ContactData.component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { StyledButton as Button } from '../../../components/UI/Buttons/StyledBut
import Spinner from '../../../components/UI/Spinner/Spinner.component';
import axios from '../../../axios-orders';
import Input from '../../../components/UI/Input/Input.component';
import withErrorHandler from "../../../hoc/withErrorHandler/withErrorHandler.closureHOC";
import * as actions from "../../../store/actions/index";

// STYLED COMPONENTS
const FormDiv = styled.div`
Expand Down Expand Up @@ -139,21 +141,23 @@ class ContactData extends Component {
orderData: formData,
};

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;
});
});
this.props.onOrderBurger(order);

// 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;
// });
// });
});
};

Expand Down Expand Up @@ -233,4 +237,10 @@ const mapStateToProps = state => {
}
}

export default connect(mapStateToProps)(ContactData);
const mapDispatchToProps = dispatch => {
return {
onOrderBurger: orderDetails => dispatch(actions.purchaseBurgerStartAsync(orderDetails)),
};
}

export default connect(mapStateToProps, mapDispatchToProps)(withErrorHandler(ContactData, axios));

0 comments on commit 61c94b9

Please sign in to comment.