Skip to main content

8.25 Implementing Button Component

BurgerBuilder.js

BurgerBuilder.js
...

purchaseContinueHandler = () => {
alert("You continue!");
};
render() {
const disabledInfo = {
...this.state.ingredients,
};

for (let key in disabledInfo) {
disabledInfo[key] = disabledInfo[key] <= 0;
}

return (
<Fragment>
<Modal
show={this.state.purchasing}
modalClosed={this.purchaseCancelHandler}
>
<OrderSummary
ingredients={this.state.ingredients}
purchaseCancelled={this.purchaseCancelHandler}
purchaseContinued={this.purchaseContinueHandler}
/>
</Modal>

...

OrderSummary.js

OrderSummary.js
import React, { Fragment } from "react";
import Button from "../../UI/Button/Button";

const orderSummary = (props) => {
const ingredientSummary = Object.keys(props.ingredients).map((igKey) => {
return (
<li key={igKey}>
<span style={{ textTransform: "capitalize" }}>{igKey}</span>:{" "}
{props.ingredients[igKey]}
</li>
);
});

return (
<Fragment>
<h3>Your Order</h3>
<p>A delicious burger with the following ingredients:</p>
<ul>{ingredientSummary}</ul>
<p>Continue to Checkout?</p>
<Button btnType="Danger" clicked={props.purchaseCancelled}>
CANCEL
</Button>
<Button btnType="Success" clicked={props.purchaseContinued}>
CONTINUE
</Button>
</Fragment>
);
};

export default orderSummary;