Skip to content

Commit

Permalink
Refactor API to accept pagination and filtering parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelmarain committed Oct 14, 2024
1 parent fa41180 commit d3abe97
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions FrontAdmin/src/API/Inhabilitaciones.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -57,6 +57,19 @@ function Inhabilitados() {
>
Alumnos a Habilitar
</Tab>
<Tab
_selected={{
borderBottom: "2px solid",
borderColor: "blue.500",
color: "blue.500",
borderTop: "none",
borderLeft: "none",
borderRight: "none"
}}
_focus={{ boxShadow: "none" }}
>
Alumnos a Inhabilitar
</Tab>
<Tab
_selected={{
borderBottom: "2px solid",
Expand All @@ -74,7 +87,6 @@ function Inhabilitados() {

<TabPanels>
<TabPanel>

<Flex>
<Box
borderRadius={8}
Expand All @@ -97,20 +109,38 @@ function Inhabilitados() {
</TabPanel>
<TabPanel>
<Flex>

<Box
borderRadius={8}
borderColor={"gray.200"}
borderStyle={"solid"}
borderWidth={1}
p={3}
>
{loading ? (
<Spinner />
) : (
<Box>
<Flex>
<Text fontSize="xl" fontWeight="bold">Inhabilitar</Text>
</Flex>
</Box>
)}
</Box>
</Flex>
</TabPanel>
<TabPanel>
<Flex>

{loading ? (
<Spinner />
) :
inhabilitados.length > 0 ?
(
<Box justifyContent={"center"} w={"100%"}>
<Flex direction={"column"} w={"100%"} mb={4}>
<Flex direction={"column"} w={"100%"} mb={2}>
<Tag bg="secundaryBg" w={"100%"} p={"10px"} size="lg" fontSize={18} display="flex" justifyContent="center" fontWeight={"bold"} fontFamily={"serif"}>Total: {totalInhabilitados}</Tag>
</Flex>
<Box borderRadius={8}
borderColor={"gray.200"}
borderStyle={"solid"}
w={"100%"}
borderWidth={1}
p={3}>
<Input type="text" placeholder="Buscar por Apellido y Nombre, Legajo o DNI..." w={"100%"} mb={2} />
<Tabla headers={headers} data={inhabilitados} />
<Box bottom="0" width="100%" bg="white" p="10px" mt={4} boxShadow="md" >
<Flex justifyContent="space-between" alignItems={"center"}>
Expand All @@ -123,9 +153,9 @@ function Inhabilitados() {
</Button>
</Flex>
</Box>
</Box>

</Box>
)}
): <p>No hay datos para mostrar</p>}

</Flex>
</TabPanel>
Expand Down

0 comments on commit d3abe97

Please sign in to comment.