Skip to content

Commit

Permalink
Funcao Remover
Browse files Browse the repository at this point in the history
  • Loading branch information
thaiane-santos committed Oct 7, 2021
1 parent d55b547 commit 43394e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/componentes/carrinho.js
Expand Up @@ -3,7 +3,7 @@ import Button from './button.js';


function Carrinho({
divOnClick,
onClick,
divClassName,
divKey,
divName,
Expand All @@ -28,7 +28,7 @@ function Carrinho({
<h1 className="divComplement"> {produtosComplement}</h1>
<h1>Quantidade: {qtd}</h1>
</div>
<Button buttonOnClick={divOnClick} buttonClass="add-button"> remover </Button>
<Button onClick={onClick} buttonClass="add-button"> remover </Button>
</div>
</>
);
Expand Down
21 changes: 17 additions & 4 deletions src/pages/pedidos/pedidos.js
Expand Up @@ -43,10 +43,22 @@ function Hall() {
}
};

const handleSubmit = (e) => {
e.preventDefault();

const remover = (e, item, index) => {
e.preventDefault();
const elemento = pedidos.find(res => res.id === item.id);

if (elemento.qtd !== 0) {
elemento.qtd -= 1;
}
if (elemento.qtd === 0) {
// alert("banana")
const listOrder = pedidos;
// remove 1 item do array
listOrder.splice(index, 1);
setPedidos([...listOrder])
}
}

const selectedProducts = products.filter(
(item) => item.type === selectedMenu
);
Expand Down Expand Up @@ -115,9 +127,10 @@ function Hall() {
produtosPrice={item.price}
qtd={item.qtd}
produtosFlavor={item.flavor}
// onClick={(evento) => adicionar(evento, item)}
onClick={(evento) => remover(evento, item, index)}
/>
</div>

)}
</section>
</section>
Expand Down

0 comments on commit 43394e4

Please sign in to comment.