This commit is contained in:
2026-02-09 12:25:53 -06:00
5 changed files with 46 additions and 33 deletions
+11 -6
View File
@@ -5,6 +5,7 @@ import { envConfig } from "@/app/lib/config";
import toast from "react-hot-toast";
import { getEquipoByCount } from "@/app/lib/getEquipoByCount";
import { getMesaByCount } from "@/app/lib/getMesaByCount";
import "./asignacion.css";
@@ -20,16 +21,20 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
const [equipoSeleccionado, setEquipoSeleccionado] = useState<any>(null);
const [open, setOpen] = useState(false);
const [tiempo, setTiempo] = useState<number>(15);
const [bitacora, setBitacora] = useState<[]|null>(null);
const [bitacora, setBitacora] = useState<[] | null>([]);
const fetchByCuenta = async (idCuenta: number) => {
const result = await getEquipoByCount(idCuenta);
const [result, resultMesa] = await Promise.all([
getEquipoByCount(idCuenta),
getMesaByCount(idCuenta),
]);
if (result?.error) {
if (result?.error && resultMesa?.error) {
setBitacora(null);
} else {
setBitacora(result);
toast.error("Ya cuentas con un equipo asignado");
setBitacora([]);
if (!result?.error) toast.error("Ya cuentas con un equipo asignado");
if (!resultMesa?.error) toast.error("Ya cuentas con una mesa asignada");
}
};
@@ -143,7 +148,7 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) {
<option value={90}>90 minutos</option>
</select>
<label style={{ marginTop: "1rem" }}>Seleccione un equipo</label>
<label>Seleccione un equipo</label>
<div className="groupInput">
<div
+12 -7
View File
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
import { envConfig } from "@/app/lib/config";
import toast from "react-hot-toast";
import { getEquipoByCount } from "../lib/getEquipoByCount";
import { getMesaByCount } from "../lib/getMesaByCount";
type Props = {
inscripcion: any[];
@@ -16,20 +17,24 @@ export default function AsignacionMesas({ idCuenta, inscripcion }: Props) {
const [loadingMesas, setLoadingMesas] = useState(false);
const [mesaSeleccionada, setMesaSeleccionada] = useState<any>(null);
const [tiempo, setTiempo] = useState<number>(15);
const [bitacora, setBitacora] = useState<[] | null>(null);
const [bitacora, setBitacora] = useState<[] | null>([]);
const fetchByCuenta = async (idCuenta: number) => {
const result = await getEquipoByCount(idCuenta);
const [result, resultMesa] = await Promise.all([
getEquipoByCount(idCuenta),
getMesaByCount(idCuenta),
]);
if (result?.error) {
if (result?.error && resultMesa?.error) {
setBitacora(null);
} else {
setBitacora(result);
toast.error("Ya cuentas con un equipo asignado");
setBitacora([]);
if (!result?.error) toast.error("Ya cuentas con un equipo asignado");
if (!resultMesa?.error) toast.error("Ya cuentas con una mesa asignada");
}
};
useEffect(() => {
useEffect(() => {
if (!idCuenta) return;
const Cuenta = idCuenta;
if (isNaN(Cuenta)) return;
@@ -163,7 +168,7 @@ export default function AsignacionMesas({ idCuenta, inscripcion }: Props) {
>
Asignar Mesa
</button>
</div>
</div>
);
+3 -19
View File
@@ -8,29 +8,13 @@ import { getTableByCount } from "../lib/getTableByCount";
import toast from "react-hot-toast";
import axios from "axios";
import { envConfig } from "../lib/config";
import { getMesaByCount } from "../lib/getMesaByCount";
interface props {
numAcount: string | null;
table: number | null;
}
async function getEquipoId(idEquipo: number) {
try {
const res = await axios.get(
`${envConfig.apiUrl}/bitacora-mesa/table/${idEquipo}`,
);
return res.data;
} catch (error: any) {
if (axios.isAxiosError(error)) {
return {
error: error.response?.data?.message || "Error al consultar equipo",
};
}
return { error: "Error desconocido" };
}
}
export default function CheckBoxMesa({ numAcount, table }: props) {
const [modo, setModo] = useState<"Mesa" | "Cuenta" | null>("Cuenta");
const [bitacora, setBitacora] = useState<any>(null);
@@ -38,7 +22,7 @@ export default function CheckBoxMesa({ numAcount, table }: props) {
const [minutos, setMinutos] = useState<number>();
const fetchByCuenta = async (idCuenta: number) => {
const result = await getTableByCount(idCuenta);
const result = await getMesaByCount(idCuenta);
if (result?.error) {
toast.error(result.error);
@@ -49,7 +33,7 @@ export default function CheckBoxMesa({ numAcount, table }: props) {
};
const fetchByEquipo = async (idEquipo: number) => {
const result = await getEquipoId(idEquipo);
const result = await getTableByCount(idEquipo);
if (result?.error) {
toast.error(result.error);
+19
View File
@@ -0,0 +1,19 @@
import axios from "axios";
import { envConfig } from "./config";
export async function getMesaByCount(idCuenta: number) {
try {
const res = await axios.get(
`${envConfig.apiUrl}/bitacora-mesa/cuenta/${idCuenta}`,
);
return res.data;
} catch (error: any) {
if (axios.isAxiosError(error)) {
return {
error: error.response?.data?.message || "Error al consultar equipo",
};
}
return { error: "Error desconocido" };
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ import { envConfig } from "./config";
export async function getTableByCount(idCuenta: number) {
try {
const res = await axios.get(
`${envConfig.apiUrl}/bitacora-mesa/cuenta/${idCuenta}`,
`${envConfig.apiUrl}/bitacora-mesa/table/${idCuenta}`,
);
return res.data;
} catch (error: any) {