diff --git a/app/(private)/AsignacionEquipo/PlaticaGate.tsx b/app/(private)/AsignacionEquipo/PlaticaGate.tsx index c606469..2fb3234 100644 --- a/app/(private)/AsignacionEquipo/PlaticaGate.tsx +++ b/app/(private)/AsignacionEquipo/PlaticaGate.tsx @@ -7,6 +7,7 @@ import toast from "react-hot-toast"; import { getEquipoByCount } from "@/app/lib/getEquipoByCount"; import "./asignacion.css"; +import { getMesaByCount } from "@/app/lib/getMesaByCount"; type Props = { inscripcion: any[]; @@ -20,7 +21,7 @@ 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>(null); const fetchByCuenta = async (idCuenta: number) => { const result = await getEquipoByCount(idCuenta); @@ -31,6 +32,15 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) { setBitacora(result); toast.error("Ya cuentas con un equipo asignado"); } + + const resultMesa = await getMesaByCount(idCuenta); + + if (resultMesa?.error) { + setBitacora(null) + } else { + setBitacora(result) + toast.error("Ya cuentas con una mesa asignada") + } }; useEffect(() => { @@ -143,7 +153,7 @@ export default function PlaticaGate({ inscripcion, numAcount }: Props) { - +
{ + useEffect(() => { if (!idCuenta) return; const Cuenta = idCuenta; if (isNaN(Cuenta)) return; @@ -163,7 +173,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) {