Skip to content

Commit

Permalink
Refactor Listado component to fix date parameter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelmarain committed Oct 14, 2024
1 parent 3036bd5 commit 159ef36
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Listado() {
full_name: string;
estado_financiero: string;
};
const { fecha } = useParams<{ fecha: string }>();
const {fecha} = useParams<{ fecha: string }>();
const [abonaron, setAbonaron] = useState<Alumno[]>([]);
const [totalabonaron, setTotalAbonaron] = useState<number>(0);
const [noAbonaron, setNoAbonaron] = useState<Alumno[]>([]);
Expand Down Expand Up @@ -82,6 +82,7 @@ export default function Listado() {
fetchAbonaron(fecha);
}, [limit2, offset2, fecha, filter]);


const handleFilterChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setFilter(event.target.value);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ import { Heading, Input, Flex, Button } from '@chakra-ui/react';
import {formatoFechaAAAAMMaMMAAAA} from '../../../../../utils/general';
import { useNavigate } from 'react-router-dom';

export default function Select() {
type SelectProps = {
page: string;
}

const Select: React.FC<SelectProps> = ({ page }) => {
const [selectedMonth, setSelectedMonth] = useState('');
const [fecha, setFecha] = useState('');
const navigate = useNavigate();

const handleMonthChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSelectedMonth(event.target.value);
setFecha(formatoFechaAAAAMMaMMAAAA(event.target.value));
};

const handleButtonClick = () => {
const [year, month] = selectedMonth.split('-');
if (page === 'cuotas') {
navigate(`/admin/estadisticas/cuotas/${month}-${year}`);
} else if (page === 'pagos') {
navigate(`/admin/estadisticas/pagos/${year}-${month}`);
}
};

return (
Expand All @@ -26,9 +36,11 @@ export default function Select() {
/>
<Flex justifyContent={"flex-end"} mt={1}>
<Button colorScheme='blue' variant={"solid"}
onClick={() => navigate(`/admin/estadisticas/cuotas/${fecha}`)}
onClick={handleButtonClick}
>Solicitar</Button>
</Flex>
</Flex>
);
};

export default Select;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useEffect } from "react";
import { useParams } from "react-router-dom"

export default function Pagos() {

const { fecha } = useParams<{ fecha: string }>();

useEffect (() => {
const [year, month] = fecha.split('-');

}, [fecha]);

return (
<div>
<h1>Pagos</h1>
</div>
)

}
2 changes: 1 addition & 1 deletion FrontAdmin/src/components/SubMenu/LinksSubMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const ITEMS_SUBMENU = [
{ 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'},
{ url: '#', title: 'Pagos' },
{ url: 'pagos', title: 'Pagos' },
{
url: 'alumnos-que-cursan-materia',
title: 'Alumnos que cursan una materia',
Expand Down
13 changes: 12 additions & 1 deletion FrontAdmin/src/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 Pagos from './components/Pages/Estadisticas/SubPages/Pagos/Pagos';

const routes = [
{
Expand Down Expand Up @@ -74,14 +75,24 @@ const routes = [
},
{
path: 'cuotas',
element: <Select />,
element: <Select page={'cuotas'} />,
rol: 'admin',
},
{
path : 'cuotas/:fecha',
element: <Listado />,
rol: 'admin',
},
{
path: 'pagos',
element: <Select page={'pagos'} />,
rol: 'admin',
},
{
path: 'pagos/:fecha',
element: <Pagos />,
rol: 'admin',
},

],
},
Expand Down

0 comments on commit 159ef36

Please sign in to comment.