fix filter table

This commit is contained in:
Wikzyy
2025-03-17 15:11:02 +07:00
parent 069c41c7b8
commit ce97994299
2 changed files with 11 additions and 56 deletions

View File

@ -42,6 +42,7 @@ const AddDialog = () => {
const resetForm = () => { const resetForm = () => {
setFormField(initialState); setFormField(initialState);
setAlert({ show: false, message: '' });
}; };
const doCreateMunicipio = useCallback( const doCreateMunicipio = useCallback(

View File

@ -160,73 +160,27 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) =
try { try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting; sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() }; filter = filter.length == 0 ? {} : { any: filter[0].value?.toLowerCase() };
const response = await axios.get(`${API_URL}/municipios/list`, { const response = await GetData(`${API_URL}/municipios/list`, {
params: { limit,
limit: limit,
page: page + 1, page: page + 1,
with_deleted: false, with_deleted: false,
order_field: sorting[0].id, order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' 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) => { // 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;
// if (a.name > b.name) return 1; // if (a.name > b.name) return 1;
// return 0; // return 0;
// }); // });
setMunicipios(response.data.data.list); setMunicipios(response?.data.list);
return { data: response?.data.data.list, totalCount: response?.data.data.total_count }; return { data: response?.data.list, totalCount: response?.data.total_count };
} catch (error) { } catch (error) {
console.error('Error fetching municipios', 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<MunicipiosProps>) => {
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<MunicipiosProps>) => {
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 ( return (
<ManageMunicipiosContext.Provider <ManageMunicipiosContext.Provider
value={{ value={{