68 lines
2.4 KiB
TypeScript
68 lines
2.4 KiB
TypeScript
import { Alumno, AlumnoSancion } from "@/app/types/sanction";
|
|
|
|
interface Props {
|
|
alumnoSanciones?: AlumnoSancion[] | null,
|
|
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.toLocaleString("es-MX", {
|
|
timeZone: "America/Mexico_City",
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit"
|
|
});
|
|
};
|
|
|
|
const formatearFechaMexico = (fechaISO: string) => {
|
|
return new Date(fechaISO).toLocaleString("es-MX", {
|
|
timeZone: "America/Mexico_City",
|
|
year: "numeric",
|
|
month: "2-digit",
|
|
day: "2-digit",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
second: "2-digit"
|
|
});
|
|
};
|
|
return (
|
|
<div style={{ margin: "1rem 0", maxWidth: "730px" }}>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>Cuenta</th>
|
|
<th>Motivo de la sanción</th>
|
|
<th>Duración (Semanas)</th>
|
|
<th>Fecha Sanción</th>
|
|
<th>Podrá utilizar el servicio hasta</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{!(alumnoSanciones?.length === 0) ? (
|
|
alumnoSanciones?.map((item) => (
|
|
<tr key={item.id_alumno_sancion}>
|
|
<td>{alumno?.id_cuenta}</td>
|
|
<td>{item.sancion.sancion}</td>
|
|
<td>{item.sancion.duracion}</td>
|
|
<td>{formatearFechaMexico(item.fecha_inicio)}</td> <td>
|
|
{calcularFechaFin(item.fecha_inicio, item.sancion.duracion)}
|
|
</td>
|
|
</tr>
|
|
))
|
|
) : (
|
|
<tr>
|
|
<td colSpan={5}>No hay sanciones registradas</td>
|
|
</tr>
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
)
|
|
} |