12.07 Navigating To Contact Data Component
Checkout.js
Checkout.js
import React, { Component } from "react";
import { Route } from "react-router-dom";
import CheckoutSummary from "../../components/Order/CheckoutSummary/CheckoutSummary";
import ContactData from "./ContactData/ContactData";
class Checkout extends Component {
state = {
ingredients: {
salad: 1,
meat: 1,
cheese: 1,
bacon: 1,
},
};
componentDidMount() {
const query = new URLSearchParams(this.props.location.search);
const ingredients = {};
for (let param of query.entries()) {
ingredients[param[0]] = +param[1];
}
this.setState({ ingredients: ingredients });
}
checkoutCancelledHandler = () => {
this.props.history.goBack();
};
checkoutContinuedHandler = () => {
this.props.history.replace("/checkout/contact-data");
};
render() {
return (
<div>
<CheckoutSummary
ingredients={this.state.ingredients}
checkoutCancelled={this.checkoutCancelledHandler}
checkoutContinued={this.checkoutContinuedHandler}
/>
<Route
path={this.props.match.path + "/contact-data"}
component={ContactData}
/>
</div>
);
}
}
export default Checkout;
New ContactData.js
ContactData.js
import React, { Component } from "react";
import Button from "../../../components/UI/Button/Button";
import classes from "./ContactData.module.css";
class ContactData extends Component {
state = {
name: "",
email: "",
address: {
street: "",
postalCode: "",
},
};
render() {
return (
<div className={classes.ContactData}>
<h4>Enter your Contact Data</h4>
<form>
<input
className={classes.Input}
type="text"
name="name"
placeholder="Your Name"
/>
<input
className={classes.Input}
type="text"
name="email"
placeholder="Your Mail"
/>
<input
className={classes.Input}
type="text"
name="street"
placeholder="Street"
/>
<input
className={classes.Input}
type="text"
name="postal"
placeholder="Postal Code"
/>
<Button btnType="Success">ORDER</Button>
</form>
</div>
);
}
}
export default ContactData;
New ContactData.module.css
ContactData.module.css
.ContactData {
margin: 20px auto;
width: 80%;
text-align: center;
box-shadow: 0 2px 3px #ccc;
border: 1px solid #eee;
padding: 10px;
box-sizing: border-box;
}
.Input {
display: block;
}
@media (min-width: 600px) {
ContactData {
width: 500px;
}
}