Modificaciones
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
"use client"
|
||||
import Footer from "@/components/layout/footer";
|
||||
import Header from "@/components/layout/header";
|
||||
import Logout from "@/components/layout/logout";
|
||||
@@ -12,7 +11,7 @@ export default function AdministradorLayout({
|
||||
children}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
return (
|
||||
<>
|
||||
<Logout />
|
||||
<main className="bg-light">{children}</main>
|
||||
|
||||
@@ -5,14 +5,22 @@ import Link from "next/link";
|
||||
|
||||
export default function Administrador() {
|
||||
const [admin, setAdmin] = useState<{ idTipoUsuario: number; token?: string } | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const idTipoUsuario = Number(localStorage.getItem('idTipoUsuario') ?? 0);
|
||||
const token = localStorage.getItem('token') ?? undefined;
|
||||
if (!idTipoUsuario) return; // no logueado
|
||||
setAdmin({ idTipoUsuario, token });
|
||||
|
||||
console.log('Datos del administrador', admin)
|
||||
|
||||
if (!idTipoUsuario) {
|
||||
// no logueado - redirigir a login
|
||||
setIsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const adminData = { idTipoUsuario, token };
|
||||
setAdmin(adminData);
|
||||
setIsLoading(false);
|
||||
console.log('Datos del administrador:', adminData);
|
||||
|
||||
}, []);
|
||||
|
||||
@@ -33,7 +41,7 @@ export default function Administrador() {
|
||||
<button>Ver casos Especiales</button>
|
||||
</Link>
|
||||
</div>
|
||||
{admin ? <TablaServicioSocial admin={admin} imprimirError={imprimirError}/> : <div>Cargando...</div>}
|
||||
{!isLoading && admin ? <TablaServicioSocial admin={admin} imprimirError={imprimirError}/> : <div>Cargando...</div>}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -20,7 +20,7 @@ export default function Servicio() {
|
||||
alert(`Error: ${mensaje}`);
|
||||
};
|
||||
|
||||
// ⚠️ NUEVA función para advertencias (confirmaciones)
|
||||
// NUEVA función para advertencias (confirmaciones)
|
||||
const imprimirWarning = (mensaje: string, onConfirm: () => void) => {
|
||||
if (window.confirm(mensaje)) {
|
||||
onConfirm();
|
||||
|
||||
@@ -132,22 +132,44 @@ export default function Servicio() {
|
||||
setAdmin({ token });
|
||||
}, []);
|
||||
|
||||
const confirmar = (message: string, onConfirm: () => void) => {
|
||||
Swal.fire({
|
||||
title: message,
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'confirmar',
|
||||
cancelButtonText: 'cancelar',
|
||||
confirmButtonColor: "#0d6efd",
|
||||
cancelButtonColor: "#dc3545",
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
onConfirm();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Función para imprimir errores
|
||||
const imprimirError = (error: unknown) => {
|
||||
alert(`❌ Error: ${JSON.stringify(error)}`);
|
||||
|
||||
Swal.fire('Error', JSON.stringify(error), 'error')
|
||||
// alert(`❌ Error: ${JSON.stringify(error)}`);
|
||||
}
|
||||
|
||||
const imprimirMensaje = (message: string) => {
|
||||
alert(`✅ ${message}`);
|
||||
Swal.fire('Exito', message, 'success')
|
||||
// alert(`✅ ${message}`);
|
||||
};
|
||||
|
||||
const imprimirWarning = (message: string, onConfirm: () => void) => {
|
||||
if (confirm(`⚠️ ${message}\n¿Deseas continuar?`)) {
|
||||
onConfirm();
|
||||
}
|
||||
confirmar(message, onConfirm)
|
||||
// if (confirm(`
|
||||
// ${Swal.fire('Aviso', message, 'warning')}
|
||||
// `)) {
|
||||
// onConfirm();
|
||||
// }
|
||||
};
|
||||
|
||||
// Función para actualizar el estado de carga
|
||||
// Función para acualizar el estado de carga
|
||||
const updateIsLoading = (value: boolean) => {
|
||||
setIsLoading(value);
|
||||
};
|
||||
@@ -207,8 +229,8 @@ export default function Servicio() {
|
||||
try {
|
||||
updateIsLoading(true);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
throw new Error('Api caida')
|
||||
// await new Promise(resolve => setTimeout(resolve, 3000));
|
||||
// throw new Error('Api caida')
|
||||
const res = await axiosInstance.get(`/servicio/admin/${idServicioVal}`); //, adminInfo.token
|
||||
console.log('Respuesta del servicio:', res.data);
|
||||
setDatos(res.data);
|
||||
|
||||
+51
-57
@@ -57,6 +57,7 @@ interface Programa {
|
||||
|
||||
export default function Home() {
|
||||
const [data, setData] = useState<InfoAlumnoExtendido>();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
// const [servicio, setServicio] = useState<InfoAlumno>();
|
||||
|
||||
const handleInfo = async () => {
|
||||
@@ -86,11 +87,13 @@ export default function Home() {
|
||||
|
||||
setData(combinado);
|
||||
|
||||
console.log("Este es el status del alumno", data?.status.idStatus)
|
||||
console.log("Este es el status del alumno", combinado?.status.idStatus)
|
||||
|
||||
console.log("Este es la infromacion combinada", data);
|
||||
console.log("Este es la infromacion combinada", combinado);
|
||||
} catch (error) {
|
||||
console.log("Error al hacer la peticion ", error)
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,62 +107,53 @@ export default function Home() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
{ data?.status.idStatus && (
|
||||
<BarraProgreso idStatus={data?.status.idStatus}/>
|
||||
{!isLoading ? (
|
||||
<>
|
||||
{ data?.status.idStatus && (
|
||||
<BarraProgreso idStatus={data?.status.idStatus}/>
|
||||
)}
|
||||
|
||||
<div className="my-5">
|
||||
<MensajeAlumno status={{ idStatus: data?.status.idStatus ?? 6 }} />
|
||||
</div>
|
||||
|
||||
{ data && (
|
||||
<InformacinoServicio
|
||||
servicio={data}
|
||||
/>
|
||||
)}
|
||||
|
||||
{ data?.status.idStatus === 2 && (
|
||||
<CompletarDatosPersonales
|
||||
idServicio={data.idServicio}
|
||||
alumno={{ token: { headers: { Authorization: "Bearer ..." } }, tokenArchivo: { headers: { Authorization: "Bearer ..." } } }}
|
||||
imprimirMensaje={(msg) => console.log(msg)}
|
||||
imprimirWarning={(msg, callback) => { if (confirm(msg)) callback(); }}
|
||||
imprimirError={(err) => console.error(err)}
|
||||
obtenerServicio={() => console.log("obtener servicio")}
|
||||
updateIsLoading={(loading) => console.log("loading", loading)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{ data?.status.idStatus !== undefined && data?.status.idStatus >= 4 && data?.status.idStatus !== 8 && (
|
||||
<PreTermino
|
||||
alumno={{tokenAlumno: localStorage.getItem('token') || ""}}
|
||||
servicio={data}
|
||||
imprimirMensaje={(msg) => console.log(msg)}
|
||||
imprimirWarning={(msg, callback) => {
|
||||
if (confirm(msg)) callback();
|
||||
}}
|
||||
imprimirError={(err) => console.error(err)}
|
||||
obtenerServicio={() => console.log("obtener servicio")}
|
||||
updateIsLoading={(loading) => console.log("loading", loading)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<div className="my-5">
|
||||
<p>Cargando...</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="my-5">
|
||||
<MensajeAlumno status={{ idStatus: data?.status.idStatus ?? 6 }} />
|
||||
</div>
|
||||
|
||||
{/* servicio={{
|
||||
Programa: {
|
||||
institucion: "UNAM",
|
||||
dependencia: "Académicos",
|
||||
programa: "Servicio Social",
|
||||
clavePrograma: "SS123",
|
||||
},
|
||||
Usuario: { usuario: "123456", nombre: "Juan Pérez" },
|
||||
Carrera: { carrera: "Matemáticas" },
|
||||
creditos: "80",
|
||||
correo: "juan@correo.com",
|
||||
fechaInicio: new Date().toISOString(),
|
||||
fechaFin: new Date().toISOString(),
|
||||
createdAt: new Date().toISOString(),
|
||||
}} */}
|
||||
|
||||
{ data && (
|
||||
<InformacinoServicio
|
||||
servicio={data}
|
||||
/>
|
||||
)}
|
||||
|
||||
{ data?.status.idStatus === 2 && (
|
||||
<CompletarDatosPersonales
|
||||
idServicio={data.idServicio}
|
||||
alumno={{ token: { headers: { Authorization: "Bearer ..." } }, tokenArchivo: { headers: { Authorization: "Bearer ..." } } }}
|
||||
imprimirMensaje={(msg) => console.log(msg)}
|
||||
imprimirWarning={(msg, callback) => { if (confirm(msg)) callback(); }}
|
||||
imprimirError={(err) => console.error(err)}
|
||||
obtenerServicio={() => console.log("obtener servicio")}
|
||||
updateIsLoading={(loading) => console.log("loading", loading)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{ data?.status.idStatus !== undefined && data?.status.idStatus >= 4 && data?.status.idStatus !== 8 && (
|
||||
<PreTermino
|
||||
alumno={{tokenAlumno: localStorage.getItem('token') || ""}}
|
||||
servicio={data}
|
||||
imprimirMensaje={(msg) => console.log(msg)}
|
||||
imprimirWarning={(msg, callback) => {
|
||||
if (confirm(msg)) callback();
|
||||
}}
|
||||
imprimirError={(err) => console.error(err)}
|
||||
obtenerServicio={() => console.log("obtener servicio")}
|
||||
updateIsLoading={(loading) => console.log("loading", loading)}
|
||||
/>
|
||||
)}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ type LocalResponsable = { idUsuario?: number; idTipoUsuario?: number; tipoUsuari
|
||||
export default function Page() {
|
||||
const router = useRouter();
|
||||
const [responsable, setResponsable] = useState<LocalResponsable>({});
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const getMessageFromUnknown = (err: unknown) => {
|
||||
if (typeof err === 'string') return err;
|
||||
@@ -32,7 +33,8 @@ export default function Page() {
|
||||
const idTipoUsuario = Number(localStorage.getItem('idTipoUsuario'));
|
||||
const tipoUsuario = localStorage.getItem('tipoUsuario');
|
||||
const token = localStorage.getItem('token') || undefined;
|
||||
setResponsable({ idUsuario: Number.isNaN(idUsuario) ? undefined : idUsuario, idTipoUsuario: Number.isNaN(idTipoUsuario) ? undefined : idTipoUsuario, tipoUsuario, token: token ?? undefined });
|
||||
setResponsable({ idUsuario: Number.isNaN(idUsuario) ? undefined : idUsuario, idTipoUsuario: Number.isNaN(idTipoUsuario) ? undefined : idTipoUsuario, tipoUsuario, token: token ?? undefined });
|
||||
setIsLoading(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -41,7 +43,7 @@ export default function Page() {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (responsable.idTipoUsuario === 1) router.push('/admin');
|
||||
if (responsable.idTipoUsuario === 1) router.push('/administrador');
|
||||
if (responsable.idTipoUsuario === 2) router.push('/responsable');
|
||||
if (responsable.idTipoUsuario === 3) router.push('/alumno');
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
@@ -53,9 +55,13 @@ export default function Page() {
|
||||
<button className="rounded-2" onClick={() => router.push('/casoEspecial/nuevo')}>Nuevo Caso Especial</button>
|
||||
</div>
|
||||
|
||||
{responsable.idTipoUsuario !== undefined && responsable.token ? (
|
||||
<LiberarCasoEspecial responsable={{ idTipoUsuario: responsable.idTipoUsuario!, token: responsable.token! }} imprimirError={(msg: string) => imprimirError(msg)} />
|
||||
) : null}
|
||||
{!isLoading ? (
|
||||
responsable.idTipoUsuario !== undefined && responsable.token ? (
|
||||
<LiberarCasoEspecial responsable={{ idTipoUsuario: responsable.idTipoUsuario!, token: responsable.token! }} imprimirError={(msg: string) => imprimirError(msg)} />
|
||||
) : null
|
||||
) : (
|
||||
<div>Cargando...</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@ import Header from "@/components/layout/header";
|
||||
import "./globals.css";
|
||||
import Footer from "@/components/layout/footer";
|
||||
import "@/sass/bootstrap.scss"
|
||||
|
||||
import { Metadata } from 'next';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
@@ -18,7 +17,7 @@ export default function RootLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
children: React.ReactNode;
|
||||
}>) {
|
||||
}>) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className="d-flex flex-column min-vh-100">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
'use client'
|
||||
import Logout from "@/components/layout/logout";
|
||||
|
||||
export default function ResponsableLayout({
|
||||
|
||||
@@ -21,6 +21,7 @@ export default function Page() {
|
||||
const router = useRouter();
|
||||
|
||||
const [responsable, setResponsable] = useState<Responsable>({});
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [status, setStatus] = useState<StatusItem[]>([]);
|
||||
|
||||
const imprimirError: ImprimirErrorFn = (err = { message: "" }, title = '¡Hubo un error!', onConfirm = () => {}) => {
|
||||
@@ -61,11 +62,9 @@ export default function Page() {
|
||||
};
|
||||
|
||||
setResponsable(r);
|
||||
setIsLoading(false);
|
||||
console.log('Responsable:', r);
|
||||
console.log('id Usuario en componente padrre', r.idUsuario);
|
||||
//ontenerCatalogoStatus();
|
||||
|
||||
console.log("Esta es la infromacino del useState en responsable", responsable)
|
||||
|
||||
if (r.idTipoUsuario === 1) router.push('/administrador');
|
||||
if (r.idTipoUsuario === 3) router.push('/alumno');
|
||||
@@ -78,8 +77,8 @@ export default function Page() {
|
||||
), [responsable]);
|
||||
|
||||
return (
|
||||
<section className="container px-2 pb-6">
|
||||
<div className="pt-6 pb-4">
|
||||
<section className="container px-2 pb-6 mb-2">
|
||||
<div className="pb-3">
|
||||
<p className="is-size-4 block mt-5 h4 mb-4">Estimado(a) responsable del programa de servicio social:</p>
|
||||
|
||||
<p className="block">
|
||||
@@ -91,7 +90,7 @@ export default function Page() {
|
||||
<button className="button is-info rounded-2" onClick={() => router.push('/responsable/nuevo')}>Agregar alumno</button>
|
||||
</div>
|
||||
|
||||
{tabla}
|
||||
{!isLoading ? tabla : <div>Cargando...</div>}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { axiosInstance } from '@/api/config';
|
||||
import { isAxiosError } from 'axios';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import type { AxiosError, AxiosResponse } from 'axios';
|
||||
import Swal from "sweetalert2";
|
||||
|
||||
interface Status {
|
||||
idStatus: number;
|
||||
@@ -133,14 +134,26 @@ export default function Archivo({
|
||||
console.log("Respuesta al rechazar:", res.data);
|
||||
|
||||
const mensaje = res.data?.message || "Documento rechazado exitosamente";
|
||||
imprimirMensaje(mensaje);
|
||||
Swal.fire({
|
||||
title: 'Exito',
|
||||
text: mensaje,
|
||||
icon: 'success',
|
||||
})
|
||||
// imprimirMensaje(mensaje);
|
||||
router.replace("/administrador");
|
||||
} catch (err: unknown) {
|
||||
if (isAxiosError(err)) {
|
||||
imprimirError(err.response?.data || err.message);
|
||||
} else {
|
||||
imprimirError(err);
|
||||
}
|
||||
const axiosErr = err as AxiosError<any>;
|
||||
const mensaje = axiosErr?.response?.data?.message || 'No se pudo rechazar el documento'
|
||||
Swal.fire({
|
||||
title: 'Error',
|
||||
text: mensaje,
|
||||
icon: 'error',
|
||||
})
|
||||
// if (isAxiosError(err)) {
|
||||
// imprimirError(err.response?.data || err.message);
|
||||
// } else {
|
||||
// imprimirError(err);
|
||||
// }
|
||||
} finally {
|
||||
updateIsLoading(false);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
import { useState } from "react";
|
||||
import { axiosInstance } from '@/api/config';
|
||||
import { isAxiosError } from 'axios';
|
||||
import { AxiosError } from 'axios';
|
||||
import { useRouter } from "next/navigation";
|
||||
import Swal from "sweetalert2";
|
||||
|
||||
interface Status {
|
||||
idStatus: number;
|
||||
@@ -80,12 +81,22 @@ export default function CancelarServicio({
|
||||
updateIsLoading(true);
|
||||
const res = await axiosInstance.put(`/servicio/cancelar`, data);
|
||||
localStorage.removeItem("idServicio");
|
||||
imprimirMensaje(res.data.message);
|
||||
|
||||
Swal.fire('Exito', res.data.message, 'success')
|
||||
// imprimirMensaje(res.data.message);
|
||||
router.push("/administrador");
|
||||
} catch (err: unknown) {
|
||||
if (isAxiosError(err)) imprimirError(err.response?.data || err.message);
|
||||
else if (err instanceof Error) imprimirError(err.message);
|
||||
else imprimirError(err);
|
||||
const axiosErr = err as AxiosError<any>;
|
||||
const mensaje = axiosErr?.response?.data?.message || 'No se pudo cancelar el servicio, intentelo mas tarde.';
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: mensaje,
|
||||
})
|
||||
// if (isAxiosError(err)) imprimirError(err.response?.data || err.message);
|
||||
// else if (err instanceof Error) imprimirError(err.message);
|
||||
// else imprimirError(err);
|
||||
} finally {
|
||||
updateIsLoading(false);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
'use client'
|
||||
import { axiosInstance } from "@/api/config";
|
||||
import { CargaMasivaProps } from "@/types/responses";
|
||||
import { AxiosError } from "axios";
|
||||
import { useRouter } from "next/navigation";
|
||||
import React, { useState } from "react";
|
||||
import { Button, Form } from "react-bootstrap";
|
||||
@@ -62,9 +63,10 @@ export default function CargaMasiva({datos}: {datos: CargaMasivaProps}) {
|
||||
console.log('Respuesta de carga masiva:', res.data)
|
||||
//updateIsLoading(false)
|
||||
//ImprimirMensaje(res.data.message)
|
||||
const message = res?.data?.message || 'Se completo la carga masiva con exito.';
|
||||
Swal.fire({
|
||||
title: 'Archivo enviado',
|
||||
text: 'El archivo se subió correctamente',
|
||||
text: message, //'El archivo se subió correctamente'
|
||||
icon: 'success',
|
||||
});
|
||||
setCsv(null);
|
||||
@@ -73,9 +75,12 @@ export default function CargaMasiva({datos}: {datos: CargaMasivaProps}) {
|
||||
} catch (error) {
|
||||
//updateIsLoading(false)
|
||||
//imprimirError(error.response.data || error)
|
||||
|
||||
const axiosErr = error as AxiosError<any>;
|
||||
const mensaje = axiosErr?.response?.data?.message || 'Error en la carga masiva.'
|
||||
Swal.fire({
|
||||
title: 'Error al enviar el archivo',
|
||||
text: 'No se pudo subir el archivo',
|
||||
text: mensaje,
|
||||
icon: 'error',
|
||||
})
|
||||
setCsv(null)
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { useState } from "react";
|
||||
import { isAxiosError } from 'axios';
|
||||
import { axiosInstance } from '@/api/config';
|
||||
import type { AxiosResponse } from 'axios';
|
||||
import { AxiosError, AxiosResponse } from 'axios';
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Carrera, Usuario } from "@/types/responses";
|
||||
import Swal from "sweetalert2";
|
||||
|
||||
interface Status {
|
||||
idStatus: number;
|
||||
@@ -101,20 +102,33 @@ export default function ConfirmarServicio({
|
||||
updateIsLoading(true);
|
||||
const res = await funcConfirmar(data);
|
||||
// ✅ TS sabe que res.data.message existe
|
||||
imprimirMensaje(res.data.message);
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Exito',
|
||||
text: res.data.message,
|
||||
});
|
||||
// imprimirMensaje(res.data.message);
|
||||
router.replace("/administrador");
|
||||
} catch (err: unknown) {
|
||||
if (isAxiosError(err)) {
|
||||
imprimirError(err.response?.data || err.message);
|
||||
} else {
|
||||
imprimirError(err);
|
||||
}
|
||||
const axiosErr = err as AxiosError<any>;
|
||||
const mensaje = axiosErr?.response?.data?.message || 'No se pudo confirmar el servicio, por favor intentelo mas tarde.';
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: mensaje,
|
||||
});
|
||||
// if (isAxiosError(err)) {
|
||||
// imprimirError(err.response?.data || err.message);
|
||||
// } else {
|
||||
// imprimirError(err);
|
||||
// }
|
||||
} finally {
|
||||
updateIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const confirmarPreRegistro = (data: ConfirmarData) =>
|
||||
const confirmarPreRegistro = (data: ConfirmarData) =>
|
||||
axiosInstance.put<ApiResponse>(`/servicio/registro`, data);
|
||||
|
||||
const confirmarLiberacion = (data: ConfirmarData) => {
|
||||
@@ -122,10 +136,29 @@ export default function ConfirmarServicio({
|
||||
return axiosInstance.put<ApiResponse>(`/servicio/liberacion`, data);
|
||||
};
|
||||
|
||||
// Validar las claves permitidas en un arreglo
|
||||
const clavesPermitidas = process.env.NEXT_PUBLIC_CP?.split(',').map(c => c.trim()) || [];
|
||||
|
||||
const confirma = () => {
|
||||
Swal.fire({
|
||||
title: "¿Seguro(a) que quieres confirmar este servicio?",
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'confirmar',
|
||||
cancelButtonText: 'cancelar',
|
||||
confirmButtonColor: "#0d6efd",
|
||||
cancelButtonColor: "#dc3545",
|
||||
}).then((result) => {
|
||||
if (result.isConfirmed) {
|
||||
confirmarServicio();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
// datos.Programa?.acatlan &&
|
||||
// datos.Programa?.acatlan && datos.programa?.programa === clavesPermitidas &&
|
||||
<div className="container space-y-4">
|
||||
{datos.status?.idStatus === 5 && datos.programa?.clavePrograma === `${process.env.NEXT_PUBLIC_CP}` && (
|
||||
{datos.status?.idStatus === 5 && clavesPermitidas.includes(datos?.programa?.clavePrograma || '') && (
|
||||
<div className="flex items-center space-x-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -134,7 +167,7 @@ export default function ConfirmarServicio({
|
||||
onChange={(e) => setVistoBuenoAcatlan(e.target.checked)}
|
||||
className="form-checkbox h-5 w-5 text-blue-600"
|
||||
/>
|
||||
<label htmlFor="vistoBuenoAcatlan" className="text-gray-700 mb-4 me-2">
|
||||
<label htmlFor="vistoBuenoAcatlan" className="text-gray-700 mb-4 me-2 ms-2">
|
||||
Visto bueno Acatlán
|
||||
</label>
|
||||
</div>
|
||||
@@ -147,12 +180,7 @@ export default function ConfirmarServicio({
|
||||
datos.programa?.acatlan &&
|
||||
!vistoBuenoAcatlan
|
||||
}
|
||||
onClick={() =>
|
||||
imprimirWarning(
|
||||
"¿Seguro(a) que quieres confirmar este servicio?",
|
||||
confirmarServicio
|
||||
)
|
||||
}
|
||||
onClick={confirma}
|
||||
className={`px-4 py-2 rounded text-white ${
|
||||
datos.status?.idStatus === 5 &&
|
||||
datos.programa?.acatlan &&
|
||||
|
||||
@@ -8,10 +8,11 @@ import { Col, FormGroup, FormLabel, InputGroup } from 'react-bootstrap';
|
||||
import { FaRegCalendarAlt, FaUpload } from 'react-icons/fa';
|
||||
import DatePicker from 'react-datepicker';
|
||||
import BotonRegresar from '../boton-regresar';
|
||||
import axios from "axios";
|
||||
import axios, { AxiosError } from "axios";
|
||||
import Image from 'next/image';
|
||||
import { registerLocale } from "react-datepicker";
|
||||
import { es } from "date-fns/locale/es";
|
||||
import Swal from 'sweetalert2';
|
||||
|
||||
registerLocale("es", es);
|
||||
|
||||
@@ -143,13 +144,20 @@ export default function CasoEspecialForm({
|
||||
} catch (err: unknown) {
|
||||
resetear();
|
||||
setNumeroCuenta('');
|
||||
let msg = { message: 'Error al buscar alumno.' };
|
||||
if (typeof err === 'object' && err !== null && 'response' in err) {
|
||||
const anyErr = err as { response?: { data?: { message?: unknown } } };
|
||||
const m = anyErr.response?.data as { message?: unknown } | undefined;
|
||||
msg = { message: m?.message ? String(m.message) : msg.message };
|
||||
} else if (err instanceof Error) msg = { message: err.message };
|
||||
imprimirError(msg);
|
||||
const axiosErr = err as AxiosError<any>;
|
||||
const mensaje = axiosErr?.response?.data?.message || 'El alumno no cumple con los requisitos para hacer el servicio social.'
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: mensaje,
|
||||
})
|
||||
// let msg = { message: 'Error al buscar alumno.' };
|
||||
// if (typeof err === 'object' && err !== null && 'response' in err) {
|
||||
// const anyErr = err as { response?: { data?: { message?: unknown } } };
|
||||
// const m = anyErr.response?.data as { message?: unknown } | undefined;
|
||||
// msg = { message: m?.message ? String(m.message) : msg.message };
|
||||
// } else if (err instanceof Error) msg = { message: err.message };
|
||||
// imprimirError(msg);
|
||||
} finally {
|
||||
updateIsLoading(false);
|
||||
}
|
||||
@@ -189,6 +197,20 @@ export default function CasoEspecialForm({
|
||||
...(idStatus === '12' && { institucion: institucion.trim() }),
|
||||
...(idStatus === '12' && { dependencia: dependencia.trim() }),
|
||||
...(idStatus === '11' && { motivo }),
|
||||
// idUsuario: Number('19839'),
|
||||
// idCarrera: Number('16'),
|
||||
// idStatus: Number('11'),
|
||||
// numeroCuenta: '422016698',
|
||||
// creditos: '100',
|
||||
// correo: correo.trim(),
|
||||
// fechaInicio: formatDate(fechaInicio),
|
||||
// fechaFin: formatDate(fechaFin),
|
||||
// fechaNacimiento: formatDate(fechaNacimiento),
|
||||
// direccion: direccion.trim(),
|
||||
// telefono: telefono,
|
||||
// ...(idStatus === '12' && { institucion: institucion.trim() }),
|
||||
// ...(idStatus === '12' && { dependencia: dependencia.trim() }),
|
||||
// ...(idStatus === '11' && { motivo }),
|
||||
};
|
||||
|
||||
console.log("Datos a enviar en caso especial:", data);
|
||||
@@ -196,6 +218,7 @@ export default function CasoEspecialForm({
|
||||
const formData = new FormData();
|
||||
// agregar el archivo.
|
||||
formData.append("archivos", file);
|
||||
formData.append("alumno", JSON.stringify(data));
|
||||
|
||||
// armas los datos para el dto
|
||||
// formData.append("alumno[idUsuario]", alumno.idUsuario.toString());
|
||||
@@ -211,21 +234,21 @@ export default function CasoEspecialForm({
|
||||
// formData.append("alumno[direccion]", direccion);
|
||||
|
||||
// validaciones extra
|
||||
if (institucion) {
|
||||
formData.append("alumno[institucion]", institucion);
|
||||
}
|
||||
// if (institucion) {
|
||||
// formData.append("alumno[institucion]", institucion);
|
||||
// }
|
||||
|
||||
if (dependencia) {
|
||||
formData.append("alumno[dependencia]", dependencia);
|
||||
}
|
||||
// if (dependencia) {
|
||||
// formData.append("alumno[dependencia]", dependencia);
|
||||
// }
|
||||
|
||||
if (motivo) {
|
||||
formData.append("alumno[motivo]", motivo);
|
||||
}
|
||||
// if (motivo) {
|
||||
// formData.append("alumno[motivo]", motivo);
|
||||
// }
|
||||
|
||||
if (!idStatus) {
|
||||
console.log('No se envio el idStatus')
|
||||
}
|
||||
// if (!idStatus) {
|
||||
// console.log('No se envio el idStatus')
|
||||
// }
|
||||
|
||||
//const info = formData.append('alumno', new Blob([JSON.stringify(data)], { type: 'application/json' }));
|
||||
// formData.append('archivos', file);
|
||||
@@ -242,6 +265,7 @@ export default function CasoEspecialForm({
|
||||
// formData.append("alumno[direccion]", alumno.direccion);
|
||||
|
||||
console.log("FormData a enviar en caso especial:", formData.getAll);
|
||||
console.log("Esta es la info al registrar el servicio", formData);
|
||||
|
||||
try {
|
||||
updateIsLoading(true);
|
||||
@@ -255,31 +279,45 @@ export default function CasoEspecialForm({
|
||||
});
|
||||
resetear();
|
||||
setNumeroCuenta('');
|
||||
const mensaje = res?.data?.message || 'Se creo el servicio social con exito.'
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Exito',
|
||||
text: mensaje,
|
||||
})
|
||||
imprimirMensaje(res.data.message);
|
||||
} catch (err: unknown) {
|
||||
const axiosErr = err as AxiosError<any>;
|
||||
const mensaje = axiosErr?.response?.data?.message || 'No se pudo completar el registro del servicio social, por favor intentelo mas tarde.'
|
||||
|
||||
Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Error',
|
||||
text: mensaje,
|
||||
})
|
||||
// Quitar esta parte
|
||||
if (axios.isAxiosError(err)) {
|
||||
// if (axios.isAxiosError(err)) {
|
||||
|
||||
const backendMessage = err.response?.data?.message;
|
||||
// const backendMessage = err.response?.data?.message;
|
||||
|
||||
if (backendMessage) {
|
||||
// if (backendMessage) {
|
||||
|
||||
// Si el backend manda string
|
||||
if (typeof backendMessage === "string") {
|
||||
imprimirError({ message: backendMessage });
|
||||
return;
|
||||
}
|
||||
// // Si el backend manda string
|
||||
// if (typeof backendMessage === "string") {
|
||||
// imprimirError({ message: backendMessage });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Si el backend manda arreglo (NestJS validation)
|
||||
if (Array.isArray(backendMessage)) {
|
||||
imprimirError({ message: backendMessage.join("\n") });
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// // Si el backend manda arreglo (NestJS validation)
|
||||
// if (Array.isArray(backendMessage)) {
|
||||
// imprimirError({ message: backendMessage.join("\n") });
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// Fallback SOLO si no vino nada del backend
|
||||
imprimirError({ message: "Error inesperado del servidor" });
|
||||
// imprimirError({ message: "Error inesperado del servidor" });
|
||||
// let msg: { message: string } = { message: 'Error al enviar formulario.' };
|
||||
// if (typeof err === 'object' && err !== null && 'response' in err) {
|
||||
// const anyErr = err as { response?: { data?: unknown } };
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
'use client'
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
|
||||
@@ -158,12 +158,18 @@ export default function CuestionarioResponsbale2({
|
||||
else answered = answer !== null && String(answer) !== '';
|
||||
if (!answered) missing.push(`Pregunta ${p.numeroPregunta}`);
|
||||
});
|
||||
formulario.tablas.forEach((t) => {
|
||||
|
||||
let tablaIndex = 0;
|
||||
|
||||
formulario.tablas.forEach((t, index) => {
|
||||
const allAnswered = t.renglones.every((r) => {
|
||||
const tablaResp = respuestas[String(t.idTabla)] as Record<number, string | null> | undefined;
|
||||
return tablaResp && tablaResp[r.idRenglon] !== null;
|
||||
});
|
||||
if (!allAnswered) missing.push(`Tabla ${t.numeroPregunta}`);
|
||||
if (!allAnswered) {
|
||||
const letra = String.fromCharCode(65 + index);
|
||||
missing.push(`Tabla ${t.numeroPregunta}.${letra}`);
|
||||
}
|
||||
});
|
||||
return missing;
|
||||
}, [formulario, respuestas]);
|
||||
|
||||
Reference in New Issue
Block a user