Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88f2ac13d7 |
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { axiosInstance } from "@/api/config";
|
import { axiosInstance } from "@/api/config";
|
||||||
import { ServicioSocialConCasoEspecial, ServicioSocialResponse } from "@/types/responses";
|
import {
|
||||||
|
ServicioSocialConCasoEspecial,
|
||||||
|
ServicioSocialResponse,
|
||||||
|
} from "@/types/responses";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -26,8 +29,8 @@ export default function ServicioSocialTabla({
|
|||||||
onPageChange,
|
onPageChange,
|
||||||
idTipoUsuario,
|
idTipoUsuario,
|
||||||
columnasResponsable = false,
|
columnasResponsable = false,
|
||||||
columnaFechaInicio = false,
|
columnaFechaInicio = true,
|
||||||
columnaFechaFin = false,
|
columnaFechaFin = true,
|
||||||
columnaCuestionario = false,
|
columnaCuestionario = false,
|
||||||
columnaCartaTermino = false,
|
columnaCartaTermino = false,
|
||||||
columnaCuestionarioCompleto = false,
|
columnaCuestionarioCompleto = false,
|
||||||
@@ -40,9 +43,6 @@ export default function ServicioSocialTabla({
|
|||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
//const columnaFechaInicio = true;
|
|
||||||
//const columnaFechaFin = true;
|
|
||||||
|
|
||||||
// 🔹 Cargar datos del padre si existen
|
// 🔹 Cargar datos del padre si existen
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
@@ -68,31 +68,9 @@ export default function ServicioSocialTabla({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEspecial) => {
|
const servicioSelected = (
|
||||||
if (!row) return;
|
row: ServicioSocialResponse | ServicioSocialConCasoEspecial
|
||||||
|
) => {
|
||||||
if (idTipoUsuario === 1) {
|
|
||||||
|
|
||||||
if (row.idServicio) {
|
|
||||||
localStorage.setItem("idServicio", String(row.idServicio));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ("idCasoEspecial" in row && row.idCasoEspecial) {
|
|
||||||
localStorage.setItem("idCasoEspecial", String(row.idCasoEspecial));
|
|
||||||
}
|
|
||||||
|
|
||||||
router.push("/administrador/servicio");
|
|
||||||
|
|
||||||
} else if (
|
|
||||||
row.idServicio ||
|
|
||||||
("idCasoEspecial" in row && row.idCasoEspecial)
|
|
||||||
) {
|
|
||||||
console.log("Limpiando selección (no admin)");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEspecial) => {
|
|
||||||
if (!row) return;
|
if (!row) return;
|
||||||
|
|
||||||
if (idTipoUsuario === 1) {
|
if (idTipoUsuario === 1) {
|
||||||
@@ -100,7 +78,6 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
localStorage.setItem("idServicio", String(row.idServicio));
|
localStorage.setItem("idServicio", String(row.idServicio));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ forma segura sin any
|
|
||||||
if ("idCasoEspecial" in row && row.idCasoEspecial) {
|
if ("idCasoEspecial" in row && row.idCasoEspecial) {
|
||||||
localStorage.setItem("idCasoEspecial", String(row.idCasoEspecial));
|
localStorage.setItem("idCasoEspecial", String(row.idCasoEspecial));
|
||||||
}
|
}
|
||||||
@@ -112,32 +89,8 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
) {
|
) {
|
||||||
console.log("Limpiando selección (no admin)");
|
console.log("Limpiando selección (no admin)");
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Codigo original
|
|
||||||
const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEspecial) => {
|
|
||||||
if (!row) return;
|
|
||||||
|
|
||||||
if (idTipoUsuario === 1) {
|
|
||||||
|
|
||||||
if (row.idServicio) {
|
|
||||||
localStorage.setItem("idServicio", String(row.idServicio));
|
|
||||||
}
|
|
||||||
if ((row as any).idCasoEspecial) {
|
|
||||||
localStorage.setItem("idCasoEspecial", String((row as any).idCasoEspecial));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Redirigir a la vista de detalle
|
|
||||||
router.push("/administrador/servicio");
|
|
||||||
} else if (row.idServicio || (row as any).idCasoEspecial) {
|
|
||||||
|
|
||||||
console.log("Limpiando selección (no admin)");
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -155,7 +108,9 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
{columnaFechaInicio && <th>Fecha Inicio</th>}
|
{columnaFechaInicio && <th>Fecha Inicio</th>}
|
||||||
{columnaFechaFin && <th>Fecha Fin</th>}
|
{columnaFechaFin && <th>Fecha Fin</th>}
|
||||||
<th>Status</th>
|
<th>Status</th>
|
||||||
{columnaCuestionarioCompleto && <th>Cuestionario Completo</th>}
|
{columnaCuestionarioCompleto && (
|
||||||
|
<th>Cuestionario Completo</th>
|
||||||
|
)}
|
||||||
{columnaCartaTermino && <th>Carta Termino</th>}
|
{columnaCartaTermino && <th>Carta Termino</th>}
|
||||||
{columnaCuestionario && <th>Cuestionario</th>}
|
{columnaCuestionario && <th>Cuestionario</th>}
|
||||||
</tr>
|
</tr>
|
||||||
@@ -167,20 +122,27 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
style={{
|
style={{
|
||||||
cursor: idTipoUsuario === 1 ? "pointer" : "default",
|
cursor: idTipoUsuario === 1 ? "pointer" : "default",
|
||||||
}}
|
}}
|
||||||
onClick={() => (
|
onClick={() =>
|
||||||
idTipoUsuario === 1 ? servicioSelected(item) : undefined
|
idTipoUsuario === 1 ? servicioSelected(item) : undefined
|
||||||
)}
|
}
|
||||||
//onClick={() => Falta corregir
|
|
||||||
//idTipoUsuario === 1 ? servicioSelected(item) : undefined
|
|
||||||
//}
|
|
||||||
>
|
>
|
||||||
|
{/* Si el padre pidió mostrar Fecha Registro, la mostramos aquí (createdAt) */}
|
||||||
|
{columnaFechaRegistro && (
|
||||||
|
<td>{formatDate((item as any).createdAt)}</td>
|
||||||
|
)}
|
||||||
|
|
||||||
<td>{item.Usuario?.usuario}</td>
|
<td>{item.Usuario?.usuario}</td>
|
||||||
<td>{item.Usuario?.nombre}</td>
|
<td>{item.Usuario?.nombre}</td>
|
||||||
<td>{item.Carrera?.carrera}</td>
|
<td>{item.Carrera?.carrera}</td>
|
||||||
|
|
||||||
|
{/* Usar las propiedades en camelCase que vienen en tu JSON */}
|
||||||
{columnaFechaInicio && (
|
{columnaFechaInicio && (
|
||||||
<td>{formatDate(item.fecha_inicio)}</td>
|
<td>{formatDate((item as any).fechaInicio)}</td>
|
||||||
)}
|
)}
|
||||||
{columnaFechaFin && <td>{formatDate(item.fecha_fin)}</td>}
|
{columnaFechaFin && (
|
||||||
|
<td>{formatDate((item as any).fechaFin)}</td>
|
||||||
|
)}
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
{columnasResponsable && item.Status?.idStatus === 7 ? (
|
{columnasResponsable && item.Status?.idStatus === 7 ? (
|
||||||
<button
|
<button
|
||||||
@@ -202,21 +164,24 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
)}
|
)}
|
||||||
</td>
|
</td>
|
||||||
{columnaCartaTermino && (
|
{columnaCartaTermino && (
|
||||||
<td>{item.cartaTermino ? (
|
<td>
|
||||||
|
{item.cartaTermino ? (
|
||||||
<span className="badge bg-success">Completado</span>
|
<span className="badge bg-success">Completado</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="badge bg-danger">No Completado</span>
|
<span className="badge bg-danger">No Completado</span>
|
||||||
)}</td>
|
)}
|
||||||
|
</td>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{columnaCuestionarioCompleto && (
|
{columnaCuestionarioCompleto && (
|
||||||
<td>{item.cuestionarioCompletado ? (
|
<td>
|
||||||
|
{item.cuestionarioCompletado ? (
|
||||||
<span className="badge bg-success">Completado</span>
|
<span className="badge bg-success">Completado</span>
|
||||||
) : (
|
) : (
|
||||||
<span className="badge bg-danger">No Completado</span>
|
<span className="badge bg-danger">No Completado</span>
|
||||||
)}</td>
|
|
||||||
)}
|
)}
|
||||||
|
</td>
|
||||||
|
)}
|
||||||
|
|
||||||
{columnaCuestionario && (
|
{columnaCuestionario && (
|
||||||
<td>
|
<td>
|
||||||
@@ -254,9 +219,7 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-outline-primary ms-2"
|
className="btn btn-sm btn-outline-primary ms-2"
|
||||||
onClick={handleNext}
|
onClick={handleNext}
|
||||||
disabled={
|
disabled={currentPage >= Math.max(1, Math.ceil(total / 10))}
|
||||||
currentPage >= Math.max(1, Math.ceil(total / 10))
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
Siguiente
|
Siguiente
|
||||||
</button>
|
</button>
|
||||||
@@ -271,7 +234,6 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
function formatDate(value?: string | null): string {
|
function formatDate(value?: string | null): string {
|
||||||
if (!value) return "";
|
if (!value) return "";
|
||||||
|
|
||||||
// Si ya viene como fecha ISO, forzamos a hora local sin modificar el día
|
|
||||||
const d = new Date(value.includes("T") ? value : `${value}T00:00:00`);
|
const d = new Date(value.includes("T") ? value : `${value}T00:00:00`);
|
||||||
|
|
||||||
if (isNaN(d.getTime())) {
|
if (isNaN(d.getTime())) {
|
||||||
@@ -286,9 +248,6 @@ function formatDate(value?: string | null): string {
|
|||||||
return `${day}/${month}/${year}`;
|
return `${day}/${month}/${year}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function statusClass(id?: number) {
|
function statusClass(id?: number) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user