diff --git a/app/(private)/AsignacionEquipo/page.tsx b/app/(private)/AsignacionEquipo/page.tsx index e7975ae..1196874 100644 --- a/app/(private)/AsignacionEquipo/page.tsx +++ b/app/(private)/AsignacionEquipo/page.tsx @@ -63,7 +63,6 @@ export default async function Page(props: { rawPlatica?.type === "Buffer" ? Boolean(rawPlatica.data[0]) : Boolean(rawPlatica); - console.log(result); } const inscResult = await getInscripcion(idCuenta); diff --git a/app/(private)/AsignacionMesas/page.tsx b/app/(private)/AsignacionMesas/page.tsx index 8f26636..69bfe52 100644 --- a/app/(private)/AsignacionMesas/page.tsx +++ b/app/(private)/AsignacionMesas/page.tsx @@ -52,7 +52,6 @@ export default async function Page(props: { rawPlatica?.type === "Buffer" ? Boolean(rawPlatica.data[0]) : Boolean(rawPlatica); - console.log(result); } diff --git a/app/(private)/BitacoraSanciones/page.tsx b/app/(private)/BitacoraSanciones/page.tsx index 56f4cc9..ac9d045 100644 --- a/app/(private)/BitacoraSanciones/page.tsx +++ b/app/(private)/BitacoraSanciones/page.tsx @@ -2,6 +2,7 @@ import BitacoraAlumno from "@/app/Components/BitacoraSanciones/BitacoraAlumno"; import BitacoraEquipo from "@/app/Components/BitacoraSanciones/BitacoraEquipo"; import BitacoraMesas from "@/app/Components/BitacoraSanciones/BitacoraMesas"; import Sanciones from "@/app/Components/BitacoraSanciones/Sanciones"; +import TableSanction from "@/app/Components/BitacoraSanciones/TableSanction"; import SearchUser from "@/app/Components/Global/SearchUser/searchUser"; import SearchUserWithDate from "@/app/Components/Global/SearchUser/SearchUserWithDate"; import ShowError from "@/app/Components/Global/ShowError"; @@ -75,6 +76,7 @@ export default async function Page(props: { label: "Sanciones", content: ( <> + ), @@ -86,7 +88,7 @@ export default async function Page(props: { <>
- {/* */} +
), diff --git a/app/Components/ActivosMantenimiento/Mesas.tsx b/app/Components/ActivosMantenimiento/Mesas.tsx index 0b32001..5ded1aa 100644 --- a/app/Components/ActivosMantenimiento/Mesas.tsx +++ b/app/Components/ActivosMantenimiento/Mesas.tsx @@ -18,11 +18,6 @@ function Mesas() { const estado = mantenimiento ? "en mantenimiento" : "disponible"; setMensaje(`Mesa ${mesa} confirmada como ${estado}`); - - console.log({ - mesa, - mantenimiento, - }); }; return ( diff --git a/app/Components/BitacoraSanciones/ApplySanction.tsx b/app/Components/BitacoraSanciones/ApplySanction.tsx new file mode 100644 index 0000000..cd80696 --- /dev/null +++ b/app/Components/BitacoraSanciones/ApplySanction.tsx @@ -0,0 +1,114 @@ +"use client"; + +import { useEffect, useState } from "react"; +import axios from "axios"; +import toast from "react-hot-toast"; +import { envConfig } from "@/app/lib/config"; +import { useRouter } from "next/navigation"; +import TableSanction from "./TableSanction"; + +interface Alumno { + id_cuenta: number; + nombre: string; + credito: number; +} + +interface Sancion { + id_sancion: number; + sancion: string; + duracion: number; +} + +interface AlumnoSancion { + id_alumno_sancion: number; + fecha_inicio: string; + sancion: Sancion; +} + +if (!envConfig.apiUrl) { + console.error("API URL is not defined in envConfig"); +} + +export default function ApplySanction({ idCuenta }: { idCuenta: number }) { + const [sanciones, setSanciones] = useState([]); + const [alumno, setAlumno] = useState(); + const [alumnoSanciones, setAlumnoSanciones] = useState([]); + const [selectedSancion, setSelectedSancion] = useState(""); + + const router = useRouter(); + + useEffect(() => { + if (!idCuenta) return; + + axios + .get(`${envConfig.apiUrl}/alumno-sancion/${idCuenta}`) + .then((res) => { + setAlumno(res.data.student); + setAlumnoSanciones( + res.data.alusancion?.length ? res.data.alusancion : [], + ); + }) + .catch((err) => { + const mensaje = + err.response?.data?.message || + "Error al obtener las sanciones del alumno"; + + }); + + axios + .get(`${envConfig.apiUrl}/sancion`) + .then((res) => setSanciones(res.data)) + .catch((err) => + toast.error("Error al obtener el catálogo de sanciones:", err), + ); + }, [idCuenta]); + + const calcularFechaFin = (fechaInicio: string, duracionSemanas: number) => { + const fecha = new Date(fechaInicio); + fecha.setDate(fecha.getDate() + duracionSemanas * 7); + return fecha.toLocaleDateString(); + }; + + const handleButton = (e: React.MouseEvent) => { + e.preventDefault(); + + if (!selectedSancion) { + toast.error("selecciona una sancion") + } + axios.post(`${envConfig.apiUrl}/alumno-sancion/`, { id_sancion: Number(selectedSancion), id_cuenta: idCuenta }) + router.refresh(); + } + + return ( + <> + + {!(alumnoSanciones?.length > 0) && + <> +
+
+ +
+
+ + + + } + + ); +} diff --git a/app/Components/BitacoraSanciones/Sanciones.tsx b/app/Components/BitacoraSanciones/Sanciones.tsx index e85d14d..d0200e0 100644 --- a/app/Components/BitacoraSanciones/Sanciones.tsx +++ b/app/Components/BitacoraSanciones/Sanciones.tsx @@ -1,6 +1,5 @@ import Information from "../Global/Information/information"; -import SearchUser from "../Global/SearchUser/searchUser"; -import TableSancion from "./TableSancion"; +import ApplySanction from "./ApplySanction"; interface Student { id_cuenta: string; @@ -13,11 +12,10 @@ export default function Sanciones({ student }: { student?: Student }) { return ( <> - {student && ( <> - + )} diff --git a/app/Components/BitacoraSanciones/TableSancion.tsx b/app/Components/BitacoraSanciones/TableSancion.tsx deleted file mode 100644 index 219fb74..0000000 --- a/app/Components/BitacoraSanciones/TableSancion.tsx +++ /dev/null @@ -1,129 +0,0 @@ -"use client"; - -import { useEffect, useState } from "react"; -import axios from "axios"; -import toast from "react-hot-toast"; -import { envConfig } from "@/app/lib/config"; - -interface Alumno { - id_cuenta: number; - nombre: string; - credito: number; -} - -interface Sancion { - id_sancion: number; - sancion: string; - duracion: number; -} - -interface AlumnoSancion { - id_alumno_sancion: number; - fecha_inicio: string; - sancion: Sancion; -} - -if (!envConfig.apiUrl) { - console.error("API URL is not defined in envConfig"); -} - -export default function TableSancion({ idCuenta }: { idCuenta: number }) { - const [sanciones, setSanciones] = useState([]); - const [alumno, setAlumno] = useState(null); - const [alumnoSanciones, setAlumnoSanciones] = useState([]); - const [selectedSancion, setSelectedSancion] = useState(""); - - useEffect(() => { - if (!idCuenta) return; - - axios - .get(`${envConfig.apiUrl}/alumno-sancion/${idCuenta}`) - .then((res) => { - setAlumno(res.data.student); - setAlumnoSanciones( - res.data.alusancion?.length ? res.data.alusancion : [], - ); - }) - .catch((err) => { - const mensaje = - err.response?.data?.message || - "Error al obtener las sanciones del alumno"; - - toast.error(mensaje); - }); - - // Obtener catálogo de sanciones - axios - .get(`${envConfig.apiUrl}/sancion`) - .then((res) => setSanciones(res.data)) - .catch((err) => - toast.error("Error al obtener el catálogo de sanciones:", err), - ); - }, [idCuenta]); - - const calcularFechaFin = (fechaInicio: string, duracionSemanas: number) => { - const fecha = new Date(fechaInicio); - fecha.setDate(fecha.getDate() + duracionSemanas * 7); - return fecha.toLocaleDateString(); - }; - - return ( - <> -
- - - - - - - - - - - - {alumnoSanciones.length > 0 ? ( - alumnoSanciones.map((item) => ( - - - - - - - - )) - ) : ( - - - - )} - -
CuentaMotivo de la sanciónDuración (Semanas)Fecha SanciónPodrá utilizar el servicio hasta
{alumno?.id_cuenta}{item.sancion.sancion}{item.sancion.duracion}{new Date(item.fecha_inicio).toLocaleDateString()} - {calcularFechaFin(item.fecha_inicio, item.sancion.duracion)} -
No hay sanciones registradas
-
- -
-
- -
-
- - - - ); -} diff --git a/app/Components/BitacoraSanciones/TableSanction.tsx b/app/Components/BitacoraSanciones/TableSanction.tsx new file mode 100644 index 0000000..d82b674 --- /dev/null +++ b/app/Components/BitacoraSanciones/TableSanction.tsx @@ -0,0 +1,67 @@ +interface Sancion { + id_sancion: number; + sancion: string; + duracion: number; +} + +interface AlumnoSancion { + id_alumno_sancion: number; + fecha_inicio: string; + sancion: Sancion; + alumno: string; +} + +interface Alumno { + id_cuenta: number; + nombre: string; + credito: number; +} + +interface Props { + alumnoSanciones: AlumnoSancion[], + alumno: Alumno +} + +export default function TableSanction({ alumnoSanciones, alumno }: Props) { + + const calcularFechaFin = (fechaInicio: string, duracionSemanas: number) => { + const fecha = new Date(fechaInicio); + fecha.setDate(fecha.getDate() + duracionSemanas * 7); + return fecha.toLocaleDateString(); + }; + + return ( +
+ + + + + + + + + + + + {alumnoSanciones.length > 0 ? ( + alumnoSanciones.map((item) => ( + + + + + + + + )) + ) : ( + + + + )} + +
CuentaMotivo de la sanciónDuración (Semanas)Fecha SanciónPodrá utilizar el servicio hasta
{alumno?.id_cuenta}{item.sancion.sancion}{item.sancion.duracion}{new Date(item.fecha_inicio).toLocaleDateString()} + {calcularFechaFin(item.fecha_inicio, item.sancion.duracion)} +
No hay sanciones registradas
+
+ ) +} \ No newline at end of file diff --git a/app/Components/EviarMensaje/EnviarMensaje.tsx b/app/Components/EviarMensaje/EnviarMensaje.tsx index f9d8f17..3d5206c 100644 --- a/app/Components/EviarMensaje/EnviarMensaje.tsx +++ b/app/Components/EviarMensaje/EnviarMensaje.tsx @@ -70,8 +70,6 @@ const EnviarMensaje = ({ titulo }: EnviarMensajeProps) => { mensaje: customMsg || mensaje, }; - console.log(payload); - }; return ( diff --git a/app/Components/EviarMensaje/EnviarMensajeSala.tsx b/app/Components/EviarMensaje/EnviarMensajeSala.tsx index 67cc87f..473c797 100644 --- a/app/Components/EviarMensaje/EnviarMensajeSala.tsx +++ b/app/Components/EviarMensaje/EnviarMensajeSala.tsx @@ -20,7 +20,6 @@ const EnviarMensajeSala = ({ titulo }: EnviarMensajeSalaProps) => { const [mensaje, setMensaje] = useState(""); const [customMsg, setCustomMsg] = useState(""); - // 🔹 Traer salas desde API useEffect(() => { const fetchSalas = async () => { try { @@ -42,9 +41,6 @@ const EnviarMensajeSala = ({ titulo }: EnviarMensajeSalaProps) => { mensaje: customMsg || mensaje, }; - console.log(payload); - - }; return ( diff --git a/app/Components/QuitarSancion/QuitarSancion.tsx b/app/Components/QuitarSancion/QuitarSancion.tsx index 6924716..748ccee 100644 --- a/app/Components/QuitarSancion/QuitarSancion.tsx +++ b/app/Components/QuitarSancion/QuitarSancion.tsx @@ -1,3 +1,11 @@ +"use client"; + +import { envConfig } from "@/app/lib/config"; +import { useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; +import TableSanction from "../BitacoraSanciones/TableSanction"; +import axios from "axios"; + interface Alumno { id_cuenta: number; nombre: string; @@ -16,58 +24,47 @@ interface AlumnoSancion { sancion: Sancion; } -interface DataProps { - student: Alumno; - alusancion: AlumnoSancion[]; -} +function QuitarSancion({ id_cuenta }: { id_cuenta: number }) { + const [alumno, setAlumno] = useState(); + const [alumnoSanciones, setAlumnoSanciones] = useState([]); + const router = useRouter(); -interface Props { - data: DataProps | null; -} + useEffect(() => { + if (!id_cuenta) return; -function QuitarSancion({ data }: Props) { - const calcularFechaFin = (fechaInicio: string, duracionSemanas: number) => { - const fecha = new Date(fechaInicio); - fecha.setDate(fecha.getDate() + duracionSemanas * 7); - return fecha.toLocaleDateString(); - }; + axios + .get(`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`) + .then((res) => { + setAlumno(res.data.student); + setAlumnoSanciones( + res.data.alusancion?.length ? res.data.alusancion : [], + ); + }) + .catch((err) => { + const mensaje = + err.response?.data?.message || + "Error al obtener las sanciones del alumno"; + + }); + }, [id_cuenta]); + + const handleButton = (e: React.MouseEvent) => { + e.preventDefault(); + + axios.delete(`${envConfig.apiUrl}/alumno-sancion/${id_cuenta}`) + router.refresh(); + } return (
-
- - - - - - - - - - - - - {data && data.alusancion.length !== 0 ? ( - data.alusancion.map((item) => ( - - - - - - - - - )) - ) : ( - - - - )} - -
IDNombreMotivo SanciónDuración (semanas)Fecha SanciónPodra utilizar el servicio hasta
{item.id_alumno_sancion}{data.student.nombre}{item.sancion.sancion}{item.sancion.duracion}{new Date(item.fecha_inicio).toLocaleDateString()} - {calcularFechaFin(item.fecha_inicio, item.sancion.duracion)} -
No hay sanciones registradas
-
+ +
); } diff --git a/app/Components/SearchMesa.tsx b/app/Components/SearchMesa.tsx index ecda544..bfb9df1 100644 --- a/app/Components/SearchMesa.tsx +++ b/app/Components/SearchMesa.tsx @@ -1,59 +1,11 @@ "use client"; -import axios from "axios"; + import { usePathname, useRouter, useSearchParams } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useState } from "react"; -interface Mesa { - id_mesa: number; - nombre?: string; -} - -interface Props { - id_cuenta: number; -} - -function Mesas({ id_cuenta }: Props) { - const [mesas, setMesas] = useState([]); - const [loading, setLoading] = useState(false); - - useEffect(() => { - if (!id_cuenta) return; - - setLoading(true); - - axios - .get(`/cuenta/${id_cuenta}`) - .then((res) => { - setMesas(res.data); - }) - .catch((err) => console.error(err)) - .finally(() => setLoading(false)); - }, [id_cuenta]); - - if (loading) return

Cargando mesas...

; - - return ( -
-

Mesas asignadas

- - {mesas.length === 0 ? ( -

No hay mesas

- ) : ( -
    - {mesas.map((mesa) => ( -
  • - Mesa {mesa.id_mesa} {mesa.nombre && `- ${mesa.nombre}`} -
  • - ))} -
- )} -
- ); -} export default function SearchMesa() { const [inputValue, setInputValue] = useState(""); - const [idCuenta, setIdCuenta] = useState(null); const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams();