diff --git a/app/(private)/AsignacionEquipo/PlaticaGate.tsx b/app/(private)/AsignacionEquipo/PlaticaGate.tsx index c606469..ac93b7a 100644 --- a/app/(private)/AsignacionEquipo/PlaticaGate.tsx +++ b/app/(private)/AsignacionEquipo/PlaticaGate.tsx @@ -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(null); const [open, setOpen] = useState(false); const [tiempo, setTiempo] = useState(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) { - +
(null); const [tiempo, setTiempo] = useState(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 - +
); diff --git a/app/Components/CheckBoxMesa.tsx b/app/Components/CheckBoxMesa.tsx index b285af6..512c82c 100644 --- a/app/Components/CheckBoxMesa.tsx +++ b/app/Components/CheckBoxMesa.tsx @@ -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(null); @@ -38,7 +22,7 @@ export default function CheckBoxMesa({ numAcount, table }: props) { const [minutos, setMinutos] = useState(); 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); diff --git a/app/lib/getMesaByCount.ts b/app/lib/getMesaByCount.ts new file mode 100644 index 0000000..a4785e5 --- /dev/null +++ b/app/lib/getMesaByCount.ts @@ -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" }; + } +} \ No newline at end of file diff --git a/app/lib/getTableByCount.ts b/app/lib/getTableByCount.ts index debf82a..cd185a9 100644 --- a/app/lib/getTableByCount.ts +++ b/app/lib/getTableByCount.ts @@ -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) {