2026-01-22 10:11:08 -06:00
|
|
|
"use client";
|
|
|
|
|
|
2026-01-29 11:21:12 -06:00
|
|
|
import { useEffect, useState } from "react";
|
2026-02-23 09:47:40 -06:00
|
|
|
import { getTableByCount } from "../lib/getTableByCount";
|
|
|
|
|
import { envConfig } from "../lib/config";
|
|
|
|
|
import { getMesaByCount } from "../lib/getMesaByCount";
|
2026-01-22 10:11:08 -06:00
|
|
|
import SearchUser from "./Global/SearchUser/searchUser";
|
2026-01-23 20:09:10 -06:00
|
|
|
import Information from "./Global/Information/information";
|
2026-01-26 13:04:50 -06:00
|
|
|
import SearchMesa from "./SearchMesa";
|
2026-01-29 11:21:12 -06:00
|
|
|
import axios from "axios";
|
2026-02-11 16:28:58 -06:00
|
|
|
import Swal from "sweetalert2";
|
2026-01-22 10:11:08 -06:00
|
|
|
|
2026-01-23 20:09:10 -06:00
|
|
|
interface props {
|
|
|
|
|
numAcount: string | null;
|
2026-01-29 11:21:12 -06:00
|
|
|
table: number | null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function CheckBoxMesa({ numAcount, table }: props) {
|
|
|
|
|
const [modo, setModo] = useState<"Mesa" | "Cuenta" | null>("Cuenta");
|
|
|
|
|
const [bitacora, setBitacora] = useState<any>(null);
|
|
|
|
|
const [tiempoRestante, setTiempoRestante] = useState<string>("");
|
|
|
|
|
const [minutos, setMinutos] = useState<number>();
|
2026-02-23 10:01:45 -06:00
|
|
|
const [error, setError] = useState()
|
|
|
|
|
const [loading, setLoading] = useState<boolean>(false)
|
2026-01-29 11:21:12 -06:00
|
|
|
|
|
|
|
|
const fetchByCuenta = async (idCuenta: number) => {
|
2026-02-06 10:39:20 -06:00
|
|
|
const result = await getMesaByCount(idCuenta);
|
2026-01-29 11:21:12 -06:00
|
|
|
|
|
|
|
|
if (result?.error) {
|
2026-02-19 10:48:45 -06:00
|
|
|
setError(result.error);
|
2026-01-29 11:21:12 -06:00
|
|
|
setBitacora(null);
|
|
|
|
|
} else {
|
|
|
|
|
setBitacora(result);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const fetchByEquipo = async (idEquipo: number) => {
|
2026-02-06 10:39:20 -06:00
|
|
|
const result = await getTableByCount(idEquipo);
|
2026-01-29 11:21:12 -06:00
|
|
|
|
|
|
|
|
if (result?.error) {
|
2026-02-19 10:48:45 -06:00
|
|
|
setError(result.error);
|
2026-01-29 11:21:12 -06:00
|
|
|
setBitacora(null);
|
|
|
|
|
} else {
|
|
|
|
|
setBitacora(result);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!numAcount) return;
|
|
|
|
|
const idCuenta = parseInt(numAcount);
|
|
|
|
|
if (isNaN(idCuenta)) return;
|
|
|
|
|
|
|
|
|
|
fetchByCuenta(idCuenta);
|
|
|
|
|
}, [numAcount]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!table) return;
|
|
|
|
|
const idEquipo = table;
|
|
|
|
|
if (isNaN(idEquipo)) return;
|
|
|
|
|
|
|
|
|
|
fetchByEquipo(idEquipo);
|
|
|
|
|
}, [table]);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!bitacora) return;
|
|
|
|
|
|
|
|
|
|
const entrada = new Date(bitacora.tiempo_entrada).getTime();
|
|
|
|
|
const asignadoMs = bitacora.tiempo_asignado * 60 * 1000;
|
|
|
|
|
|
|
|
|
|
const interval = setInterval(() => {
|
|
|
|
|
const ahora = Date.now();
|
|
|
|
|
const restante = entrada + asignadoMs - ahora;
|
|
|
|
|
|
|
|
|
|
if (restante <= 0) {
|
|
|
|
|
setTiempoRestante("agotado");
|
|
|
|
|
clearInterval(interval);
|
|
|
|
|
} else {
|
|
|
|
|
const minutos = Math.floor(restante / 60000);
|
|
|
|
|
setMinutos(minutos + 1);
|
|
|
|
|
const segundos = Math.floor((restante % 60000) / 1000);
|
|
|
|
|
setTiempoRestante(`${minutos} minutos con ${segundos} segundos`);
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
|
|
|
|
|
return () => clearInterval(interval);
|
|
|
|
|
}, [bitacora]);
|
|
|
|
|
|
|
|
|
|
const handleButton = async (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
|
e.preventDefault();
|
2026-02-23 10:01:45 -06:00
|
|
|
setLoading(false)
|
2026-01-29 11:21:12 -06:00
|
|
|
|
|
|
|
|
await axios.patch(
|
|
|
|
|
`${envConfig.apiUrl}/bitacora-mesa/cancelar/${bitacora.id_bitacora_mesa}`,
|
|
|
|
|
{ tiempo_asignado: minutos },
|
|
|
|
|
);
|
|
|
|
|
|
2026-02-11 16:28:58 -06:00
|
|
|
Swal.fire({
|
2026-02-20 14:33:08 -05:00
|
|
|
title: "Tiempo cancelado correctamente!",
|
2026-02-11 16:28:58 -06:00
|
|
|
icon: "success",
|
|
|
|
|
draggable: true,
|
|
|
|
|
});
|
2026-01-29 11:21:12 -06:00
|
|
|
|
|
|
|
|
if (modo === "Cuenta" && numAcount) {
|
|
|
|
|
fetchByCuenta(parseInt(numAcount));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (modo === "Mesa" && table) {
|
|
|
|
|
fetchByEquipo(table);
|
|
|
|
|
}
|
2026-02-23 10:01:45 -06:00
|
|
|
setLoading(true)
|
2026-01-29 11:21:12 -06:00
|
|
|
};
|
2026-01-22 10:11:08 -06:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="radio-grid">
|
|
|
|
|
<label className="radio-card">
|
|
|
|
|
<input
|
|
|
|
|
type="radio"
|
|
|
|
|
name="modo"
|
2026-01-22 12:25:07 -06:00
|
|
|
checked={modo === "Mesa"}
|
|
|
|
|
onChange={() => setModo("Mesa")}
|
2026-01-22 10:11:08 -06:00
|
|
|
/>
|
|
|
|
|
<span className="radio-ui"></span>
|
2026-01-22 12:25:07 -06:00
|
|
|
<span className="radio-text">Mesa</span>
|
2026-01-22 10:11:08 -06:00
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label className="radio-card">
|
|
|
|
|
<input
|
|
|
|
|
type="radio"
|
|
|
|
|
name="modo"
|
|
|
|
|
checked={modo === "Cuenta"}
|
|
|
|
|
onChange={() => setModo("Cuenta")}
|
|
|
|
|
/>
|
|
|
|
|
<span className="radio-ui"></span>
|
|
|
|
|
<span className="radio-text">Cuenta</span>
|
|
|
|
|
</label>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{modo === "Cuenta" && <SearchUser value={numAcount ?? null} />}
|
2026-01-26 13:04:50 -06:00
|
|
|
{modo === "Mesa" && <SearchMesa />}
|
2026-01-23 20:09:10 -06:00
|
|
|
|
2026-02-23 10:01:45 -06:00
|
|
|
<h2 style={{ marginTop: "10px" }}>{error}</h2>
|
2026-02-19 10:48:45 -06:00
|
|
|
|
2026-01-29 11:21:12 -06:00
|
|
|
{bitacora && (
|
|
|
|
|
<>
|
|
|
|
|
<Information
|
|
|
|
|
NoCuenta={bitacora.alumno_inscrito.alumno.id_cuenta}
|
|
|
|
|
Nombre={bitacora.alumno_inscrito.alumno.nombre}
|
|
|
|
|
Tiempo={tiempoRestante}
|
|
|
|
|
Mesa={bitacora.mesa.id_mesa}
|
|
|
|
|
/>
|
|
|
|
|
<button
|
|
|
|
|
className="button buttonSearch"
|
|
|
|
|
style={{ marginTop: "1rem" }}
|
|
|
|
|
onClick={handleButton}
|
2026-02-23 12:23:46 -06:00
|
|
|
disabled={loading || minutos ? false : true}
|
2026-01-29 11:21:12 -06:00
|
|
|
>
|
|
|
|
|
Cancelar tiempo
|
|
|
|
|
</button>
|
|
|
|
|
</>
|
2026-01-23 20:09:10 -06:00
|
|
|
)}
|
2026-01-22 10:11:08 -06:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-23 12:47:08 -06:00
|
|
|
//IO
|