Skip to content

Commit

Permalink
Define ingredientes únicos
Browse files Browse the repository at this point in the history
  • Loading branch information
victormiguez committed Dec 11, 2018
1 parent a828eab commit d2fc743
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 4 additions & 1 deletion dojos/20181212-jest-enzyme/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ const ingredients = [
id: '1',
name: "Pão italiano",
price: 10,
unique: true,
},
{
id: '2',
name: "Pão de brioche",
price: 10,
unique: true,
},
{
id: '3',
Expand Down Expand Up @@ -112,6 +114,7 @@ class App extends Component {

{ingredients.map(ingredient => (
<Ingredient
cart={this.state.cart}
ingredient={ingredient}
addItem={this.addIngredientToCart}
key={ingredient.id}
Expand All @@ -125,7 +128,7 @@ class App extends Component {
removeItem={this.removeIngredientFromCart}
/>

<span>Total: {this.state.cart.total}</span>
<span>Total: R${this.state.cart.total}</span>
</Fragment>
);
}
Expand Down
13 changes: 11 additions & 2 deletions dojos/20181212-jest-enzyme/src/Components/Ingredient/Ingredient.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import React from 'react';

import './Ingredient.css';

const Ingredient = ({ ingredient, addItem }) => {
const Ingredient = ({ ingredient, addItem, cart }) => {
const isInCart = cart.items.includes(ingredient);

return (
<div className="ingredient">
<p className="ingredient__info">
<span className="ingredient__name">{ingredient.name}</span>
<span className="ingredient__price">R${ingredient.price}</span>
</p>

<button type="button" onClick={() => addItem(ingredient)} className="ingredient__button">Adicionar</button>
<button
type="button"
onClick={() => addItem(ingredient)}
className="ingredient__button"
disabled={ingredient.unique && isInCart}
>
Adicionar
</button>
</div>
);
};
Expand Down

0 comments on commit d2fc743

Please sign in to comment.