refactor axios to useCallApi
This commit is contained in:
@ -3,10 +3,10 @@ import { Button } from '@/components/ui/button';
|
||||
import { Toaster } from '@/components/ui/sonner';
|
||||
import { apiConfig } from '@/config/api.config';
|
||||
import { ColumnDef } from '@tanstack/react-table';
|
||||
import axios from 'axios';
|
||||
import { createContext, useCallback, useMemo, useState } from 'react';
|
||||
import { useNavigate, useParams } from 'react-router';
|
||||
import ListToolbar from '../blocks/ListToolbar';
|
||||
import { useCallApi } from '@/hooks';
|
||||
|
||||
interface PostoAdmsProps {
|
||||
posto_adms_id: number;
|
||||
@ -58,6 +58,7 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
const [showEditDialog, setShowEditDialog] = useState(false);
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
const [selectedPostoAdms, setSelectedPostoAdms] = useState<string | null>(null);
|
||||
const { GetData } = useCallApi();
|
||||
|
||||
const navigate = useNavigate();
|
||||
const { municipioId } = useParams();
|
||||
@ -151,14 +152,12 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
try {
|
||||
sorting: sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
|
||||
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
|
||||
const response = await axios.get(`${API_URL}/postoadms/list`, {
|
||||
params: {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
|
||||
}
|
||||
const response = await GetData(`${API_URL}/postoadms/list`, {
|
||||
limit,
|
||||
page: page + 1,
|
||||
with_deleted: false,
|
||||
order_field: sorting[0].id,
|
||||
order_direction: sorting[0].desc ? 'DESC' : 'ASC'
|
||||
});
|
||||
// console.log(response.data);
|
||||
// const sortedList = response.data.data.list.sort((a: PostoAdmsProps, b: PostoAdmsProps) => {
|
||||
@ -166,8 +165,8 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
|
||||
// if (a.name > b.name) return 1;
|
||||
// return 0;
|
||||
// });
|
||||
setPostoAdms(response.data.data.list);
|
||||
return { data: response.data.data.list, totalCount: response.data.data.total_count };
|
||||
setPostoAdms(response?.data.list);
|
||||
return { data: response?.data.list, totalCount: response?.data.total_count };
|
||||
} catch (error) {
|
||||
console.error('Error fetching Postu Administrativo', error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user