Compare commits
6 Commits
ada8da5974
...
0c1a2e3ae8
Author | SHA1 | Date |
---|---|---|
|
0c1a2e3ae8 | |
|
1aa9f28cc6 | |
|
bc2b125ac2 | |
|
53b6041973 | |
|
de1f7b2370 | |
|
c7dc7eb330 |
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 |
|
@ -14,21 +14,34 @@ import {
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} 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 { Label } from "@/components/ui/label"; // Import Label component
|
||||||
|
|
||||||
function Informacion() {
|
function Informacion() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [conciertos, setConciertos] = useState([]);
|
const [conciertos, setConciertos] = useState([]);
|
||||||
|
const [filteredConciertos, setFilteredConciertos] = useState([]);
|
||||||
const [selectedConcierto, setSelectedConcierto] = useState(null);
|
const [selectedConcierto, setSelectedConcierto] = useState(null);
|
||||||
const [tipoAsiento, setTipoAsiento] = useState([]);
|
const [tipoAsiento, setTipoAsiento] = useState([]);
|
||||||
const [numeroAsiento, setNumeroAsiento] = useState([]);
|
const [numeroAsiento, setNumeroAsiento] = useState([]);
|
||||||
const [selectedCategoria, setSelectedCategoria] = useState("");
|
const [selectedCategoria, setSelectedCategoria] = useState("");
|
||||||
const [asientoSeleccionado, setAsientoSeleccionado] = useState("");
|
const [asientoSeleccionado, setAsientoSeleccionado] = useState("");
|
||||||
|
const [searchTerm, setSearchTerm] = useState("");
|
||||||
|
const [precioAsiento, setPrecioAsiento] = useState(null); // Add state for seat price
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConciertos();
|
fetchConciertos();
|
||||||
fetchAsientos();
|
fetchAsientos();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setFilteredConciertos(
|
||||||
|
conciertos.filter((concierto) =>
|
||||||
|
concierto.nombre.toLowerCase().includes(searchTerm.toLowerCase())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, [searchTerm, conciertos]);
|
||||||
|
|
||||||
const fetchConciertos = async () => {
|
const fetchConciertos = async () => {
|
||||||
let { data, error } = await supabaseClient.from("conciertos").select("*");
|
let { data, error } = await supabaseClient.from("conciertos").select("*");
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -39,11 +52,15 @@ function Informacion() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchAsientos = async () => {
|
const fetchAsientos = async () => {
|
||||||
let { data, error } = await supabaseClient.from("asientos").select("numero_asiento, categoria");
|
let { data, error } = await supabaseClient
|
||||||
|
.from("asientos")
|
||||||
|
.select("numero_asiento, categoria, precio"); // Include price in the select
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} else {
|
} else {
|
||||||
const uniqueCategories = [...new Set(data.map((asiento) => asiento.categoria))];
|
const uniqueCategories = [
|
||||||
|
...new Set(data.map((asiento) => asiento.categoria)),
|
||||||
|
];
|
||||||
setTipoAsiento(uniqueCategories);
|
setTipoAsiento(uniqueCategories);
|
||||||
setNumeroAsiento(data);
|
setNumeroAsiento(data);
|
||||||
}
|
}
|
||||||
|
@ -57,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 = () => {
|
||||||
|
@ -64,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);
|
||||||
};
|
};
|
||||||
|
@ -82,9 +108,27 @@ function Informacion() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{conciertos.map((concierto) => (
|
<div className="w-full flex items-end">
|
||||||
<div key={concierto.id} className="flex items-center gap-4 p-4 border rounded-lg">
|
<div className="flex">
|
||||||
<div className="w-16 h-16 bg-gray-300" />
|
<Input
|
||||||
|
placeholder="Búsqueda por nombre"
|
||||||
|
className="w-60"
|
||||||
|
value={searchTerm}
|
||||||
|
onChange={(e) => setSearchTerm(e.target.value)}
|
||||||
|
/>
|
||||||
|
<img src="/search.jpg" alt="search" className="h-7 w-7" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{filteredConciertos.map((concierto) => (
|
||||||
|
<div
|
||||||
|
key={concierto.id}
|
||||||
|
className="flex items-center gap-4 p-4 border rounded-lg"
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
@ -117,19 +161,27 @@ 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>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{filteredAsientos.map((asiento) => (
|
{filteredAsientos.map((asiento) => (
|
||||||
<SelectItem key={asiento.numero_asiento} value={asiento.numero_asiento}>
|
<SelectItem
|
||||||
|
key={asiento.numero_asiento}
|
||||||
|
value={asiento.numero_asiento}
|
||||||
|
>
|
||||||
{asiento.numero_asiento}
|
{asiento.numero_asiento}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
))}
|
))}
|
||||||
</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
|
||||||
|
|
|
@ -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>
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -19,13 +19,13 @@ export default function ConcertList() {
|
||||||
<div className="flex flex-col items-center w-[80%]">
|
<div className="flex flex-col items-center w-[80%]">
|
||||||
<Tabs defaultValue="account" className="w-full">
|
<Tabs defaultValue="account" className="w-full">
|
||||||
<div className="w-full flex">
|
<div className="w-full flex">
|
||||||
<TabsList className="grid w-full grid-cols-2">
|
<TabsList className="grid w-full grid-cols-2">
|
||||||
<TabsTrigger value="info">Información</TabsTrigger>
|
<TabsTrigger value="info">Información</TabsTrigger>
|
||||||
<TabsTrigger value="reportes">Reportes</TabsTrigger>
|
<TabsTrigger value="reportes">Reportes</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
<Link href="/carrito">
|
<Link href="/carrito">
|
||||||
<img src="/carrito.svg" alt="carrito" className="h-10 w-10"/>
|
<img src="/carrito.svg" alt="carrito" className="h-10 w-10" />
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
<TabsContent value="info">
|
<TabsContent value="info">
|
||||||
<Card>
|
<Card>
|
||||||
|
@ -34,12 +34,6 @@ export default function ConcertList() {
|
||||||
<CardDescription></CardDescription>
|
<CardDescription></CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-2">
|
<CardContent className="space-y-2">
|
||||||
<div className="w-full flex items-end">
|
|
||||||
<div className="flex">
|
|
||||||
<Input placeholder="Búsqueda por nombre" className="w-60"></Input>
|
|
||||||
<img src="/search.jpg" alt="search" className="h-7 w-7"/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<Informacion />
|
<Informacion />
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardFooter></CardFooter>
|
<CardFooter></CardFooter>
|
||||||
|
|
Loading…
Reference in New Issue