Skip to content

Commit d6655de

Browse files
authored
Create E
1 parent 4638a92 commit d6655de

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

E

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// src/pages/Checkout.js
2+
import React from "react";
3+
import { useCart } from "../store/cart";
4+
5+
export default function Checkout() {
6+
const { cart, clearCart } = useCart();
7+
8+
const total = cart.reduce((acc, item) => acc + item.price, 0).toFixed(2);
9+
10+
const handleCheckout = () => {
11+
alert("Pedido finalizado com sucesso!");
12+
clearCart();
13+
};
14+
15+
return (
16+
<div className="p-6">
17+
<h1 className="text-2xl font-bold mb-4">Checkout</h1>
18+
{cart.length === 0 ? (
19+
<p>Seu carrinho está vazio.</p>
20+
) : (
21+
<div>
22+
<ul className="mb-4 space-y-2">
23+
{cart.map((item, i) => (
24+
<li key={i} className="flex justify-between">
25+
<span>{item.name}</span>
26+
<span>R$ {item.price}</span>
27+
</li>
28+
))}
29+
</ul>
30+
<p className="font-semibold mb-2">Total: R$ {total}</p>
31+
<button onClick={handleCheckout} className="bg-blue-600 text-white px-4 py-2 rounded">
32+
Finalizar Pedido
33+
</button>
34+
</div>
35+
)}
36+
</div>
37+
);
38+
}

0 commit comments

Comments
 (0)