From fa411806171d12591b76fa567553c74a62066d0a Mon Sep 17 00:00:00 2001 From: yoelmarain Date: Sun, 13 Oct 2024 21:47:36 -0300 Subject: [PATCH 1/9] Refactor API to fetch and display list of disabled students --- FrontAdmin/src/API/Inhabilitaciones.ts | 23 +++ .../Estadisticas/SubPages/Cuotas/Listado.tsx | 7 +- .../Inhabilitaciones/Inhabilitaciones.tsx | 138 ++++++++++++++++++ .../src/components/SubMenu/LinksSubMenu.tsx | 2 +- FrontAdmin/src/routes.tsx | 6 + 5 files changed, 170 insertions(+), 6 deletions(-) create mode 100644 FrontAdmin/src/API/Inhabilitaciones.ts create mode 100644 FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx diff --git a/FrontAdmin/src/API/Inhabilitaciones.ts b/FrontAdmin/src/API/Inhabilitaciones.ts new file mode 100644 index 0000000..ec89afa --- /dev/null +++ b/FrontAdmin/src/API/Inhabilitaciones.ts @@ -0,0 +1,23 @@ +import Cookies from 'js-cookie'; + +export const getInhabilitaciones = async () => { + try { + const token = Cookies.get('tokennn'); + const response = await fetch('http://localhost:8000/api/alumnos/inhabilitados', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + }); + + if (response.ok) { + const data = await response.json(); + return data; + } else { + throw new Error('Error en la respuesta del servidor'); + } + } catch (error) { + throw new Error('Network error: ' + error); + } +}; diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Cuotas/Listado.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Cuotas/Listado.tsx index 4594a7d..840063d 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Cuotas/Listado.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Cuotas/Listado.tsx @@ -40,13 +40,13 @@ export default function Listado() { const handleNextPage2 = () => { if (offset2 + limit2 < totalabonaron) { - setOffset1(offset2 + limit2); + setOffset2(offset2 + limit2); } }; const handlePreviousPage2 = () => { if (offset2 > 0) { - setOffset1(offset2 - limit2); + setOffset2(offset2 - limit2); } }; @@ -86,9 +86,6 @@ export default function Listado() { setFilter(event.target.value); }; - console.log(abonaron); - console.log(noAbonaron); - return ( ([]); + const [loading, setLoading] = useState(true); + const headers = ['Apellido y Nombre', 'Legajo' , 'DNI', 'Estado financiero']; + const [limit1] = useState(10); + const [offset1, setOffset1] = useState(0); + const [totalInhabilitados, setTotalInhabilitados] = useState(0); + + useEffect(() => { + const fetchData = async () => { + const response = await getInhabilitaciones(); + setInhabilitados(response); + setTotalInhabilitados(response.length); + setLoading(false); + }; + + fetchData(); + }, []); + + const handleNextPage = () => { + if (offset1 + limit1 < totalInhabilitados) { + setOffset1(offset1 + limit1); + } + }; + + const handlePreviousPage = () => { + if (offset1 > 0) { + setOffset1(offset1 - limit1); + } + }; + + + + return ( + + + + + Alumnos a Habilitar + + + Alumnos Inhabilitados + + + + + + + + + {loading ? ( + + ) : ( + + + Habilitar + + + )} + + + + + + + {loading ? ( + + ) : ( + + + Total: {totalInhabilitados} + + + + + + + Página {Math.ceil(offset1 / limit1) + 1} de {Math.ceil(totalInhabilitados / limit1)} + + + + + + )} + + + + + + + ); +} + +export default Inhabilitados; \ No newline at end of file diff --git a/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx b/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx index e620baa..f20ff32 100644 --- a/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx +++ b/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx @@ -1,5 +1,5 @@ export const ITEMS_SUBMENU = [ - { url: '#', title: 'Inhabilitaciones' }, + { url: 'inhabilitaciones', title: 'Inhabilitaciones' }, { url: '#', title: 'Baja Provisoria' }, { url: 'cuotas', title: 'Cuotas' , tooltip: 'Alumnos que abonaron/no abonaron una respectiva cuota' }, { url: 'matricula', title: 'Matricula' }, diff --git a/FrontAdmin/src/routes.tsx b/FrontAdmin/src/routes.tsx index ba93431..de9da65 100644 --- a/FrontAdmin/src/routes.tsx +++ b/FrontAdmin/src/routes.tsx @@ -31,6 +31,7 @@ import path from 'path'; import EstadoCuenta from './components/Pages-Alumnos/EstadoCuenta/EstadoCuenta'; import Sysadmin from './components/Pages/SysAdmin/SysAdmin'; import Matricula from './components/Pages/Estadisticas/SubPages/Matricula'; +import Inhabilitados from './components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones'; const routes = [ { @@ -82,6 +83,11 @@ const routes = [ element: , rol: 'admin', }, + { + path: 'inhabilitaciones', + element: , + rol: 'admin', + }, ], }, From d3abe9754a4e423c2521080d257441fddf435ccb Mon Sep 17 00:00:00 2001 From: yoelmarain Date: Sun, 13 Oct 2024 22:33:29 -0300 Subject: [PATCH 2/9] Refactor API to accept pagination and filtering parameters --- FrontAdmin/src/API/Inhabilitaciones.ts | 4 +- .../Inhabilitaciones/Inhabilitaciones.tsx | 56 ++++++++++++++----- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/FrontAdmin/src/API/Inhabilitaciones.ts b/FrontAdmin/src/API/Inhabilitaciones.ts index ec89afa..12a9eef 100644 --- a/FrontAdmin/src/API/Inhabilitaciones.ts +++ b/FrontAdmin/src/API/Inhabilitaciones.ts @@ -1,9 +1,9 @@ import Cookies from 'js-cookie'; -export const getInhabilitaciones = async () => { +export const getInhabilitaciones = async (limit: number, offset: number) => { try { const token = Cookies.get('tokennn'); - const response = await fetch('http://localhost:8000/api/alumnos/inhabilitados', { + const response = await fetch(`http://localhost:8000/api/alumnos/inhabilitados?limit=${limit}&offset=${offset}` , { method: 'GET', headers: { 'Content-Type': 'application/json', diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx index da4a17e..5613f99 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx @@ -14,14 +14,14 @@ function Inhabilitados() { useEffect(() => { const fetchData = async () => { - const response = await getInhabilitaciones(); + const response = await getInhabilitaciones(limit1, offset1); setInhabilitados(response); setTotalInhabilitados(response.length); setLoading(false); }; fetchData(); - }, []); + }, [limit1, offset1]); const handleNextPage = () => { if (offset1 + limit1 < totalInhabilitados) { @@ -57,6 +57,19 @@ function Inhabilitados() { > Alumnos a Habilitar + + Alumnos a Inhabilitar + - - + {loading ? ( ) : ( + + + Inhabilitar + + + )} + + + + + + + {loading ? ( + + ) : + inhabilitados.length > 0 ? + ( - + Total: {totalInhabilitados} - + @@ -123,9 +153,9 @@ function Inhabilitados() { - + - )} + ):

No hay datos para mostrar

}
From d828893e30ceddab070c825dd72b515fb3f19a6d Mon Sep 17 00:00:00 2001 From: Miranda Ariano Date: Tue, 15 Oct 2024 13:37:27 -0300 Subject: [PATCH 3/9] feat: listado de alumnos que no abonaron matricula --- ...Alumnos-que-fimaron-compromiso-de-pago.tsx | 29 ++----------------- .../Pages/Estadisticas/SubPages/Matricula.tsx | 27 +++++++++++++++-- .../Estadisticas/SubPages/Pesta\303\261a.tsx" | 26 +++++++++++++++++ .../Estadisticas/SubPages/TablaAlumnos.tsx | 2 +- 4 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 "FrontAdmin/src/components/Pages/Estadisticas/SubPages/Pesta\303\261a.tsx" diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Alumnos-que-fimaron-compromiso-de-pago.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Alumnos-que-fimaron-compromiso-de-pago.tsx index efe224e..a813968 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Alumnos-que-fimaron-compromiso-de-pago.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Alumnos-que-fimaron-compromiso-de-pago.tsx @@ -3,6 +3,7 @@ import { Tabs, TabList, Tab, TabPanels, TabPanel } from '@chakra-ui/react'; import TablaAlumnos from './TablaAlumnos'; import { FetchFirmantes } from '../../../../API/AlumnosCompromisoPago'; import { FetchNoFirmantes } from '../../../../API/AlumnosCompromisoPago'; +import Pestaña from './Pestaña'; const AlumnosCompromisoPago: React.FC = () => { const [index, setIndex] = useState(0); // Estado para manejar la pestaña seleccionada @@ -11,32 +12,8 @@ const AlumnosCompromisoPago: React.FC = () => {
- - Firmaron - - - No firmaron - + + diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Matricula.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Matricula.tsx index eb4df8e..00d108f 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Matricula.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Matricula.tsx @@ -1,11 +1,32 @@ -import React from 'react'; +import React, { useState } from 'react'; +import { Tabs, TabList, Tab, TabPanels, TabPanel } from '@chakra-ui/react'; import TablaAlumnos from './TablaAlumnos'; import { FetchFirmantes } from '../../../../API/AlumnosCompromisoPago'; +import { FetchNoFirmantes } from '../../../../API/AlumnosCompromisoPago'; +import Pestaña from './Pestaña'; const Matricula: React.FC = () => { + const [index, setIndex] = useState(0); // Estado para manejar la pestaña seleccionada + return ( - +
+ + + + + + + + + + + + + + + +
); }; -export default Matricula; +export default Matricula; \ No newline at end of file diff --git "a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Pesta\303\261a.tsx" "b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Pesta\303\261a.tsx" new file mode 100644 index 0000000..af5c4a1 --- /dev/null +++ "b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Pesta\303\261a.tsx" @@ -0,0 +1,26 @@ +import React from 'react'; +import { Tab } from '@chakra-ui/react'; + +interface CustomTabProps { + title: string; +} + +const CustomTab: React.FC = ({ title }) => { + return ( + + {title} + + ); +}; + +export default CustomTab; diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/TablaAlumnos.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/TablaAlumnos.tsx index 68c4ad7..8f99fe8 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/TablaAlumnos.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/TablaAlumnos.tsx @@ -101,7 +101,7 @@ const TablaAlumnos: React.FC = ({ fetchFunction, title }) => - {['full_name', 'legajo', 'dni', 'estado_financiero', 'anio_ingreso'].map((field) => ( + {['APELLIDO Y NOMBRE', 'LEGAJO', 'DNI', 'ESTADO FINANCIERO', 'AÑO INGRESO'].map((field) => ( - + @@ -116,8 +139,6 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => { monto.cuatrimestre} - - - - ))} @@ -178,9 +204,14 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => { + ); }; export default NewInterfaz; - From 9f157400fe3aaf37a6616aafc0cbd9d621d74295 Mon Sep 17 00:00:00 2001 From: Miranda Ariano Date: Wed, 16 Oct 2024 00:02:27 -0300 Subject: [PATCH 5/9] feat: listado de alumnos que se dieron de baja --- .../src/components/Pages/Estadisticas/AlumnosBaja.tsx | 11 +++++++++++ FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx | 2 +- FrontAdmin/src/routes.tsx | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 FrontAdmin/src/components/Pages/Estadisticas/AlumnosBaja.tsx diff --git a/FrontAdmin/src/components/Pages/Estadisticas/AlumnosBaja.tsx b/FrontAdmin/src/components/Pages/Estadisticas/AlumnosBaja.tsx new file mode 100644 index 0000000..8c71792 --- /dev/null +++ b/FrontAdmin/src/components/Pages/Estadisticas/AlumnosBaja.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import TablaAlumnos from './SubPages/TablaAlumnos'; +import { FetchFirmantes } from '../../../API/AlumnosCompromisoPago'; + +const AlumnosBaja = () => { + return ( + + ); +}; + +export default AlumnosBaja; diff --git a/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx b/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx index e620baa..5193cf1 100644 --- a/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx +++ b/FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx @@ -1,6 +1,6 @@ export const ITEMS_SUBMENU = [ { url: '#', title: 'Inhabilitaciones' }, - { url: '#', title: 'Baja Provisoria' }, + { url: 'baja-provisoria', title: 'Baja Provisoria' }, { url: 'cuotas', title: 'Cuotas' , tooltip: 'Alumnos que abonaron/no abonaron una respectiva cuota' }, { url: 'matricula', title: 'Matricula' }, { url: 'alumnos-que-firmaron-compromiso-de-pago', title: 'Compromiso de Pago'}, diff --git a/FrontAdmin/src/routes.tsx b/FrontAdmin/src/routes.tsx index ba93431..8ca632c 100644 --- a/FrontAdmin/src/routes.tsx +++ b/FrontAdmin/src/routes.tsx @@ -31,6 +31,7 @@ import path from 'path'; import EstadoCuenta from './components/Pages-Alumnos/EstadoCuenta/EstadoCuenta'; import Sysadmin from './components/Pages/SysAdmin/SysAdmin'; import Matricula from './components/Pages/Estadisticas/SubPages/Matricula'; +import AlumnosBaja from './components/Pages/Estadisticas/AlumnosBaja'; const routes = [ { @@ -57,6 +58,11 @@ const routes = [ rol: 'admin', }, + { + path: 'baja-provisoria', + element: , + rol: 'admin', + }, { path: 'alumnos-que-firmaron-compromiso-de-pago', element: , From ccef44a3ed8a61b4cebc80b759b6ff2957b9969c Mon Sep 17 00:00:00 2001 From: yoelmarain Date: Wed, 16 Oct 2024 00:03:31 -0300 Subject: [PATCH 6/9] Refactor API to add endpoints for fetching and disabling students --- FrontAdmin/src/API/Inhabilitaciones.ts | 47 ++++++++++++ .../Alumnos_a_Inhabilitar.tsx | 54 +++++++++++++ .../Inhabilitaciones/Inhabilitaciones.tsx | 25 ++----- .../SubPages/Inhabilitaciones/Tabla.tsx | 75 +++++++++++++++++++ 4 files changed, 181 insertions(+), 20 deletions(-) create mode 100644 FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx create mode 100644 FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx diff --git a/FrontAdmin/src/API/Inhabilitaciones.ts b/FrontAdmin/src/API/Inhabilitaciones.ts index 12a9eef..07156f5 100644 --- a/FrontAdmin/src/API/Inhabilitaciones.ts +++ b/FrontAdmin/src/API/Inhabilitaciones.ts @@ -21,3 +21,50 @@ export const getInhabilitaciones = async (limit: number, offset: number) => { throw new Error('Network error: ' + error); } }; + + +export const getAlumnosaInhabilitar = async () => { + try { + const token = Cookies.get('tokennn'); + const response = await fetch(`http://localhost:8000/api/alumnos/alumnos-a-inhabilitar` , { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + }); + + if (response.ok) { + const data = await response.json(); + return data; + } else { + throw new Error('Error en la respuesta del servidor'); + } + } catch (error) { + throw new Error('Network error: ' + error); + } + +}; + +export const inhabilitarAlumno = async (legajo: number) => { + try { + const token = Cookies.get('tokennn'); + const response = await fetch(`http://localhost:8000/api/alumnos/alumno-a-inhabilitar/${legajo}/` , { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}`, + }, + }); + if (response.ok) { + const data = await response.json(); + return data; + } else { + throw new Error('Error en la respuesta del servidor'); + } + } catch (error) { + throw new Error('Network error: ' + error); + } + +}; + diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx new file mode 100644 index 0000000..4e6a4cf --- /dev/null +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx @@ -0,0 +1,54 @@ +import { useEffect } from "react"; +import { getAlumnosaInhabilitar } from '../../../../../API/Inhabilitaciones'; +import { useState } from "react"; +import { Box, Button, Flex, Spinner } from "@chakra-ui/react"; +import Tabla from './Tabla'; + +export default function AInhabilitar() { + + const [alumnosAInhabilitar, setAlumnosAInhabilitar] = useState([]); + const [loading, setLoading] = useState(true); + const headers = ['Apellido y Nombre', 'Legajo' , 'DNI']; + const [request, setRequest] = useState(false); + + useEffect (() => { + const fetchData = async () => { + const response2 = await getAlumnosaInhabilitar(); + setAlumnosAInhabilitar(response2.results); + setLoading(false); + }; + fetchData(); + }, []); + + return ( + + {loading ? ( + + ) : ( + + + {alumnosAInhabilitar.length > 0 ? ( + + + + + + ) :

No hay datos para mostrar

} +
+
+ )} +
+ + ); +} \ No newline at end of file diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx index 5613f99..f6688ce 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Inhabilitaciones.tsx @@ -1,13 +1,14 @@ import React, { useEffect, useState } from 'react'; import {getInhabilitaciones} from '../../../../../API/Inhabilitaciones'; import Tabla from '../Cuotas/Tabla'; +import AInhabilitar from './Alumnos_a_Inhabilitar'; import { Box, Button, Flex, Tab, TabList, Text ,TabPanel, TabPanels, Tabs, Tag, Spinner, Input } from "@chakra-ui/react"; import { ArrowLeftIcon, ArrowRightIcon } from '@chakra-ui/icons'; function Inhabilitados() { const [inhabilitados, setInhabilitados] = useState([]); const [loading, setLoading] = useState(true); - const headers = ['Apellido y Nombre', 'Legajo' , 'DNI', 'Estado financiero']; + const headers = ['Apellido y Nombre', 'Legajo' , 'DNI', 'Desde']; const [limit1] = useState(10); const [offset1, setOffset1] = useState(0); const [totalInhabilitados, setTotalInhabilitados] = useState(0); @@ -15,8 +16,8 @@ function Inhabilitados() { useEffect(() => { const fetchData = async () => { const response = await getInhabilitaciones(limit1, offset1); - setInhabilitados(response); - setTotalInhabilitados(response.length); + setInhabilitados(response.results); + setTotalInhabilitados(response.count); setLoading(false); }; @@ -109,23 +110,7 @@ function Inhabilitados() { - - {loading ? ( - - ) : ( - - - Inhabilitar - - - )} - + diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx new file mode 100644 index 0000000..3f61f5b --- /dev/null +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx @@ -0,0 +1,75 @@ +import React, { useState } from 'react'; +import { Table, Tr, Th,Thead, Tbody, Td, Checkbox } from '@chakra-ui/react'; +import { useNavigate } from 'react-router-dom'; + +interface TablaProps { + headers: string[]; + data: Array>; + request: boolean; +} + +const Tabla: React.FC = ({ headers, data, request }) => { + const [selectedRows, setSelectedRows] = useState<{ [key: string]: boolean }>({}); + const navigate = useNavigate(); + + const keyMap: { [key: string]: string } = { + 'Apellido y Nombre': 'full_name', + 'DNI': 'user', + 'Legajo': 'legajo', + }; + + const handleCheckboxChange = (dni: string) => { + setSelectedRows((prevSelectedRows) => ({ + ...prevSelectedRows, + [dni]: !prevSelectedRows[dni], + })); + }; + + const handleHeaderCheckboxChange = (e: React.ChangeEvent) => { + const isChecked = e.target.checked; + const newSelectedRows = data.reduce((acc, row) => { + acc[row.user] = isChecked; + return acc; + }, {} as { [key: string]: boolean }); + setSelectedRows(newSelectedRows); + }; + + const allRowsSelected = data.length > 0 && Object.keys(selectedRows).length === data.length && Object.values(selectedRows).every(Boolean); + + return ( +
{field.toUpperCase()} Date: Tue, 15 Oct 2024 21:19:45 -0300 Subject: [PATCH 4/9] Add posibilidad de eliminar el ultimo compromiso --- FrontAdmin/src/API/Montos.ts | 25 +++++++ .../Pages/Configuracion/Configuracion.tsx | 20 ++++-- .../Configuracion/Montos/NewInterfaz.tsx | 67 ++++++++++++++----- 3 files changed, 88 insertions(+), 24 deletions(-) diff --git a/FrontAdmin/src/API/Montos.ts b/FrontAdmin/src/API/Montos.ts index 0cba830..34db3bc 100644 --- a/FrontAdmin/src/API/Montos.ts +++ b/FrontAdmin/src/API/Montos.ts @@ -84,3 +84,28 @@ export const loadPDF = async (id :string,file: File) => { throw new Error('Network error: ' + JSON.stringify(error)); } }; + +export const deleteCompromiso = async (id: number) => { + try { + const token = Cookies.get('tokennn'); + + const response = await fetch(`http://localhost:8000/api/compromisos/${id}/`, { + method: 'DELETE', + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + if (response.ok) { + const data = await response.json(); + return data; + } else { + const errorResponse = await response.json(); + throw new Error( + 'Error en la respuesta del servidor: ' + JSON.stringify(errorResponse) + ); + } + } catch (error) { + throw new Error('Network error: ' + error); + } +} \ No newline at end of file diff --git a/FrontAdmin/src/components/Pages/Configuracion/Configuracion.tsx b/FrontAdmin/src/components/Pages/Configuracion/Configuracion.tsx index 9622b22..ec1413b 100644 --- a/FrontAdmin/src/components/Pages/Configuracion/Configuracion.tsx +++ b/FrontAdmin/src/components/Pages/Configuracion/Configuracion.tsx @@ -1,4 +1,4 @@ -import { Grid, GridItem, Flex, Button, Text, Box } from '@chakra-ui/react'; +import { Grid, GridItem, Flex, Button, Text, Box, Spinner } from '@chakra-ui/react'; import Montos from './Montos/Montos'; import { FetchMontos } from '../../../API/Montos'; import { useEffect, useState } from 'react'; @@ -13,8 +13,10 @@ function Configuracion() { const [totalCount, setTotalCount] = useState(0); const fetchMontos = async (offset: number, limit: number) => { + setLoading(true); try { const data = await FetchMontos(offset, limit); + setMontos(data.results); setTotalCount(data.count); } catch (error) { @@ -46,11 +48,17 @@ function Configuracion() { return ( - - fetchMontos(offset, limit)} /> - - - + + {loading ? ( + + + + ) : ( + <> + fetchMontos(offset, limit)} /> + fetchMontos(offset, limit)} /> + + )} diff --git a/FrontAdmin/src/components/Pages/Configuracion/Montos/NewInterfaz.tsx b/FrontAdmin/src/components/Pages/Configuracion/Montos/NewInterfaz.tsx index 949d282..efb1be4 100644 --- a/FrontAdmin/src/components/Pages/Configuracion/Montos/NewInterfaz.tsx +++ b/FrontAdmin/src/components/Pages/Configuracion/Montos/NewInterfaz.tsx @@ -18,10 +18,12 @@ import { ModalBody, ModalCloseButton, useDisclosure, + Spinner, } from '@chakra-ui/react'; import Cookies from 'js-cookie'; import { useEffect, useState } from 'react'; - +import { deleteCompromiso } from '../../../../API/Montos'; +import ModalComponent from '../../../Modal/ModalConfirmarCambios'; interface Compromiso { anio: string | number | Date; fecha_carga_comp_pdf: string; @@ -38,17 +40,19 @@ interface Compromiso { fecha_vencimiento_1: number; fecha_vencimiento_2: number; fecha_vencimiento_3: number; - } interface CardCargaProps { compromisos: Compromiso[]; + fetchMontos: () => void; } -const NewInterfaz = ({ compromisos }: CardCargaProps) => { +const NewInterfaz = ({ compromisos, fetchMontos }: CardCargaProps) => { const [montos, setMontos] = useState([]); const [pdfUrl, setPdfUrl] = useState(null); const { isOpen, onOpen, onClose } = useDisclosure(); + const { isOpen: isConfirmOpen, onOpen: onConfirmOpen, onClose: onConfirmClose } = useDisclosure(); // Estado para el modal de confirmación + const [isDeleting, setIsDeleting] = useState(false); // Estado de carga para la eliminación useEffect(() => { const sortedMontos = [...compromisos].sort((a, b) => { @@ -56,6 +60,7 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => { const dateB = new Date(b.fecha_carga_comp_pdf); return dateB.getTime() - dateA.getTime(); }); + console.log('Montos ordenados:', sortedMontos); setMontos(sortedMontos); }, [compromisos]); @@ -82,6 +87,24 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => { onClose(); }; + const handleDeleteLastCompromiso = async () => { + if (montos.length === 0) return; + + const lastCompromiso = montos[0]; + try { + setIsDeleting(true); + await deleteCompromiso(lastCompromiso.id_comp_pago); + fetchMontos(); + onConfirmClose(); + } catch (error) { + console.error('Error al eliminar el compromiso:', error); + } finally { + fetchMontos(); + onConfirmClose(); + setIsDeleting(false); + } + }; + return ( {
Año/ Cuatrimestre MatrículaMontosMontos Dia de vencimiento Fecha Ult Modif. Acciones {' $ ' + monto.matricula} Monto Completo: {' $ ' + monto.monto_completo} @@ -129,31 +150,36 @@ const NewInterfaz = ({ compromisos }: CardCargaProps) => { - + 1er Vencimiento: {monto.fecha_vencimiento_1} - + 2do Vencimiento: {monto.fecha_vencimiento_2} - + 3er Vencimiento: {monto.fecha_vencimiento_3} {new Date(monto.fecha_carga_comp_pdf).toLocaleString( 'es-ES', { dateStyle: 'short', timeStyle: 'short' } )} - + + + {index === 0 && ( + + )} +
+ + + + {headers.map((header) => ( + + ))} + + + + {data.map((row) => ( + + + {headers.map((header) => ( + + ))} + + ))} + +
+ + {header}
+ handleCheckboxChange(row.user)} + /> + {row[keyMap[header]]}
+ ); +}; + +export default Tabla; \ No newline at end of file From 37572115b58a04acc14b6bdfc65c979fcffdd0d2 Mon Sep 17 00:00:00 2001 From: yoelmarain Date: Wed, 16 Oct 2024 00:41:03 -0300 Subject: [PATCH 7/9] Refactor API to handle empty response in inhabilitarAlumno function --- FrontAdmin/src/API/Inhabilitaciones.ts | 9 +++++-- .../Alumnos_a_Inhabilitar.tsx | 22 +++++++--------- .../SubPages/Inhabilitaciones/Tabla.tsx | 26 ++++++++++++++++--- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/FrontAdmin/src/API/Inhabilitaciones.ts b/FrontAdmin/src/API/Inhabilitaciones.ts index 07156f5..fc16135 100644 --- a/FrontAdmin/src/API/Inhabilitaciones.ts +++ b/FrontAdmin/src/API/Inhabilitaciones.ts @@ -57,8 +57,13 @@ export const inhabilitarAlumno = async (legajo: number) => { }, }); if (response.ok) { - const data = await response.json(); - return data; + if (response.status === 204) { + // No hay contenido en la respuesta + return {}; + } else { + const data = await response.json(); + return data; + } } else { throw new Error('Error en la respuesta del servidor'); } diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx index 4e6a4cf..82de220 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx @@ -11,12 +11,13 @@ export default function AInhabilitar() { const headers = ['Apellido y Nombre', 'Legajo' , 'DNI']; const [request, setRequest] = useState(false); - useEffect (() => { - const fetchData = async () => { - const response2 = await getAlumnosaInhabilitar(); - setAlumnosAInhabilitar(response2.results); - setLoading(false); - }; + const fetchData = async () => { + setLoading(true); + const response2 = await getAlumnosaInhabilitar(); + setAlumnosAInhabilitar(response2.results); + }; + + useEffect(() => { fetchData(); }, []); @@ -25,20 +26,17 @@ export default function AInhabilitar() { borderRadius={8} w={"100%"} > - {loading ? ( - - ) : ( + {alumnosAInhabilitar.length > 0 ? ( - + @@ -47,7 +45,7 @@ export default function AInhabilitar() { ) :

No hay datos para mostrar

}
- )} + ); diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx index 3f61f5b..a1e667a 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx @@ -1,16 +1,19 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Table, Tr, Th,Thead, Tbody, Td, Checkbox } from '@chakra-ui/react'; import { useNavigate } from 'react-router-dom'; +import { inhabilitarAlumno } from '../../../../../API/Inhabilitaciones'; +import { set } from 'date-fns'; interface TablaProps { headers: string[]; data: Array>; request: boolean; + onInhabilitar: () => void; } -const Tabla: React.FC = ({ headers, data, request }) => { +const Tabla: React.FC = ({ headers, data, request, onInhabilitar }) => { const [selectedRows, setSelectedRows] = useState<{ [key: string]: boolean }>({}); - const navigate = useNavigate(); + const [renderKey, setRenderKey] = useState(0); const keyMap: { [key: string]: string } = { 'Apellido y Nombre': 'full_name', @@ -34,10 +37,25 @@ const Tabla: React.FC = ({ headers, data, request }) => { setSelectedRows(newSelectedRows); }; + useEffect(() => { + const handleInhabilitar = async () => { + const alumnosInhabilitar = data.filter((row) => selectedRows[row.user]); + for (const alumno of alumnosInhabilitar) { + await inhabilitarAlumno(alumno.legajo); + } + setSelectedRows({}); + setRenderKey((prevKey) => prevKey + 1); + onInhabilitar(); + }; + if (request) { + handleInhabilitar(); + } + }, [request]); + const allRowsSelected = data.length > 0 && Object.keys(selectedRows).length === data.length && Object.values(selectedRows).every(Boolean); return ( - +
From b4adb6bef6b261aa35b3f795eb3df895b3e7c1e0 Mon Sep 17 00:00:00 2001 From: yoelmarain Date: Wed, 16 Oct 2024 00:48:01 -0300 Subject: [PATCH 8/9] Refactor to update table request status in Alumnos_a_Inhabilitar.tsx --- .../SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx | 2 +- .../Pages/Estadisticas/SubPages/Inhabilitaciones/Tabla.tsx | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx index 82de220..e6db89e 100644 --- a/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx +++ b/FrontAdmin/src/components/Pages/Estadisticas/SubPages/Inhabilitaciones/Alumnos_a_Inhabilitar.tsx @@ -30,7 +30,7 @@ export default function AInhabilitar() { {alumnosAInhabilitar.length > 0 ? ( - +