File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments