fetch get data municipio, postoadms, sucos on table

This commit is contained in:
Wikzyy
2025-03-03 08:57:36 +07:00
parent 80596e6f29
commit 84408ac869
6 changed files with 259 additions and 5 deletions

View File

@ -14,6 +14,7 @@ interface PostoAdmsProps {
}
interface ContextProps {
postoAdms: PostoAdmsProps[];
showSearchDialog: boolean;
handleSearchDialog: (show: boolean) => void;
showEditDialog: boolean;
@ -33,6 +34,7 @@ interface ContextProps {
}
const initialProps: ContextProps = {
postoAdms: [],
showSearchDialog: false,
handleSearchDialog: (show: boolean) => {},
showEditDialog: false,
@ -49,6 +51,7 @@ const ManagePostoAdmsContext = createContext<ContextProps>(initialProps);
const API_URL = apiConfig.service_master_data;
const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNode }) => {
const [postoAdms, setPostoAdms] = useState<PostoAdmsProps[]>([]);
const [showSearchDialog, setShowSearchDialog] = useState(false);
const [showAddDialog, setShowAddDialog] = useState(false);
const [showEditDialog, setShowEditDialog] = useState(false);
@ -121,10 +124,10 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
);
const getPostoAdmsLists = async (page: number, limit: number, sorting: any, filter: any) => {
sorting: sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
try {
const response = await axios.get(`${API_URL}/municipios/postoadms/${municipioId}`, {
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,
@ -134,7 +137,13 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
}
});
console.log(response.data);
return { data: response.data.data, totalCount: response.data.data.total_count };
// const sortedList = response.data.data.list.sort((a: PostoAdmsProps, b: PostoAdmsProps) => {
// if (a.name < b.name) return -1;
// 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 };
} catch (error) {
console.error('Error fetching Postu Administrativo', error);
}
@ -143,6 +152,7 @@ const ManagePostoAdmsContextProvider = ({ children }: { children: React.ReactNod
return (
<ManagePostoAdmsContext.Provider
value={{
postoAdms,
showSearchDialog,
handleSearchDialog,
showAddDialog,