Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e838a5b78d |
+17
-15
@@ -1,10 +1,10 @@
|
|||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
|
|
||||||
// Crea una instancia base de Axios
|
// Crea una instancia base de Axios
|
||||||
export const axiosInstance = axios.create({
|
export const axiosInstance = axios.create({
|
||||||
baseURL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000/api', // poner la url
|
baseURL: process.env.NEXT_PUBLIC_API_URL || "http://localhost:3411", // poner la url
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
timeout: 10000, // tiempo máximo de espera (10 segundos)
|
timeout: 10000, // tiempo máximo de espera (10 segundos)
|
||||||
});
|
});
|
||||||
@@ -12,18 +12,17 @@ export const axiosInstance = axios.create({
|
|||||||
// Interceptor para agregar el token automáticamente
|
// Interceptor para agregar el token automáticamente
|
||||||
axiosInstance.interceptors.request.use(
|
axiosInstance.interceptors.request.use(
|
||||||
(config) => {
|
(config) => {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
const token = localStorage.getItem('token');
|
const token = localStorage.getItem("token");
|
||||||
if (token) {
|
if (token) {
|
||||||
// Múltiples formatos según lo que espere el backend
|
// Múltiples formatos según lo que espere el backend
|
||||||
config.headers.Authorization = `Bearer ${token}`;
|
config.headers.Authorization = `Bearer ${token}`;
|
||||||
|
|
||||||
//Quitar estas lienas
|
//Quitar estas lienas
|
||||||
config.headers['token'] = token;
|
config.headers["token"] = token;
|
||||||
config.headers['x-access-token'] = token;
|
config.headers["x-access-token"] = token;
|
||||||
config.headers['token-v2'] = token;
|
config.headers["token-v2"] = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return config;
|
return config;
|
||||||
},
|
},
|
||||||
@@ -37,21 +36,24 @@ axiosInstance.interceptors.response.use(
|
|||||||
if (error.response) {
|
if (error.response) {
|
||||||
// Token inválido o sesión expirada
|
// Token inválido o sesión expirada
|
||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
console.warn('Sesión expirada o token inválido.');
|
console.warn("Sesión expirada o token inválido.");
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== "undefined") {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
window.location.href = '/'; // redirige automáticamente
|
window.location.href = "/"; // redirige automáticamente
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Errores del servidor
|
// Errores del servidor
|
||||||
console.error('Error en la respuesta del servidor:', error.response.data);
|
console.error("Error en la respuesta del servidor:", error.response.data);
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
// No hubo respuesta del servidor
|
// No hubo respuesta del servidor
|
||||||
console.error('No se recibió respuesta del servidor.');
|
console.error("No se recibió respuesta del servidor.");
|
||||||
} else {
|
} else {
|
||||||
// Error en la configuración de la petición
|
// Error en la configuración de la petición
|
||||||
console.error('Error en la configuración de la solicitud:', error.message);
|
console.error(
|
||||||
|
"Error en la configuración de la solicitud:",
|
||||||
|
error.message
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
|
|||||||
+49
-25
@@ -1,4 +1,4 @@
|
|||||||
'use client'
|
"use client";
|
||||||
import { axiosInstance } from "@/api/config";
|
import { axiosInstance } from "@/api/config";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@@ -12,39 +12,38 @@ export default function Home() {
|
|||||||
const object = Object.fromEntries(formData);
|
const object = Object.fromEntries(formData);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await axiosInstance.post('/usuario/login', object);
|
const res = await axiosInstance.post("/auth/login", object);
|
||||||
|
|
||||||
// Extraer datos del backend
|
// Extraer datos del backend
|
||||||
const token = res?.data?.token ?? '';
|
const token = res?.data?.token ?? "";
|
||||||
const usuarioObj = res?.data?.Usuario ?? res?.data ?? {};
|
const usuarioObj = res?.data?.Usuario ?? res?.data ?? {};
|
||||||
const idUsuario = usuarioObj.idUsuario ?? '';
|
const idUsuario = usuarioObj.idUsuario ?? "";
|
||||||
const usuario = usuarioObj.usuario ?? '';
|
const usuario = usuarioObj.usuario ?? "";
|
||||||
const nombre = usuarioObj.nombre ?? '';
|
const nombre = usuarioObj.nombre ?? "";
|
||||||
const idTipoUsuario = Number(usuarioObj.TipoUsuario?.idTipoUsuario ?? 0);
|
const idTipoUsuario = Number(usuarioObj.TipoUsuario?.idTipoUsuario ?? 0);
|
||||||
//const idTipoUsuario = Number((usuarioObj as any).TipoUsuario?.idTipoUsuario ?? 0);
|
//const idTipoUsuario = Number((usuarioObj as any).TipoUsuario?.idTipoUsuario ?? 0);
|
||||||
|
|
||||||
|
|
||||||
// Guardar en localStorage
|
// Guardar en localStorage
|
||||||
localStorage.setItem('token', String(token));
|
localStorage.setItem("token", String(token));
|
||||||
localStorage.setItem('idUsuario', String(idUsuario));
|
localStorage.setItem("idUsuario", String(idUsuario));
|
||||||
localStorage.setItem('usuario', String(usuario));
|
localStorage.setItem("usuario", String(usuario));
|
||||||
localStorage.setItem('nombre', String(nombre));
|
localStorage.setItem("nombre", String(nombre));
|
||||||
localStorage.setItem('idTipoUsuario', String(idTipoUsuario));
|
localStorage.setItem("idTipoUsuario", String(idTipoUsuario));
|
||||||
|
|
||||||
// Validar y redirigir según el idTipoUsuario
|
// Validar y redirigir según el idTipoUsuario
|
||||||
if (token && idUsuario && idTipoUsuario) {
|
if (token && idUsuario && idTipoUsuario) {
|
||||||
switch (idTipoUsuario) {
|
switch (idTipoUsuario) {
|
||||||
case 1:
|
case 1:
|
||||||
router.push('/administrador');
|
router.push("/administrador");
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
router.push('/responsable');
|
router.push("/responsable");
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
router.push('/alumno');
|
router.push("/alumno");
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
router.push('/casoEspecial');
|
router.push("/casoEspecial");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn(`Tipo de usuario desconocido: ${idTipoUsuario}`);
|
console.warn(`Tipo de usuario desconocido: ${idTipoUsuario}`);
|
||||||
@@ -53,31 +52,56 @@ export default function Home() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
console.error('Error: datos de usuario incompletos');
|
console.error("Error: datos de usuario incompletos");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error en el inicio de sesión:', error);
|
console.error("Error en el inicio de sesión:", error);
|
||||||
localStorage.clear();
|
localStorage.clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="d-flex justify-content-center align-items-center bg-light" style={{ minHeight: 'calc(100vh - 200px)' }}>
|
<div
|
||||||
<form className="p-4 shadow rounded bg-white w-100" style={{ maxWidth: '400px' }} onSubmit={handleOnSubmit}>
|
className="d-flex justify-content-center align-items-center bg-light"
|
||||||
|
style={{ minHeight: "calc(100vh - 200px)" }}
|
||||||
|
>
|
||||||
|
<form
|
||||||
|
className="p-4 shadow rounded bg-white w-100"
|
||||||
|
style={{ maxWidth: "400px" }}
|
||||||
|
onSubmit={handleOnSubmit}
|
||||||
|
>
|
||||||
<h2 className="text-center mb-4 fw-bold">IRIS</h2>
|
<h2 className="text-center mb-4 fw-bold">IRIS</h2>
|
||||||
|
|
||||||
<div className="mb-3">
|
<div className="mb-3">
|
||||||
<label htmlFor="usuario" className="form-label">Usuario</label>
|
<label htmlFor="usuario" className="form-label">
|
||||||
<input type="text" name="usuario" id="usuario" className="form-control" required />
|
Usuario
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
name="usuario"
|
||||||
|
id="usuario"
|
||||||
|
className="form-control"
|
||||||
|
required
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-4">
|
<div className="mb-4">
|
||||||
<label htmlFor="password" className="form-label">Contraseña</label>
|
<label htmlFor="password" className="form-label">
|
||||||
<input type="password" name="password" id="password" className="form-control" required />
|
Contraseña
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
name="password"
|
||||||
|
id="password"
|
||||||
|
className="form-control"
|
||||||
|
required
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="d-grid">
|
<div className="d-grid">
|
||||||
<button type="submit" className="btn btn-primary btn-lg">Iniciar Sesión</button>
|
<button type="submit" className="btn btn-primary btn-lg">
|
||||||
|
Iniciar Sesión
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from "next/navigation";
|
||||||
import { Form, FormGroup, FormLabel, FormControl, FormSelect, Button, InputGroup, Row, Col } from "react-bootstrap";
|
import {
|
||||||
|
Form,
|
||||||
|
FormGroup,
|
||||||
|
FormLabel,
|
||||||
|
FormControl,
|
||||||
|
FormSelect,
|
||||||
|
Button,
|
||||||
|
InputGroup,
|
||||||
|
Row,
|
||||||
|
Col,
|
||||||
|
} from "react-bootstrap";
|
||||||
import { FaUser, FaSchool, FaInfoCircle } from "react-icons/fa";
|
import { FaUser, FaSchool, FaInfoCircle } from "react-icons/fa";
|
||||||
import ServicioSocialTabla from "../servicio-social-tabla";
|
import ServicioSocialTabla from "../servicio-social-tabla";
|
||||||
import { axiosInstance } from "@/api/config";
|
import { axiosInstance } from "@/api/config";
|
||||||
@@ -22,7 +32,6 @@ interface Props {
|
|||||||
|
|
||||||
type StatusItem = { idStatus: number; status: string };
|
type StatusItem = { idStatus: number; status: string };
|
||||||
|
|
||||||
|
|
||||||
export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
@@ -31,8 +40,12 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
const [data, setData] = useState<ServicioSocialResponse[]>([]);
|
const [data, setData] = useState<ServicioSocialResponse[]>([]);
|
||||||
const [status, setStatus] = useState<StatusItem[]>([]);
|
const [status, setStatus] = useState<StatusItem[]>([]);
|
||||||
|
|
||||||
const [search, setSearch] = useState({ numeroCuenta: '', nombre: '', idStatus: '' });
|
const [search, setSearch] = useState({
|
||||||
const searchAnterior = useRef({ numeroCuenta: '', nombre: '', idStatus: '' });
|
numeroCuenta: "",
|
||||||
|
nombre: "",
|
||||||
|
idStatus: "",
|
||||||
|
});
|
||||||
|
const searchAnterior = useRef({ numeroCuenta: "", nombre: "", idStatus: "" });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (admin?.idTipoUsuario === 1) {
|
if (admin?.idTipoUsuario === 1) {
|
||||||
@@ -48,7 +61,7 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
|
|
||||||
async function obtenerServicios(pagina?: number) {
|
async function obtenerServicios(pagina?: number) {
|
||||||
const paginaActual = pagina ?? page;
|
const paginaActual = pagina ?? page;
|
||||||
let query = '';
|
let query = "";
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
@@ -62,21 +75,35 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
searchAnterior.current = { ...search };
|
searchAnterior.current = { ...search };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (search.idStatus) query += `&idStatus=${encodeURIComponent(search.idStatus)}`;
|
if (search.idStatus)
|
||||||
|
query += `&idStatus=${encodeURIComponent(search.idStatus)}`;
|
||||||
if (search.nombre) query += `&nombre=${encodeURIComponent(search.nombre)}`;
|
if (search.nombre) query += `&nombre=${encodeURIComponent(search.nombre)}`;
|
||||||
if (search.numeroCuenta) query += `&numeroCuenta=${encodeURIComponent(search.numeroCuenta)}`;
|
if (search.numeroCuenta)
|
||||||
|
query += `&numeroCuenta=${encodeURIComponent(search.numeroCuenta)}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// asegurar que enviamos Authorization si existe en admin, y loggear token para debug
|
// asegurar que enviamos Authorization si existe en admin, y loggear token para debug
|
||||||
const config = admin?.token ? { headers: { Authorization: `Bearer ${admin.token}` } } : undefined;
|
const config = admin?.token
|
||||||
console.debug('Obtener servicios - localStorage token:', typeof window !== 'undefined' ? localStorage.getItem('token') : undefined, 'admin.token:', admin?.token);
|
? { headers: { Authorization: `Bearer ${admin.token}` } }
|
||||||
const res = await axiosInstance.get(`/servicio/servicios_admin?pagina=${paginaActual}${query}`, config);
|
: undefined;
|
||||||
console.debug('Respuesta servicios_admin:', res.data);
|
console.debug(
|
||||||
|
"Obtener servicios - localStorage token:",
|
||||||
|
typeof window !== "undefined"
|
||||||
|
? localStorage.getItem("token")
|
||||||
|
: undefined,
|
||||||
|
"admin.token:",
|
||||||
|
admin?.token
|
||||||
|
);
|
||||||
|
const res = await axiosInstance.get(
|
||||||
|
`/servicio/admin?pagina=${paginaActual}${query}`,
|
||||||
|
config
|
||||||
|
);
|
||||||
|
console.debug("Respuesta servicios_admin:", res.data);
|
||||||
setData(res.data.serviciosAdmin || []);
|
setData(res.data.serviciosAdmin || []);
|
||||||
setTotal(res.data.count ?? 0);
|
setTotal(res.data.count ?? 0);
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
// manejar error
|
// manejar error
|
||||||
console.error('Error obtenerServicios', err);
|
console.error("Error obtenerServicios", err);
|
||||||
//const mensaje = (err as any)?.response?.data ?? String(err); Falta imprimir error
|
//const mensaje = (err as any)?.response?.data ?? String(err); Falta imprimir error
|
||||||
//imprimirError(mensaje);
|
//imprimirError(mensaje);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -87,25 +114,29 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
const obtenerCatalogoStatus = async () => {
|
const obtenerCatalogoStatus = async () => {
|
||||||
try {
|
try {
|
||||||
//const headers = responsable?.token ? { Authorization: `Bearer ${responsable.token}` } : undefined;
|
//const headers = responsable?.token ? { Authorization: `Bearer ${responsable.token}` } : undefined;
|
||||||
const res = await axiosInstance.get<StatusItem[]>('/status');
|
const res = await axiosInstance.get<StatusItem[]>("/status");
|
||||||
setStatus(res.data);
|
setStatus(res.data);
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
//console.log('Status obtenidos', status);
|
//console.log('Status obtenidos', status);
|
||||||
obtenerServicios();
|
obtenerServicios();
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
const axiosErr = err as AxiosError;
|
const axiosErr = err as AxiosError;
|
||||||
console.log('Error al obtener catálogo de status:', err);
|
console.log("Error al obtener catálogo de status:", err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<div className="columns">
|
<div className="columns">
|
||||||
<h2 className="title">Servicios Sociales</h2>
|
<h2 className="title">Servicios Sociales</h2>
|
||||||
|
|
||||||
<section className="container-fluid my-4">
|
<section className="container-fluid my-4">
|
||||||
<Form onSubmit={(e) => { e.preventDefault(); obtenerServicios(1); }}>
|
<Form
|
||||||
|
onSubmit={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
obtenerServicios(1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Row className="g-3">
|
<Row className="g-3">
|
||||||
<Col md={3}>
|
<Col md={3}>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
@@ -119,8 +150,15 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
placeholder="No.Cuenta"
|
placeholder="No.Cuenta"
|
||||||
maxLength={9}
|
maxLength={9}
|
||||||
value={search.numeroCuenta}
|
value={search.numeroCuenta}
|
||||||
onChange={(e) => setSearch(prev => ({ ...prev, numeroCuenta: e.target.value }))}
|
onChange={(e) =>
|
||||||
onKeyDown={(e) => { if (e.key === 'Enter') obtenerServicios(1); }}
|
setSearch((prev) => ({
|
||||||
|
...prev,
|
||||||
|
numeroCuenta: e.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") obtenerServicios(1);
|
||||||
|
}}
|
||||||
className="rounded-4"
|
className="rounded-4"
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
@@ -138,8 +176,15 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="Nombre"
|
placeholder="Nombre"
|
||||||
value={search.nombre}
|
value={search.nombre}
|
||||||
onChange={(e) => setSearch(prev => ({ ...prev, nombre: e.target.value }))}
|
onChange={(e) =>
|
||||||
onKeyDown={(e) => { if (e.key === 'Enter') obtenerServicios(1); }}
|
setSearch((prev) => ({
|
||||||
|
...prev,
|
||||||
|
nombre: e.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") obtenerServicios(1);
|
||||||
|
}}
|
||||||
className="rounded-4"
|
className="rounded-4"
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
@@ -155,12 +200,19 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
</InputGroup.Text>
|
</InputGroup.Text>
|
||||||
<FormSelect
|
<FormSelect
|
||||||
value={search.idStatus}
|
value={search.idStatus}
|
||||||
onChange={(e) => setSearch(Prev => ({ ...Prev, idStatus: e.target.value }))}
|
onChange={(e) =>
|
||||||
|
setSearch((Prev) => ({
|
||||||
|
...Prev,
|
||||||
|
idStatus: e.target.value,
|
||||||
|
}))
|
||||||
|
}
|
||||||
className="rounded-4"
|
className="rounded-4"
|
||||||
>
|
>
|
||||||
<option value="">Status</option>
|
<option value="">Status</option>
|
||||||
{status.slice(0, 10).map((s) => (
|
{status.slice(0, 10).map((s) => (
|
||||||
<option key={s.idStatus} value={s.idStatus}>{s.status}</option>
|
<option key={s.idStatus} value={s.idStatus}>
|
||||||
|
{s.status}
|
||||||
|
</option>
|
||||||
))}
|
))}
|
||||||
</FormSelect>
|
</FormSelect>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
@@ -168,8 +220,12 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col md={3} className="d-flex align-items-end">
|
<Col md={3} className="d-flex align-items-end">
|
||||||
<Button type="submit" className="w-100 rounded-5" disabled={isLoading}>
|
<Button
|
||||||
{isLoading ? 'Buscando...' : 'Buscar'}
|
type="submit"
|
||||||
|
className="w-100 rounded-5"
|
||||||
|
disabled={isLoading}
|
||||||
|
>
|
||||||
|
{isLoading ? "Buscando..." : "Buscar"}
|
||||||
</Button>
|
</Button>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
@@ -177,7 +233,6 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<ServicioSocialTabla
|
<ServicioSocialTabla
|
||||||
data={data}
|
data={data}
|
||||||
total={total}
|
total={total}
|
||||||
@@ -196,12 +251,10 @@ export default function TablaServicioSocial({ admin, imprimirError }: Props) {
|
|||||||
//if ((row as any)?.idServicio) localStorage.setItem('idServicio', String((row as any).idServicio));
|
//if ((row as any)?.idServicio) localStorage.setItem('idServicio', String((row as any).idServicio));
|
||||||
router.push(`/responsable/${path}`);
|
router.push(`/responsable/${path}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error al manejar acción de fila', e);
|
console.error("Error al manejar acción de fila", e);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
@@ -68,11 +71,12 @@ export default function ServicioSocialTabla({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEspecial) => {
|
const servicioSelected = (
|
||||||
|
row: ServicioSocialResponse | ServicioSocialConCasoEspecial
|
||||||
|
) => {
|
||||||
if (!row) return;
|
if (!row) return;
|
||||||
|
|
||||||
if (idTipoUsuario === 1) {
|
if (idTipoUsuario === 1) {
|
||||||
|
|
||||||
if (row.idServicio) {
|
if (row.idServicio) {
|
||||||
localStorage.setItem("idServicio", String(row.idServicio));
|
localStorage.setItem("idServicio", String(row.idServicio));
|
||||||
}
|
}
|
||||||
@@ -85,19 +89,18 @@ export default function ServicioSocialTabla({
|
|||||||
if (row.idServicio) {
|
if (row.idServicio) {
|
||||||
router.push("/administrador/servicio");
|
router.push("/administrador/servicio");
|
||||||
} else if ("idCasoEspecial" in row && row.idCasoEspecial) {
|
} else if ("idCasoEspecial" in row && row.idCasoEspecial) {
|
||||||
router.push('/administrador/casos_especiales/caso_especial')
|
router.push("/administrador/casos_especiales/caso_especial");
|
||||||
}
|
}
|
||||||
// Hacer validacion para saber que id fue y redireccionar
|
// Hacer validacion para saber que id fue y redireccionar
|
||||||
//router.push("/administrador/servicio");
|
//router.push("/administrador/servicio");
|
||||||
//router.push('/administrador/casos_especiales/caso_especial')
|
//router.push('/administrador/casos_especiales/caso_especial')
|
||||||
|
|
||||||
} else if (
|
} else if (
|
||||||
row.idServicio ||
|
row.idServicio ||
|
||||||
("idCasoEspecial" in row && row.idCasoEspecial)
|
("idCasoEspecial" in row && row.idCasoEspecial)
|
||||||
) {
|
) {
|
||||||
console.log("Limpiando selección (no admin)");
|
console.log("Limpiando selección (no admin)");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEspecial) => {
|
const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEspecial) => {
|
||||||
@@ -163,7 +166,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>
|
||||||
@@ -175,23 +180,25 @@ 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
|
//onClick={() => Falta corregir
|
||||||
//idTipoUsuario === 1 ? servicioSelected(item) : undefined
|
//idTipoUsuario === 1 ? servicioSelected(item) : undefined
|
||||||
//}
|
//}
|
||||||
>
|
>
|
||||||
{columnaFechaRegistro && <td>{formatDate(item.createdAt)}</td>}
|
{columnaFechaRegistro && (
|
||||||
<td>{item.Usuario?.usuario}</td>
|
<td>{formatDate(item.createdAt)}</td>
|
||||||
<td>{item.Usuario?.nombre}</td>
|
)}
|
||||||
<td>{item.Carrera?.carrera}</td>
|
<td>{item.usuario?.usuario}</td>
|
||||||
|
<td>{item.usuario?.nombre}</td>
|
||||||
|
<td>{item.carrera?.carrera}</td>
|
||||||
{columnaFechaInicio && (
|
{columnaFechaInicio && (
|
||||||
<td>{formatDate(item.fechaInicio)}</td>
|
<td>{formatDate(item.fechaInicio)}</td>
|
||||||
)}
|
)}
|
||||||
{columnaFechaFin && <td>{formatDate(item.fechaFin)}</td>}
|
{columnaFechaFin && <td>{formatDate(item.fechaFin)}</td>}
|
||||||
<td>
|
<td>
|
||||||
{columnasResponsable && item.Status?.idStatus === 7 ? (
|
{columnasResponsable && item.status?.idStatus === 7 ? (
|
||||||
<button
|
<button
|
||||||
className="btn btn-sm btn-danger"
|
className="btn btn-sm btn-danger"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
@@ -203,29 +210,32 @@ const servicioSelected = (row: ServicioSocialResponse | ServicioSocialConCasoEsp
|
|||||||
) : (
|
) : (
|
||||||
<span
|
<span
|
||||||
className={`badge bg-${statusClass(
|
className={`badge bg-${statusClass(
|
||||||
item.Status?.idStatus
|
item.status?.idStatus
|
||||||
)}`}
|
)}`}
|
||||||
>
|
>
|
||||||
{item.Status?.status}
|
{item.status?.status}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</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>
|
||||||
@@ -263,9 +273,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>
|
||||||
@@ -295,9 +303,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:
|
||||||
|
|||||||
Vendored
+3
-3
@@ -8,9 +8,9 @@ export interface ServicioSocialResponse {
|
|||||||
fechaFin?: string | null;
|
fechaFin?: string | null;
|
||||||
fechaInicio?: string | null;
|
fechaInicio?: string | null;
|
||||||
fecha_registro?: string | null;
|
fecha_registro?: string | null;
|
||||||
Usuario?: Usuario;
|
usuario?: Usuario;
|
||||||
Carrera?: Carrera;
|
carrera?: Carrera;
|
||||||
Status?: Status;
|
status?: Status;
|
||||||
cartaTermino?: boolean;
|
cartaTermino?: boolean;
|
||||||
idCuestionarioPrograma?: number | null;
|
idCuestionarioPrograma?: number | null;
|
||||||
idCuestionarioPrograma2?: number | null;
|
idCuestionarioPrograma2?: number | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user