Modificaciones en los mensajes de alerta

This commit is contained in:
santiago
2026-01-15 11:22:20 -06:00
parent 44f9486f45
commit ea5b94f48b
14 changed files with 250 additions and 68 deletions
+18 -4
View File
@@ -19,8 +19,9 @@
"react-dom": "19.1.0",
"react-hot-toast": "^2.6.0",
"react-icons": "^5.5.0",
"react-toastify": "^11.0.5",
"sass": "^1.95.0",
"sweetalert2": "^11.26.2",
"sweetalert2": "^11.26.17",
"sweetalert2-react-content": "^5.1.0",
"validator": "^13.15.15"
},
@@ -5152,6 +5153,19 @@
"integrity": "sha512-fBASbA6LnOU9dOU2eW7aQ8xmYBSXUIWr+UmF9b1efZBazGNO+rcXT/icdKnYm2pTwcRylVUYwW7H1PHfLekVzA==",
"license": "MIT"
},
"node_modules/react-toastify": {
"version": "11.0.5",
"resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-11.0.5.tgz",
"integrity": "sha512-EpqHBGvnSTtHYhCPLxML05NLY2ZX0JURbAdNYa6BUkk+amz4wbKBQvoKQAB0ardvSarUBuY4Q4s1sluAzZwkmA==",
"license": "MIT",
"dependencies": {
"clsx": "^2.1.1"
},
"peerDependencies": {
"react": "^18 || ^19",
"react-dom": "^18 || ^19"
}
},
"node_modules/react-transition-group": {
"version": "4.4.5",
"resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz",
@@ -5815,9 +5829,9 @@
}
},
"node_modules/sweetalert2": {
"version": "11.26.4",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.26.4.tgz",
"integrity": "sha512-qIgIQOVoz85Xj2Rij+htVFNH+HiIgfSR8ZJsHQvX4p9uLtJveXVqU7vPxJ4Eo6SALnLeo0Sw6COY164Zg3oBiw==",
"version": "11.26.17",
"resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-11.26.17.tgz",
"integrity": "sha512-kkaySn1IRfwNlf9AkZVqDmBINDWw9NRR6Ij0O5dBRBOD1+mbtZJWxxR9/pA90nce9E5tIIkJ7SWij4rMWXtA1g==",
"license": "MIT",
"peer": true,
"funding": {
+2 -1
View File
@@ -20,8 +20,9 @@
"react-dom": "19.1.0",
"react-hot-toast": "^2.6.0",
"react-icons": "^5.5.0",
"react-toastify": "^11.0.5",
"sass": "^1.95.0",
"sweetalert2": "^11.26.2",
"sweetalert2": "^11.26.17",
"sweetalert2-react-content": "^5.1.0",
"validator": "^13.15.15"
},
+2
View File
@@ -5,6 +5,7 @@ import Footer from "@/components/layout/footer";
import "@/sass/bootstrap.scss"
import { Metadata } from 'next';
import { ToastContainer } from 'react-toastify';
export const metadata: Metadata = {
title: 'IRIS Test',
@@ -25,6 +26,7 @@ export default function RootLayout({
<Header />
<main className="flex-grow-1 bg-light">
{children}
{/* <ToastContainer position="top-right" autoClose={3000} /> */}
</main>
<Footer />
</body>
+5
View File
@@ -3,6 +3,8 @@ import { axiosInstance } from "@/api/config";
import Image from "next/image";
import { useRouter } from "next/navigation";
import React, { useState } from "react";
import { toast } from "react-toastify";
import Swal from "sweetalert2";
export default function Home() {
const [showPassword, setShowPassword] = useState(false);
@@ -74,6 +76,9 @@ export default function Home() {
console.error('Error: datos de usuario incompletos');
}
} catch (error) {
Swal.fire("Error", "No se agrego el usuario o la contraseña correcta", "error");
// toast.error("Usuario o contraseña estan mal")
//alert("Usuario o password mal")
console.error('Error en el inicio de sesión:', error);
//localStorage.clear();
}
+15 -2
View File
@@ -6,6 +6,7 @@ import React, { useState } from "react";
import { Button, Form } from "react-bootstrap";
import { FaUpload } from "react-icons/fa";
import { ImDownload } from "react-icons/im";
import Swal from "sweetalert2";
export default function CargaMasiva({datos}: {datos: CargaMasivaProps}) {
const router = useRouter();
@@ -61,11 +62,23 @@ export default function CargaMasiva({datos}: {datos: CargaMasivaProps}) {
console.log('Respuesta de carga masiva:', res.data)
//updateIsLoading(false)
//ImprimirMensaje(res.data.message)
alert("Se subio la carga masiva correctamente.");
router.push("/administrador/responsables")
Swal.fire({
title: 'Archivo enviado',
text: 'El archivo se subió correctamente',
icon: 'success',
});
setCsv(null);
//alert("Se subio la carga masiva correctamente.");
//router.push("/administrador/responsables")
} catch (error) {
//updateIsLoading(false)
//imprimirError(error.response.data || error)
Swal.fire({
title: 'Error al enviar el archivo',
text: 'No se pudo subir el archivo',
icon: 'error',
})
setCsv(null)
console.log('Error en carga masiva:', error)
}
}
+15 -1
View File
@@ -3,6 +3,7 @@ import { axiosInstance } from "@/api/config";
import { error } from "console";
import { useState } from "react";
import { Button, Col, FormGroup, FormLabel, FormSelect, InputGroup } from "react-bootstrap";
import Swal from "sweetalert2";
interface Props {
years: number[];
@@ -48,12 +49,25 @@ export default function Cuestionario({ years, admin, updateIsLoading }: Props) {
link.remove();
window.URL.revokeObjectURL(url);
Swal.fire({
title: 'Exito',
text: 'Se descargo el cuestionario exitosamente.',
icon: 'success',
})
// reset
setSelectedYear("");
setSelectedCuestionario("");
setVersion("");
//updateIsLoading(false);
} catch (err: unknown) {
} catch (err) {
Swal.fire({
title: 'Error',
text: 'Error al descargar el cuestionario.',
icon: 'error',
})
console.error("Error en descargar el formulario", err)
//updateIsLoading(false);
// optional: handle error, e.g. console.error(err)
@@ -5,6 +5,7 @@ import { axiosInstance } from "@/api/config";
import { isAxiosError } from "axios";
import validator from "validator";
import { useRouter } from "next/navigation";
import Swal from "sweetalert2";
interface Responsable {
idUsuario?: number;
@@ -57,6 +58,39 @@ export default function EditarResponsable({
return true;
};
// Funcion para confirmar actualizacion
const confirmarActualizacion = () => {
Swal.fire({
title: '¿Seguro(a) que quiere actualizar la información de este usuario?',
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sí, actualizar",
cancelButtonText: "Cancelar",
confirmButtonColor: "#0d6efd",
cancelButtonColor: "#dc3545",
}).then((result) => {
if (result.isConfirmed) {
actualizar(); // 👈 aquí ejecutas la función
}
});
};
const confirmarCambioPassword = () => {
Swal.fire({
title: '¿Seguro(a) que quiere cambiar la contraseña para este usuario?',
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sí, actualizar",
cancelButtonText: "Cancelar",
confirmButtonColor: "#0d6efd",
cancelButtonColor: "#dc3545",
}).then((result) => {
if (result.isConfirmed) {
password(); // 👈 aquí ejecutas la función
}
});
}
// Actualizar información del responsable
const actualizar = async () => {
@@ -75,17 +109,29 @@ export default function EditarResponsable({
try {
updateIsLoading(true);
const res = await axiosInstance.patch(`/usuario/responsable/${idResponsable}`, data);
imprimirMensaje(res.data.message);
Swal.fire({
title: 'Exito',
text: 'Se actualizaron los datos correctamente',
icon: 'success',
})
//imprimirMensaje(res.data.message);
router.replace("/administrador/responsables/responsable");
} catch (err: unknown) {
let msg: unknown = err;
if (isAxiosError(err) && err.response?.data) {
console.error("ERROR DEL SERVER:", err.response.data);
msg = JSON.stringify(err.response.data, null, 2);
} else if (err instanceof Error) {
msg = err.message;
}
imprimirError(msg);
} catch (err) {
Swal.fire({
title: 'Error',
text: 'Error al actualizar los datos',
icon: 'error',
})
// let msg: unknown = err;
// if (isAxiosError(err) && err.response?.data) {
// console.error("ERROR DEL SERVER:", err.response.data);
// msg = JSON.stringify(err.response.data, null, 2);
// } else if (err instanceof Error) {
// msg = err.message;
// }
// imprimirError(msg);
} finally {
updateIsLoading(false);
}
@@ -102,18 +148,32 @@ export default function EditarResponsable({
try {
updateIsLoading(true);
const res = await axiosInstance.post(`/usuario/new-password-responsable/${idResponsable}`);
imprimirMensaje(res.data.message);
Swal.fire({
title: 'Exito',
text: 'Se envio la nueva contraseña al responsable',
icon: 'success',
})
//imprimirMensaje(res.data.message);
router.replace("/administrador/responsables/responsable");
} catch (err: unknown) {
let msg: unknown = err;
if (isAxiosError(err) && err.response?.data) {
msg = err.response.data;
} else if (err instanceof Error) {
msg = err.message;
}
imprimirError(msg);
} catch (err) {
Swal.fire({
title: 'Error',
text: 'Error al actualizar la contraseña del responsable',
icon: 'error',
})
// let msg: unknown = err;
// if (isAxiosError(err) && err.response?.data) {
// msg = err.response.data;
// } else if (err instanceof Error) {
// msg = err.message;
// }
// imprimirError(msg);
} finally {
updateIsLoading(false);
updateIsLoading(false);
}
};
@@ -152,12 +212,7 @@ export default function EditarResponsable({
<div className="pt-5 flex gap-4">
<button
disabled={mostrarBoton()}
onClick={() =>
imprimirWarning(
"¿Seguro(a) que quiere actualizar la información de este usuario?",
actualizar
)
}
onClick={confirmarActualizacion}
className={`mb-4 px-4 py-2 rounded text-white ${
mostrarBoton() ? "bg-gray-400 cursor-not-allowed" : "bg-blue-600 hover:bg-blue-700"
}`}
@@ -166,12 +221,7 @@ export default function EditarResponsable({
</button>
<button
onClick={() =>
imprimirWarning(
"¿Seguro(a) que quiere cambiar la contraseña para este usuario?",
password
)
}
onClick={confirmarCambioPassword}
className="ms-3 px-4 py-2 rounded bg-morado hover:bg-blue-600 text-white"
>
Cambiar contraseña
@@ -3,6 +3,7 @@ import { useState } from "react";
import { Col, FormGroup, FormLabel, FormSelect, InputGroup, Button } from "react-bootstrap";
import { axiosInstance } from "@/api/config"; // tu config de axios
import { isAxiosError } from 'axios';
import Swal from "sweetalert2";
//import fileDownload from "js-file-download";
interface Props {
@@ -52,15 +53,28 @@ export default function GustavoBazPrada({
link.remove();
window.URL.revokeObjectURL(url);
Swal.fire({
title: 'Exito',
text: 'Se descargo el archivo correctamente.',
icon: 'success',
})
//fileDownload(res.data, `${selectedYear}_gustavo_baz_prada.csv`);
setSelectedYear("");
updateIsLoading?.(false);
} catch (err: unknown) {
Swal.fire({
title: 'Error',
text: 'No se pudo completar la descarga.',
icon: 'error',
})
updateIsLoading?.(false);
if (isAxiosError(err)) imprimirError?.(String(err.response?.data) || err.message || 'Error al descargar');
else if (err instanceof Error) imprimirError?.(err.message);
else imprimirError?.('Error al descargar');
// if (isAxiosError(err)) imprimirError?.(String(err.response?.data) || err.message || 'Error al descargar');
// else if (err instanceof Error) imprimirError?.(err.message);
// else imprimirError?.('Error al descargar');
}
};
@@ -4,6 +4,7 @@ import { useState } from "react";
import { axiosInstance } from "@/api/config";
import { isAxiosError } from 'axios';
import { useRouter } from "next/navigation";
import Swal from "sweetalert2";
interface Props {
//admin: { token: { headers: { token: string } } };
@@ -35,6 +36,22 @@ export default function ReasignacionProgramas({
);
};
const confirmarActualizacion = () => {
Swal.fire({
title: `¿Seguro(a) que quiere eliminar a ${correoOtroResponsable} y pasar todos los programas a ${responsable.usuario}?`,
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sí, actualizar",
cancelButtonText: "Cancelar",
confirmButtonColor: "#0d6efd",
cancelButtonColor: "#dc3545",
}).then((result) => {
if (result.isConfirmed) {
reasignarProgramas(); // 👈 aquí ejecutas la función
}
});
};
// Función principal: reasignar programas
const reasignarProgramas = async () => {
const data = {
@@ -93,12 +110,7 @@ export default function ReasignacionProgramas({
: "bg-blue-600 hover:bg-blue-700"
}`}
disabled={mostrarBoton()}
onClick={() =>
imprimirWarning(
`¿Seguro(a) que quiere eliminar a ${correoOtroResponsable} y pasar todos los programas a ${responsable.usuario}?`,
reasignarProgramas
)
}
onClick={confirmarActualizacion}
>
Reasignar
</button>
+13
View File
@@ -5,6 +5,7 @@ import { Button, Col, FormGroup, FormLabel, InputGroup, Row } from "react-bootst
import DatePicker from "react-datepicker";
import moment from "moment";
import { FaCalendarAlt, FaRegCalendarAlt } from "react-icons/fa";
import Swal from "sweetalert2";
//import { saveAs } from "file-saver";
interface Props {
@@ -64,6 +65,12 @@ export default function Reporte({ admin }: Props) {
link.remove()
window.URL.revokeObjectURL(url)
Swal.fire({
title: 'Exito',
text: 'Se descargo el reporte exitosamente.',
icon: 'success',
})
//saveAs(res.data, "reporte.csv");
// reset
@@ -71,6 +78,12 @@ export default function Reporte({ admin }: Props) {
setSelectedFin(null);
//updateIsLoading(false);
} catch (err: unknown) {
Swal.fire({
title: 'Error',
text: 'No se pudo descargar el reporte.',
icon: 'error',
})
console.log("Error al descargar el reporte", err)
//updateIsLoading(false);
// optional: handle error
+3
View File
@@ -5,6 +5,7 @@ import { axiosInstance } from "@/api/config";
import axios, { isAxiosError } from 'axios';
import { Button, FormGroup, FormLabel } from "react-bootstrap";
import { FaUpload } from "react-icons/fa";
import { useRouter } from "next/navigation";
interface Alumno {
tokenAlumno: string;
@@ -39,6 +40,7 @@ export default function PreTermino({
updateIsLoading,
}: Props) {
const [file, setFile] = useState<File | null>(null);
const router = useRouter();
useEffect(() => {
console.log("Esta es la informacion que se le pasa verificacion cuestionario alumno", servicio)
@@ -73,6 +75,7 @@ export default function PreTermino({
imprimirMensaje(res.data.message);
obtenerServicio();
setFile(null);
router.refresh(); // Para recargar la pagina y valide si tiene el informe.
} catch (err: unknown) {
if (isAxiosError(err)) {
imprimirError((err.response?.data) || err.message);
@@ -4,6 +4,7 @@ import React, { useEffect, useMemo, useState } from "react";
import { axiosInstance } from "@/api/config";
import { routerServerGlobal } from "next/dist/server/lib/router-utils/router-server-context";
import { useRouter } from "next/navigation";
import Swal from "sweetalert2";
type Responsable = { token?: string };
@@ -282,18 +283,30 @@ export default function CuestionarioResponsbale2({
const headers = responsable?.token ? { Authorization: `Bearer ${responsable.token}` } : undefined;
await axiosInstance.post('/cuestionario-programa2', data, { headers });
imprimirMensaje('Se enviaron los datos correctamente');
try { localStorage.removeItem('idCuestionarioAlumno'); } catch (_) {}
Swal.fire({
title: 'Exito',
text: 'Se subio el cuestionario correctamente.',
icon: 'success',
})
//imprimirMensaje('Se enviaron los datos correctamente');
// try { localStorage.removeItem('idCuestionarioAlumno'); } catch (_) {}
if (typeof window !== 'undefined') router.replace('/responsable'); //window.location.href = '/responsable';
} catch (err: unknown) {
if (typeof err === 'object' && err !== null && 'response' in err) {
const anyErr = err as { response?: { data?: { message?: unknown } } };
imprimirError(String(anyErr.response?.data?.message) || 'Error al enviar el formulario');
} else if (err instanceof Error) {
imprimirError(err.message);
} else {
imprimirError('Error al enviar el formulario');
}
} catch (err) {
Swal.fire({
title: 'Error',
text: 'No se pudo enviar el cuestionario.',
icon: 'error',
})
// if (typeof err === 'object' && err !== null && 'response' in err) {
// const anyErr = err as { response?: { data?: { message?: unknown } } };
// imprimirError(String(anyErr.response?.data?.message) || 'Error al enviar el formulario');
// } else if (err instanceof Error) {
// imprimirError(err.message);
// } else {
// imprimirError('Error al enviar el formulario');
// }
} finally {
updateIsLoading(false);
setIsLoading(false);
+35 -7
View File
@@ -7,6 +7,7 @@ import { Form } from "react-bootstrap";
import { FaUpload } from "react-icons/fa";
import { useRouter } from "next/navigation";
import axios from "axios";
import Swal from "sweetalert2";
type Responsable = { tokenArchivo?: string };
@@ -39,6 +40,22 @@ export default function UploadArchivo({
console.log("Responsable en upload archivo:", responsable);
const confirmarEnvioArchivo = () => {
Swal.fire({
title: `¿Estas seguro(a) de querer subir esta carta de ${tipoCarta}?`,
icon: "warning",
showCancelButton: true,
confirmButtonText: "Sí, actualizar",
cancelButtonText: "Cancelar",
confirmButtonColor: "#0d6efd",
cancelButtonColor: "#dc3545",
}).then((result) => {
if (result.isConfirmed) {
subir(); // 👈 aquí ejecutas la función
}
});
};
const subir = async () => {
if (!file) return;
const formData = new FormData();
@@ -59,15 +76,26 @@ export default function UploadArchivo({
});
try { localStorage.removeItem('idServicio'); }
catch (error) {}
updateIsLoading(false);
imprimirMensaje(res.data?.message || 'Archivo subido');
Swal.fire({
title: 'Exito',
text: 'Se subio el archivo correctamente',
icon: 'success',
})
//imprimirMensaje(res.data?.message || 'Archivo subido');
if (typeof window !== 'undefined') router.replace('/responsable') //window.location.href = '/responsable';
} catch (err: unknown) {
} catch (err) {
Swal.fire({
title: 'Error',
text: 'Error al enviar el archivo',
icon: 'error',
})
updateIsLoading(false);
const axiosErr = err as AxiosError;
if (axiosErr?.response?.data) imprimirError(axiosErr.response.data as object);
else if (err instanceof Error) imprimirError(err.message);
else imprimirError({ message: 'Error desconocido' });
// const axiosErr = err as AxiosError;
// if (axiosErr?.response?.data) imprimirError(axiosErr.response.data as object);
// else if (err instanceof Error) imprimirError(err.message);
// else imprimirError({ message: 'Error desconocido' });
}
};
@@ -124,7 +152,7 @@ export default function UploadArchivo({
</div>
<div className="text-center my-4">
<button className="btn btn-success" disabled={!file?.name} onClick={() => imprimirWarning(`¿Estas seguro(a) de querer subir esta carta de ${tipoCarta}?`, subir)}>
<button className="btn btn-success" disabled={!file?.name} onClick={confirmarEnvioArchivo}>
Enviar
</button>
</div>
+1 -1
View File
@@ -15,7 +15,7 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{