Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions E
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// src/pages/Checkout.js
import React from "react";
import { useCart } from "../store/cart";

export default function Checkout() {
const { cart, clearCart } = useCart();

const total = cart.reduce((acc, item) => acc + item.price, 0).toFixed(2);

const handleCheckout = () => {
alert("Pedido finalizado com sucesso!");
clearCart();
};

return (
<div className="p-6">
<h1 className="text-2xl font-bold mb-4">Checkout</h1>
{cart.length === 0 ? (
<p>Seu carrinho está vazio.</p>
) : (
<div>
<ul className="mb-4 space-y-2">
{cart.map((item, i) => (
<li key={i} className="flex justify-between">
<span>{item.name}</span>
<span>R$ {item.price}</span>
</li>
))}
</ul>
<p className="font-semibold mb-2">Total: R$ {total}</p>
<button onClick={handleCheckout} className="bg-blue-600 text-white px-4 py-2 rounded">
Finalizar Pedido
</button>
</div>
)}
</div>
);
}