Merge branch 'benito' of https://git.gumoio.com/benito.rodriguez/Venta.De.Boletos.De.Un.Concierto into rvg-frontend
This commit is contained in:
commit
53b6041973
ventaboletos/src
|
@ -22,17 +22,15 @@ function Informacion() {
|
||||||
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("");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchConciertos();
|
fetchConciertos();
|
||||||
fetchTipoAsiento();
|
fetchAsientos();
|
||||||
fetchNumeroAsiento();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const fetchConciertos = async () => {
|
const fetchConciertos = async () => {
|
||||||
let { data: conciertos, error } = await supabaseClient
|
let { data, error } = await supabaseClient.from("conciertos").select("*");
|
||||||
.from("conciertos")
|
|
||||||
.select("*");
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,8 +38,8 @@ function Informacion() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchNumeroAsiento = async () => {
|
const fetchAsientos = async () => {
|
||||||
let { data: asientos, error } = await supabaseClient
|
let { data, error } = await supabaseClient
|
||||||
.from("asientos")
|
.from("asientos")
|
||||||
.select("numero_asiento, categoria");
|
.select("numero_asiento, categoria");
|
||||||
if (error) {
|
if (error) {
|
||||||
|
@ -84,19 +82,13 @@ function Informacion() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obtener carrito actual desde localStorage
|
|
||||||
const carritoActual = JSON.parse(localStorage.getItem("carrito")) || [];
|
const carritoActual = JSON.parse(localStorage.getItem("carrito")) || [];
|
||||||
|
|
||||||
// Agregar el concierto con el tipo de asiento seleccionado
|
|
||||||
const nuevoCarrito = [
|
const nuevoCarrito = [
|
||||||
...carritoActual,
|
...carritoActual,
|
||||||
{ ...selectedConcierto, asiento: asientoSeleccionado },
|
{ ...selectedConcierto, asiento: asientoSeleccionado },
|
||||||
];
|
];
|
||||||
|
|
||||||
// Guardar en localStorage
|
|
||||||
localStorage.setItem("carrito", JSON.stringify(nuevoCarrito));
|
localStorage.setItem("carrito", JSON.stringify(nuevoCarrito));
|
||||||
|
|
||||||
// Cerrar el modal
|
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -132,7 +124,7 @@ function Informacion() {
|
||||||
<SelectValue placeholder="Selecciona un tipo de asiento" />
|
<SelectValue placeholder="Selecciona un tipo de asiento" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{tipoAsiento?.map((tipo) => (
|
{tipoAsiento.map((tipo) => (
|
||||||
<SelectItem key={tipo} value={tipo}>
|
<SelectItem key={tipo} value={tipo}>
|
||||||
{tipo}
|
{tipo}
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
|
@ -141,12 +133,12 @@ function Informacion() {
|
||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<Select onValueChange={(value) => console.log(value)}>
|
<Select onValueChange={setAsientoSeleccionado}>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder="Selecciona un asiento" />
|
<SelectValue placeholder="Selecciona un asiento" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{filteredAsientos?.map((asiento) => (
|
{filteredAsientos.map((asiento) => (
|
||||||
<SelectItem
|
<SelectItem
|
||||||
key={asiento.numero_asiento}
|
key={asiento.numero_asiento}
|
||||||
value={asiento.numero_asiento}
|
value={asiento.numero_asiento}
|
||||||
|
|
|
@ -3,6 +3,12 @@ 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);
|
||||||
|
@ -11,7 +17,12 @@ export default function Carrito() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const carritoGuardado = JSON.parse(localStorage.getItem("carrito")) || [];
|
const carritoGuardado = JSON.parse(localStorage.getItem("carrito")) || [];
|
||||||
setCarrito(carritoGuardado);
|
// Asigna el precio basado en el tipo de boleto si no tiene un precio definido
|
||||||
|
const carritoConPrecios = carritoGuardado.map(item => ({
|
||||||
|
...item,
|
||||||
|
precio: PRECIOS_BOLETO[item.tipoBoleto] || 0,
|
||||||
|
}));
|
||||||
|
setCarrito(carritoConPrecios);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const eliminarConcierto = () => {
|
const eliminarConcierto = () => {
|
||||||
|
@ -58,7 +69,7 @@ export default function Carrito() {
|
||||||
<div className="flex justify-between mt-4">
|
<div className="flex justify-between mt-4">
|
||||||
<Button
|
<Button
|
||||||
className="bg-gray-500 hover:bg-gray-600"
|
className="bg-gray-500 hover:bg-gray-600"
|
||||||
onClick={() => router.push("/")}
|
onClick={() => router.push("/")}
|
||||||
>
|
>
|
||||||
Cancelar
|
Cancelar
|
||||||
</Button>
|
</Button>
|
||||||
|
|
Loading…
Reference in New Issue