diff --git a/src/app/administrador/casos_especiales/caso_especial/editar/page.tsx b/src/app/administrador/casos_especiales/caso_especial/editar/page.tsx new file mode 100644 index 0000000..9a7128f --- /dev/null +++ b/src/app/administrador/casos_especiales/caso_especial/editar/page.tsx @@ -0,0 +1,127 @@ +'use client' +import EditarAlumno from "@/components/administrador/editar-caso-especial"; +import BotonRegresar from "@/components/boton-regresar"; +import { getUserCasoEspecial } from "@/services/userCasoE.services"; +import { CasoEspecial } from "@/types/responses"; +import { AxiosError, isAxiosError } from "axios"; +import { useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; +import Swal from "sweetalert2"; + +interface Admin { + idTipoUsuario: number; + tipoUsuario?: string; + token: string; +} + +export default function EditarCasoEspecial() { + const [idCasoEspecial, setIdCasoEspecial] = useState(null); + const [isLoading, setIsLoading] = useState(false); + const [casoEspecial, setCasoEspecial] = useState({}); + const [datos, setDatos] = useState({}); // es de casoEspecial + const router = useRouter(); + + const getLocalInfo = () => { + const storedAdmin: Admin = { + idTipoUsuario: Number(localStorage.getItem('idTipoUsuario')), + tipoUsuario: localStorage.getItem('tipoUsuario') || undefined, + token: localStorage.getItem('token') || '', + } + + setCasoEspecial(storedAdmin); + + const storageIdCaso = Number(localStorage.getItem('idCasoEspecial')); + setIdCasoEspecial(storageIdCaso); + } + + + const imprimirError = (err: unknown = {}, title = '¡Hubo un error!', onConfirm = () => {}) => { + let message = 'Ocurrió un error'; + if (typeof err === 'string') message = err; + else if (err instanceof Error) message = err.message; + else if (isAxiosError(err) && err.response?.data?.message) message = String(err.response.data.message); + + Swal.fire({ + title, + text: message, + icon: 'error', + confirmButtonText: 'Entendido', + }).then(() => onConfirm()); + + try { + const anyErr = err as { err?: string }; + if (anyErr.err === 'token error') { + localStorage.clear(); + router.replace('/'); + } + } catch (_) {} + }; + + const imprimirMensaje = (message: string, title = '¡Felicidades!', onConfirm = () => {}) => { + Swal.fire({ + title, + text: message, + icon: 'success', + confirmButtonText: 'Ok', + }).then(() => onConfirm()); + }; + + const imprimirWarning = ( + message: string, + onConfirm = () => {}, + title = '¡Espera un minuto!', + onCancel = () => {} + ) => { + Swal.fire({ + title, + text: message, + icon: 'warning', + showCancelButton: true, + confirmButtonText: 'Confirmar', + cancelButtonText: 'Cancelar', + }).then((result) => { + if (result.isConfirmed) onConfirm(); + else onCancel(); + }); + }; + + const updateIsLoading = (value: boolean) => setIsLoading(value); + + useEffect(() => { + const fetchUser = async () => { + await getLocalInfo(); + + if (!idCasoEspecial) return + + try { + setIsLoading(true); + const data = await getUserCasoEspecial(idCasoEspecial) + + setDatos(data); + } catch (error) { + const axiosErr = error as AxiosError; + const mensaje = axiosErr?.response?.data?.message || 'No se pudo obtener la infromacion del caso especial.' + Swal.fire({ + title: 'Error', + icon: 'error', + text: mensaje, + }) + } + } + }, []) + + return ( +
+ + +
+ ) +} \ No newline at end of file diff --git a/src/app/administrador/casos_especiales/caso_especial/page.tsx b/src/app/administrador/casos_especiales/caso_especial/page.tsx index 49803ce..ebf6dad 100644 --- a/src/app/administrador/casos_especiales/caso_especial/page.tsx +++ b/src/app/administrador/casos_especiales/caso_especial/page.tsx @@ -79,7 +79,7 @@ export default function CasoEspecialPage() { title = '¡Espera un minuto!', onCancel = () => {} ) => { - MySwal.fire({ + Swal.fire({ title, text: message, icon: 'warning', diff --git a/src/app/casoEspecial/nuevo/page.tsx b/src/app/casoEspecial/nuevo/page.tsx index 1c9fa9c..b03ecb7 100644 --- a/src/app/casoEspecial/nuevo/page.tsx +++ b/src/app/casoEspecial/nuevo/page.tsx @@ -2,6 +2,7 @@ import BotonRegresar from "@/components/boton-regresar"; import CasoEspecialForm from "@/components/casoEspecial/caso-especial-form"; import { useState } from "react"; +import Swal from "sweetalert2"; export default function Nuevo() { const [isLoading, setIsLoading] = useState(false); @@ -17,10 +18,24 @@ export default function Nuevo() { alert(`${message}`); } - const imprimirWarning = (message: string, onConfirm: () => void) => { - if (confirm(`${message}\n¿Desea continuar?`)) { - onConfirm(); - } + const imprimirWarning = (message: string, onConfirm: () => void, title: string) => { + Swal.fire({ + title, + text: message, + icon: "warning", + showCancelButton: true, + confirmButtonText: 'confirmar', + cancelButtonText: 'cancelar', + confirmButtonColor: "#0d6efd", + cancelButtonColor: "#dc3545", + }).then((result) => { + if (result.isConfirmed) { + onConfirm(); + } + }) + // if (confirm(`${message}\n¿Desea continuar?`)) { + // onConfirm(); + // } } const updateIsLoading = (value: boolean) => { diff --git a/src/components/administrador/editar-caso-especial.tsx b/src/components/administrador/editar-caso-especial.tsx index 1039d77..a0a35e3 100644 --- a/src/components/administrador/editar-caso-especial.tsx +++ b/src/components/administrador/editar-caso-especial.tsx @@ -1,6 +1,6 @@ "use client"; -import { useState, useMemo } from "react"; +import { useState, useMemo, useEffect } from "react"; import { axiosInstance } from "@/api/config"; import { isAxiosError } from "axios"; import moment from "moment"; @@ -10,6 +10,8 @@ import "react-datepicker/dist/react-datepicker.css"; import { useRouter } from "next/navigation"; import { registerLocale } from "react-datepicker"; import { es } from "date-fns/locale/es"; +import { Col, FormGroup, FormLabel, InputGroup } from "react-bootstrap"; +import { FaRegCalendar } from "react-icons/fa6"; registerLocale("es", es); @@ -26,7 +28,9 @@ interface Viejo { } interface Admin { - token: { headers: Record }; + idTipoUsuario: number; + tipoUsuario?: string; + token: string; } interface Props { @@ -103,7 +107,7 @@ export default function EditarAlumno({ try { updateIsLoading(true); - const res = await axiosInstance.put(`/caso_especial/update`, data, admin.token); + const res = await axiosInstance.put(`/caso_especial/update/${idCasoEspecial}`, data); imprimirMensaje(res.data.message); router.push("/admin/casos_especiales/caso_especial"); } catch (err: unknown) { @@ -121,60 +125,127 @@ export default function EditarAlumno({ return (
-

Editar información del alumno

+

Editar información del alumno

{/* Correo */} -
- +
+ setNuevo({ ...nuevo, correo: e.target.value })} - className="border rounded p-2 w-full" + className="form-control border rounded p-2 w-full" />
{/* Teléfono */} -
- +
+ setNuevo({ ...nuevo, telefono: e.target.value })} - className="border rounded p-2 w-full" + className="form-control border rounded p-2 w-full" />
{/* Dirección */} -
- +
+ setNuevo({ ...nuevo, direccion: e.target.value })} - className="border rounded p-2 w-full" + className="form-control border rounded p-2 w-full" />
+ + + + Fecha de inicio + + + + + + setNuevo({ ...nuevo, fechaInicio: date || undefined })} + minDate={minDate1} + placeholderText={fecha(viejo.fechaInicio)} + className="form-control" + wrapperClassName="flex-grow-1" + calendarClassName="mi-calendario" + + showMonthDropdown + showYearDropdown + scrollableYearDropdown + yearDropdownItemNumber={60} + dropdownMode="select" + + locale="es" + /> + + + + {/* Fecha inicio */} -
- + {/*
+ setNuevo({ ...nuevo, fechaInicio: date || undefined })} - minDate={minDate1} - placeholderText={fecha(viejo.fechaInicio)} - className="border rounded p-2 w-full" + selected={nuevo.fechaInicio} + onChange={(date) => setNuevo({ ...nuevo, fechaInicio: date || undefined })} + minDate={minDate1} + placeholderText={fecha(viejo.fechaInicio)} + className="form-control" + wrapperClassName="flex-grow-1" + calendarClassName="mi-calendario" - locale="es" + showMonthDropdown + showYearDropdown + scrollableYearDropdown + yearDropdownItemNumber={60} + dropdownMode="select" + + locale="es" /> -
+
*/} - {/* Fecha fin */} + + + Fecha de fin + + + + + setNuevo({ ...nuevo, fechaFin: date || undefined })} + minDate={minDate2} + placeholderText={fecha(viejo.fechaFin)} + dateFormat={'dd-MM-yyyy'} + className="form-control" + wrapperClassName="flex-grow-1" + calendarClassName="mi-calendario" + + showMonthDropdown + showYearDropdown + scrollableYearDropdown + yearDropdownItemNumber={60} + dropdownMode="select" + + locale='es' + /> + + + + + {/* Fecha fin {nuevo.fechaInicio && (
@@ -188,29 +259,57 @@ export default function EditarAlumno({ locale='es' />
- )} + )} */} + + + + Fecha de nacimiento + + + + + setNuevo({ ...nuevo, fechaNacimiento: date || undefined })} + placeholderText={fecha(viejo.fechaNacimiento)} + dateFormat={'dd-MM-yyyy'} + className="form-control" + wrapperClassName="flex-grow-1" + calendarClassName="mi-calendario" + + showMonthDropdown + showYearDropdown + scrollableYearDropdown + yearDropdownItemNumber={60} + dropdownMode="select" + + locale='es' + /> + + + {/* Fecha nacimiento */} -
+ {/*
setNuevo({ ...nuevo, fechaNacimiento: date || undefined })} placeholderText={fecha(viejo.fechaNacimiento)} - className="border rounded p-2 w-full" + className="form-control border rounded p-2 w-full" locale='es' /> -
+
*/} {/* Motivo */} {viejo.motivo && ( -
- +
+ setNuevo({ ...nuevo, dependencia: e.target.value })} - className="border rounded p-2 w-full" + className="form-control border rounded p-2 w-full" />
)} {/* Institución */} {viejo.institucion && ( -
- +
+ setNuevo({ ...nuevo, institucion: e.target.value })} - className="border rounded p-2 w-full" + className="form-control border rounded p-2 w-full" />
)} diff --git a/src/components/administrador/liberar-caso-especial.tsx b/src/components/administrador/liberar-caso-especial.tsx index febd051..068d8c4 100644 --- a/src/components/administrador/liberar-caso-especial.tsx +++ b/src/components/administrador/liberar-caso-especial.tsx @@ -27,7 +27,7 @@ export default function LiberarCasoEspecial({ try { updateIsLoading(true); - const res = await axiosInstance.put(`/caso_especial/liberaciony${idCasoEspecial}`, data); + const res = await axiosInstance.put(`/caso-especial/liberaciony/${idCasoEspecial}`, data); imprimirMensaje(res.data.message); router.replace('/administrador/casos_especiales'); } catch (err: unknown) { diff --git a/src/components/casoEspecial/caso-especial-form.tsx b/src/components/casoEspecial/caso-especial-form.tsx index 3f76869..9b8ef50 100644 --- a/src/components/casoEspecial/caso-especial-form.tsx +++ b/src/components/casoEspecial/caso-especial-form.tsx @@ -42,7 +42,7 @@ interface Props { // responsable: Responsable; imprimirError: (msg: { message: string }) => void; imprimirMensaje: (msg: string) => void; - imprimirWarning: (msg: string, callback: () => void) => void; + imprimirWarning: (msg: string, callback: () => void, title: string) => void; updateIsLoading: (value: boolean) => void; } @@ -139,6 +139,7 @@ export default function CasoEspecialForm({ updateIsLoading(true); const res = await axiosInstance.post(`/usuario/escolares/${numeroCuenta}`); resetear(); + console.log('Esta es la res:' , res) setAlumno(res.data); } catch (err: unknown) { resetear(); @@ -377,6 +378,12 @@ export default function CasoEspecialForm({ updateFechas(); }, []); + const confirmarCasoEspecial = () => { + Swal.fire({ + + }) + } + // Render return ( @@ -682,9 +689,9 @@ export default function CasoEspecialForm({ onClick={() => imprimirWarning( '¿Estás seguro(a) de querer crear un nuevo caso especial?', - enviar - ) - } + enviar, + 'Aviso' + )} > Enviar diff --git a/src/services/userCasoE.services.ts b/src/services/userCasoE.services.ts new file mode 100644 index 0000000..6341b5b --- /dev/null +++ b/src/services/userCasoE.services.ts @@ -0,0 +1,8 @@ +import { axiosInstance } from "@/api/config" +import { CasoEspecial } from "@/types/responses" + +export const getUserCasoEspecial = async (idCasoEspecial: number): Promise => { + const res = await axiosInstance.get(`caso-especial/caso_especial/${idCasoEspecial}`) + + return res.data +} \ No newline at end of file diff --git a/src/types/responses.d.ts b/src/types/responses.d.ts index cc46c25..b44d7fd 100644 --- a/src/types/responses.d.ts +++ b/src/types/responses.d.ts @@ -57,4 +57,17 @@ export interface Responsables { interface ServicioSocialConCasoEspecial extends ServicioSocialResponse { idCasoEspecial?: number; +} + +interface CasoEspecial { + idCasoEspecial: number; + correo?: string; + telefono?: string; + direccion?: string; + fechaInicio?: Date; + fechaFin?: Date; + fechaNacimiento?: Date; + motivo?: string; + dependencia?: string; + institucion?: string; } \ No newline at end of file