now ist working bitacora alumno and bitacora equipo
This commit is contained in:
@@ -13,11 +13,14 @@ export default async function Page(props: {
|
||||
searchParams?: Promise<{
|
||||
key?: string;
|
||||
numAcount?: string;
|
||||
date?: string;
|
||||
}>;
|
||||
}) {
|
||||
const params = await props.searchParams;
|
||||
const key = params?.key && params.key;
|
||||
const numAcount = params?.numAcount ? params.numAcount : null;
|
||||
const date = params?.date ? params.date : null;
|
||||
|
||||
|
||||
let student: any = null;
|
||||
let errorMessage = "";
|
||||
@@ -46,7 +49,7 @@ export default async function Page(props: {
|
||||
label: "Bitácora equipo",
|
||||
content: (
|
||||
<>
|
||||
<BitacoraEquipo />
|
||||
<BitacoraEquipo date={date}/>
|
||||
</>
|
||||
),
|
||||
},
|
||||
@@ -56,7 +59,12 @@ export default async function Page(props: {
|
||||
content: (
|
||||
<>
|
||||
<SearchUserWithDate value={numAcount} />
|
||||
<BitacoraAlumno />
|
||||
<BitacoraAlumno
|
||||
key={`${numAcount}-${date}`}
|
||||
numAcount={numAcount}
|
||||
date={date}
|
||||
/>
|
||||
|
||||
</>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,35 +1,69 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import axios from "axios";
|
||||
import { envConfig } from "@/app/lib/config";
|
||||
|
||||
interface alumnos {
|
||||
interface AlumnoBitacora {
|
||||
tiempo_entrada: string;
|
||||
tiempo_asignado: string;
|
||||
Ubicacion_equipo: number;
|
||||
tiempo_asignado: number;
|
||||
equipo: {
|
||||
ubicacion: string;
|
||||
nombre_equipo: string;
|
||||
};
|
||||
}
|
||||
|
||||
function BitacoraAlumno() {
|
||||
const [alumnos, setAlumnos] = useState<alumnos[]>([]);
|
||||
interface BitacoraAlumnoProps {
|
||||
numAcount: string | null;
|
||||
date: string | null;
|
||||
}
|
||||
|
||||
function BitacoraAlumno({ numAcount, date }: BitacoraAlumnoProps) {
|
||||
const [alumnos, setAlumnos] = useState<AlumnoBitacora[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!numAcount) return;
|
||||
if (!date) return;
|
||||
|
||||
axios.post(`${envConfig.apiUrl}/bitacora/equipos-por-dia`, {
|
||||
numero_cuenta: numAcount,
|
||||
fecha: date,
|
||||
})
|
||||
.then(res => {
|
||||
setAlumnos(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}, [numAcount, date]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tiempo Entrada</th>
|
||||
<th>Tiempo Asignado</th>
|
||||
<th>Ubicacion del equipo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{alumnos.map((alumno, index) => (
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tiempo Entrada</th>
|
||||
<th>Tiempo Asignado</th>
|
||||
<th>Ubicación del equipo</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{alumnos.length > 0 ? (
|
||||
alumnos.map((alumno, index) => (
|
||||
<tr key={index}>
|
||||
<td>{alumno.tiempo_entrada}</td>
|
||||
<td>{new Date(alumno.tiempo_entrada).toLocaleString()}</td>
|
||||
<td>{alumno.tiempo_asignado}</td>
|
||||
<td>{alumno.Ubicacion_equipo}</td>
|
||||
<td>{alumno.equipo.ubicacion}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={3} style={{ textAlign: "center" }}>
|
||||
No tuvo equipos asignados
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ interface equipos {
|
||||
cuenta_asociada: number;
|
||||
}
|
||||
|
||||
function BitacoraEquipo() {
|
||||
function BitacoraEquipo({ date }: { date: string | null }) {
|
||||
const [equipo, setEquipo] = useState<equipos[]>([]);
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loadingEquipos, setLoadingEquipos] = useState(false);
|
||||
@@ -31,6 +31,23 @@ function BitacoraEquipo() {
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!equipoSeleccionado?.id_equipo) return;
|
||||
if (!date) return;
|
||||
|
||||
axios.post(`${envConfig.apiUrl}/bitacora/equipos-por-equipo`, {
|
||||
id_equipo: equipoSeleccionado.id_equipo,
|
||||
fecha: date,
|
||||
})
|
||||
.then(res => {
|
||||
setEquipo(res.data);
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
});
|
||||
}, [equipoSeleccionado, date]);
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<label>Seleccione un equipo</label>
|
||||
@@ -61,7 +78,7 @@ function BitacoraEquipo() {
|
||||
</div>
|
||||
|
||||
{open && (
|
||||
<div className="options" style={{ bottom: "auto"}}>
|
||||
<div className="options" style={{ bottom: "auto" }}>
|
||||
{equipos.length === 0 && (
|
||||
<div className="option disabled">
|
||||
No hay equipos disponibles
|
||||
@@ -96,15 +113,28 @@ function BitacoraEquipo() {
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{equipo.map((equipo, index) => (
|
||||
<tr key={index}>
|
||||
<td>{equipo.hora_entrada}</td>
|
||||
<td>{equipo.min_utilizados}</td>
|
||||
<td>{equipo.hora_salida}</td>
|
||||
<td>{equipo.cuenta_asociada}</td>
|
||||
{equipo.length > 0 ? (
|
||||
equipo.map((registro, index) => (
|
||||
<tr key={index}>
|
||||
<td>{new Date(registro.hora_entrada).toLocaleString()}</td>
|
||||
<td>{registro.min_utilizados}</td>
|
||||
<td>
|
||||
{registro.hora_salida
|
||||
? new Date(registro.hora_salida).toLocaleString()
|
||||
: "—"}
|
||||
</td>
|
||||
<td>{registro.cuenta_asociada}</td>
|
||||
</tr>
|
||||
))
|
||||
) : (
|
||||
<tr>
|
||||
<td colSpan={4} style={{ textAlign: "center" }}>
|
||||
Este equipo no tuvo asignaciones en esa fecha
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
)}
|
||||
</tbody>
|
||||
|
||||
</table>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -2,57 +2,76 @@
|
||||
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import SearchDate from "../../SearchDate/SearchDate";
|
||||
|
||||
interface urlProp {
|
||||
value: string | null;
|
||||
}
|
||||
|
||||
function SearchUserWithDate(props: urlProp) {
|
||||
const [numAcount, setnumAcount] = useState("");
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const todayISO = new Date().toLocaleDateString("en-CA");
|
||||
|
||||
const [numAcount, setNumAcount] = useState("");
|
||||
const [date, setDate] = useState(todayISO);
|
||||
|
||||
useEffect(() => {
|
||||
if (props.value) {
|
||||
setnumAcount(props.value);
|
||||
}
|
||||
}, [props.value]);
|
||||
const num = searchParams.get("numAcount");
|
||||
const dateParam = searchParams.get("date");
|
||||
|
||||
if (num) setNumAcount(num);
|
||||
if (dateParam) setDate(dateParam);
|
||||
}, [searchParams]);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
|
||||
if (numAcount) {
|
||||
params.set("numAcount", `${numAcount}`);
|
||||
router.push(`${pathname}?${params.toString()}`);
|
||||
params.set("numAcount", numAcount);
|
||||
}
|
||||
|
||||
if (date) {
|
||||
params.set("date", date);
|
||||
}
|
||||
|
||||
router.push(`${pathname}?${params.toString()}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<form className="containerForm" onSubmit={handleSubmit}>
|
||||
<label className="label">No.Cuenta</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
type="text"
|
||||
value={numAcount}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (/^\d*$/.test(value) && value.length <= 9) {
|
||||
setnumAcount(value);
|
||||
}
|
||||
}}
|
||||
placeholder="Coloca un número de cuenta..."
|
||||
inputMode="numeric"
|
||||
pattern="[0-9]*"
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
<SearchDate />
|
||||
</>
|
||||
<form className="containerForm" onSubmit={handleSubmit}>
|
||||
<label className="label">No.Cuenta</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
type="text"
|
||||
value={numAcount}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (/^\d*$/.test(value) && value.length <= 9) {
|
||||
setNumAcount(value);
|
||||
}
|
||||
}}
|
||||
placeholder="Coloca un número de cuenta..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<label className="label">Fecha</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
type="date"
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button className="button buttonSearch" type="submit">
|
||||
Buscar
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
export default SearchUserWithDate;
|
||||
//IO
|
||||
|
||||
@@ -1,27 +1,49 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
function SearchDate() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const todayISO = new Date().toLocaleDateString("en-CA");
|
||||
const [date, setDate] = useState(todayISO);
|
||||
|
||||
useEffect(() => {
|
||||
const dateParam = searchParams.get("date");
|
||||
if (dateParam) {
|
||||
setDate(dateParam);
|
||||
}
|
||||
}, [searchParams]);
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
|
||||
if (date) {
|
||||
params.set("date", date);
|
||||
}
|
||||
|
||||
router.push(`${pathname}?${params.toString()}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<form className="containerForm">
|
||||
<label className="label">Fecha</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
type="date"
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
placeholder="Selecciona una fecha..."
|
||||
/>
|
||||
<button className="button buttonSearch" type="submit">
|
||||
Buscar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
<form className="containerForm" onSubmit={handleSubmit}>
|
||||
<label className="label">Fecha</label>
|
||||
<div className="groupInput">
|
||||
<input
|
||||
type="date"
|
||||
value={date}
|
||||
onChange={(e) => setDate(e.target.value)}
|
||||
/>
|
||||
<button className="button buttonSearch" type="submit">
|
||||
Buscar
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user