Skip to content

Commit f95f1a3

Browse files
committed
2-DR2-AT.13
1 parent 3db9493 commit f95f1a3

File tree

2 files changed

+49
-7
lines changed
  • 2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-AT-ecommerce-dummy-crud/src/pages/product-list

2 files changed

+49
-7
lines changed

2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-AT-ecommerce-dummy-crud/src/pages/product-list/index.jsx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ export default function ProductList() {
2222
buscaProdutos();
2323
}, []);
2424

25+
const handleExcluir = async (id) => {
26+
if (!window.confirm('Tem certeza que deseja excluir este produto?')) {
27+
return;
28+
}
29+
30+
try {
31+
await axios.delete(`https://dummyjson.com/products/${id}`);
32+
setProdutos(produtos.filter(produto => produto.id !== id));
33+
console.log('Produto excluído com sucesso');
34+
} catch (error) {
35+
console.error('Erro ao excluir produto:', error);
36+
}
37+
};
38+
2539
if (carregando) {
2640
return <div className={style.carregando}>Carregando produtos...</div>;
2741
}
@@ -37,12 +51,20 @@ export default function ProductList() {
3751
</h3>
3852
<p className={style.preco}>Preço: R$ {produto.price.toString().replace(".", ",")}</p>
3953
</div>
40-
<button
41-
className={style.botaoEditar}
42-
onClick={() => navigate(`/novo/${produto.id}`)}
43-
>
44-
Editar
45-
</button>
54+
<div className={style.acoes}>
55+
<button
56+
className={style.botaoEditar}
57+
onClick={() => navigate(`/novo/${produto.id}`)}
58+
>
59+
Editar
60+
</button>
61+
<button
62+
className={style.botaoExcluir}
63+
onClick={() => handleExcluir(produto.id)}
64+
>
65+
Excluir
66+
</button>
67+
</div>
4668
</div>
4769
))
4870
}

2-desenvolvimento-front-end/DR2-fundamentos-de-react/DR2-AT-ecommerce-dummy-crud/src/pages/product-list/style.module.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
color: #2c5f2d;
6767
}
6868

69+
.acoes {
70+
display: flex;
71+
gap: 8px;
72+
flex-shrink: 0;
73+
}
74+
6975
.botaoEditar {
7076
background-color: #2c5f2d;
7177
color: white;
@@ -75,13 +81,27 @@
7581
font-size: 1rem;
7682
cursor: pointer;
7783
transition: background-color 0.2s;
78-
flex-shrink: 0;
7984
}
8085

8186
.botaoEditar:hover {
8287
background-color: #1f4520;
8388
}
8489

90+
.botaoExcluir {
91+
background-color: #d32f2f;
92+
color: white;
93+
border: none;
94+
border-radius: 4px;
95+
padding: 10px 20px;
96+
font-size: 1rem;
97+
cursor: pointer;
98+
transition: background-color 0.2s;
99+
}
100+
101+
.botaoExcluir:hover {
102+
background-color: #b71c1c;
103+
}
104+
85105
.carregando {
86106
text-align: center;
87107
padding: 20px;

0 commit comments

Comments
 (0)