diff --git a/src/pages/master/municipios/blocks/AddDialog.tsx b/src/pages/master/municipios/blocks/AddDialog.tsx index cb447f2..d2dfda4 100644 --- a/src/pages/master/municipios/blocks/AddDialog.tsx +++ b/src/pages/master/municipios/blocks/AddDialog.tsx @@ -42,6 +42,7 @@ const AddDialog = () => { const resetForm = () => { setFormField(initialState); + setAlert({ show: false, message: '' }); }; const doCreateMunicipio = useCallback( diff --git a/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx b/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx index 1ac9904..63697d4 100644 --- a/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx +++ b/src/pages/master/municipios/hooks/ManageMunicipiosContext.tsx @@ -160,73 +160,27 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) = 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}/municipios/list`, { - params: { - limit: limit, - page: page + 1, - with_deleted: false, - order_field: sorting[0].id, - order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' - } + const response = await GetData(`${API_URL}/municipios/list`, { + limit, + page: page + 1, + with_deleted: false, + order_field: sorting[0].id, + order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', + filter: JSON.stringify(filter) }); - // console.log(response.data); + // console.log(response?.data); // const sortedList = response.data.data.list.sort((a: MunicipiosProps, b: MunicipiosProps) => { // if (a.name < b.name) return -1; // if (a.name > b.name) return 1; // return 0; // }); - setMunicipios(response.data.data.list); - return { data: response?.data.data.list, totalCount: response?.data.data.total_count }; + setMunicipios(response?.data.list); + return { data: response?.data.list, totalCount: response?.data.total_count }; } catch (error) { console.error('Error fetching municipios', error); } }; - const getPostoadmsByMunicipio = async (name: string) => { - try { - const response = await axios.get(`${API_URL}/municipios/postoadms/${name}`); - const data = response.data; - console.log(data); - } catch (error) { - console.error(`Error fetching municipios by ${name}`, error); - } - }; - - const createMunicipios = async (data: Partial) => { - try { - await axios.post(`${API_URL}/municipios/create`, data); - // getMunicipiosLists(10, 1, false, 'name', 'ASC'); - } catch (error) { - console.error('Error creating municipios', error); - } - }; - - const updateMunicipios = async (id: number, data: Partial) => { - try { - await axios.put(`${API_URL}/update/${id}`, data); - // getMunicipiosLists(10, 1, false, 'name', 'ASC'); - } catch (error) { - console.error('Error updating municipios', error); - } - }; - - const deleteMunicipios = async (id: number, hardDelete?: boolean) => { - try { - await axios.delete(`${API_URL}/delete/${id}/${hardDelete}`); - // getMunicipiosLists(10, 1, false, 'name', 'ASC'); - } catch (error) { - console.error('Error deleting municipios', error); - } - }; - - const restoreMunicipios = async (id: number) => { - try { - await axios.put(`${API_URL}/restore/${id}`); - // getMunicipiosLists(10, 1, false, 'name', 'ASC'); - } catch (error) { - console.error('Error restoring municipios', error); - } - }; return (