Add concert images and implement seat pricing in Informacion component
This commit is contained in:
parent
1aa9f28cc6
commit
0c1a2e3ae8
ventaboletos
public/images
src
Binary file not shown.
After ![]() (image error) Size: 9.4 KiB |
Binary file not shown.
After ![]() (image error) Size: 70 KiB |
Binary file not shown.
After ![]() (image error) Size: 11 KiB |
|
@ -15,6 +15,7 @@ import {
|
||||||
} from "@/components/ui/select";
|
} from "@/components/ui/select";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
import { Label } from "@/components/ui/label"; // Import Label component
|
||||||
|
|
||||||
function Informacion() {
|
function Informacion() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
|
@ -26,6 +27,7 @@ function Informacion() {
|
||||||
const [selectedCategoria, setSelectedCategoria] = useState("");
|
const [selectedCategoria, setSelectedCategoria] = useState("");
|
||||||
const [asientoSeleccionado, setAsientoSeleccionado] = useState("");
|
const [asientoSeleccionado, setAsientoSeleccionado] = useState("");
|
||||||
const [searchTerm, setSearchTerm] = useState("");
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
|
const [precioAsiento, setPrecioAsiento] = useState(null); // Add state for seat price
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConciertos();
|
fetchConciertos();
|
||||||
|
@ -52,7 +54,7 @@ function Informacion() {
|
||||||
const fetchAsientos = async () => {
|
const fetchAsientos = async () => {
|
||||||
let { data, error } = await supabaseClient
|
let { data, error } = await supabaseClient
|
||||||
.from("asientos")
|
.from("asientos")
|
||||||
.select("numero_asiento, categoria");
|
.select("numero_asiento, categoria, precio"); // Include price in the select
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -72,6 +74,15 @@ function Informacion() {
|
||||||
const handleCategoriaChange = (categoria) => {
|
const handleCategoriaChange = (categoria) => {
|
||||||
setSelectedCategoria(categoria);
|
setSelectedCategoria(categoria);
|
||||||
setAsientoSeleccionado("");
|
setAsientoSeleccionado("");
|
||||||
|
setPrecioAsiento(null); // Reset price when category changes
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAsientoChange = (asiento) => {
|
||||||
|
setAsientoSeleccionado(asiento);
|
||||||
|
const selectedAsiento = numeroAsiento.find(
|
||||||
|
(item) => item.numero_asiento === asiento
|
||||||
|
);
|
||||||
|
setPrecioAsiento(selectedAsiento?.precio || null); // Set the price of the selected seat
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAgregarAlCarrito = () => {
|
const handleAgregarAlCarrito = () => {
|
||||||
|
@ -79,13 +90,13 @@ function Informacion() {
|
||||||
alert("Selecciona un tipo de asiento antes de continuar.");
|
alert("Selecciona un tipo de asiento antes de continuar.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const carritoActual = JSON.parse(localStorage.getItem("carrito")) || [];
|
const carritoActual = JSON.parse(localStorage.getItem("carrito")) || [];
|
||||||
const nuevoCarrito = [
|
const nuevoCarrito = [
|
||||||
...carritoActual,
|
...carritoActual,
|
||||||
{ ...selectedConcierto, asiento: asientoSeleccionado },
|
{ ...selectedConcierto, asiento: asientoSeleccionado, precio: precioAsiento },
|
||||||
];
|
];
|
||||||
|
|
||||||
localStorage.setItem("carrito", JSON.stringify(nuevoCarrito));
|
localStorage.setItem("carrito", JSON.stringify(nuevoCarrito));
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
@ -112,8 +123,12 @@ function Informacion() {
|
||||||
<div
|
<div
|
||||||
key={concierto.id}
|
key={concierto.id}
|
||||||
className="flex items-center gap-4 p-4 border rounded-lg"
|
className="flex items-center gap-4 p-4 border rounded-lg"
|
||||||
>
|
>
|
||||||
<div className="w-16 h-16 bg-gray-300" />
|
<img
|
||||||
|
src={`/images/${concierto.imagen || "default.jpeg"}`}
|
||||||
|
alt={concierto.nombre}
|
||||||
|
className="w-24 h-24 rounded-lg object-cover"
|
||||||
|
/>
|
||||||
<div>
|
<div>
|
||||||
<p className="text-lg font-semibold">{concierto.nombre}</p>
|
<p className="text-lg font-semibold">{concierto.nombre}</p>
|
||||||
<p className="text-sm text-gray-600">{concierto.fecha}</p>
|
<p className="text-sm text-gray-600">{concierto.fecha}</p>
|
||||||
|
@ -146,7 +161,7 @@ function Informacion() {
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Select onValueChange={setAsientoSeleccionado}>
|
<Select onValueChange={handleAsientoChange}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecciona un asiento" />
|
<SelectValue placeholder="Selecciona un asiento" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
@ -162,6 +177,11 @@ function Informacion() {
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<Label>
|
||||||
|
{precioAsiento !== null ? `Precio: $${precioAsiento}` : "Selecciona un asiento para ver el precio"}
|
||||||
|
</Label>
|
||||||
|
</div>
|
||||||
<div className="flex justify-end gap-2 mt-4">
|
<div className="flex justify-end gap-2 mt-4">
|
||||||
<Button variant="outline" onClick={() => setOpen(false)}>
|
<Button variant="outline" onClick={() => setOpen(false)}>
|
||||||
Cancelar
|
Cancelar
|
||||||
|
@ -174,4 +194,4 @@ function Informacion() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Informacion;
|
export default Informacion;
|
|
@ -3,12 +3,6 @@ import { useRouter } from "next/router";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||||
|
|
||||||
const PRECIOS_BOLETO = {
|
|
||||||
VIP: 100,
|
|
||||||
Intermedio: 75,
|
|
||||||
General: 25,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function Carrito() {
|
export default function Carrito() {
|
||||||
const [carrito, setCarrito] = useState([]);
|
const [carrito, setCarrito] = useState([]);
|
||||||
const [showDialog, setShowDialog] = useState(false);
|
const [showDialog, setShowDialog] = useState(false);
|
||||||
|
@ -17,12 +11,7 @@ export default function Carrito() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const carritoGuardado = JSON.parse(localStorage.getItem("carrito")) || [];
|
const carritoGuardado = JSON.parse(localStorage.getItem("carrito")) || [];
|
||||||
// Asigna el precio basado en el tipo de boleto si no tiene un precio definido
|
setCarrito(carritoGuardado);
|
||||||
const carritoConPrecios = carritoGuardado.map(item => ({
|
|
||||||
...item,
|
|
||||||
precio: PRECIOS_BOLETO[item.tipoBoleto] || 0,
|
|
||||||
}));
|
|
||||||
setCarrito(carritoConPrecios);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const eliminarConcierto = () => {
|
const eliminarConcierto = () => {
|
||||||
|
@ -38,6 +27,30 @@ export default function Carrito() {
|
||||||
return carrito.reduce((total, item) => total + (item.precio || 0), 0);
|
return carrito.reduce((total, item) => total + (item.precio || 0), 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pagar = async () => {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/comprar-boletos", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ boletos: carrito }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Error al procesar el pago");
|
||||||
|
}
|
||||||
|
|
||||||
|
alert("Compra realizada con éxito");
|
||||||
|
localStorage.removeItem("carrito");
|
||||||
|
setCarrito([]);
|
||||||
|
router.push("/");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error en la compra:", error);
|
||||||
|
alert("Hubo un problema al realizar la compra");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-4 max-w-3xl mx-auto bg-gray-900 text-white rounded-lg shadow-lg">
|
<div className="p-4 max-w-3xl mx-auto bg-gray-900 text-white rounded-lg shadow-lg">
|
||||||
<h2 className="text-2xl font-bold mb-4">Carrito de Compras</h2>
|
<h2 className="text-2xl font-bold mb-4">Carrito de Compras</h2>
|
||||||
|
@ -73,7 +86,7 @@ export default function Carrito() {
|
||||||
>
|
>
|
||||||
Cancelar
|
Cancelar
|
||||||
</Button>
|
</Button>
|
||||||
<Button className="bg-green-500 hover:bg-green-600">Pagar</Button>
|
<Button className="bg-green-500 hover:bg-green-600" onClick={pagar}>Pagar</Button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
@ -95,4 +108,4 @@ export default function Carrito() {
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
Loading…
Reference in New Issue