feat: increase fetchSucos limit and add doFetchData function

This commit is contained in:
Wikzyy
2025-03-18 10:46:39 +07:00
parent 1cfda6745e
commit e0c064c749
6 changed files with 199 additions and 88 deletions

View File

@ -80,6 +80,24 @@ const AddDialog = () => {
[formField]
);
const doFetchMunicipios = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log(response?.data);
setMunicipios(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -110,25 +128,7 @@ const AddDialog = () => {
}, [showAddDialog]);
useEffect(() => {
const fetchMunicipios = async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log(response?.data);
setMunicipios(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
};
fetchMunicipios([{ id: 'name', desc: false }]);
doFetchMunicipios([{ id: 'name', desc: false }]);
}, []);
return (

View File

@ -80,6 +80,41 @@ const EditDialog = () => {
[selectedPostoAdms, formField]
);
const doFetchMunicipios = useCallback(async (sorting: any) => {
try {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log('MUNICIPIOS: ', response?.data);
setMunicipios(response?.data.list);
} catch (error) {
console.error('Error fetching municipios', error);
}
}, []);
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/postoadms/getdata/${id}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name,
municipio_id: response.data.municipios.id
}));
} else {
setFormField((prev) => ({
...prev,
name: ''
}));
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -93,6 +128,18 @@ const EditDialog = () => {
setAlert({ show: false, message: '' });
};
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (selectedPostoAdms) {
doFetchData(selectedPostoAdms);
}
}, [selectedPostoAdms]);
useEffect(() => {
if (selectedPostoAdms) {
setFormField({
@ -104,25 +151,7 @@ const EditDialog = () => {
}, [formattedTime]);
useEffect(() => {
try {
const fetchMunicipios = async (sorting: any) => {
sorting = sorting.length == 0 ? [{ id: 'name', desc: false }] : sorting;
const response = await GetData(`${API_URL}/municipios/list`, {
limit: 100,
page: 1,
with_deleted: false,
order_field: sorting[0].id,
order_direction: sorting[0].desc == false ? 'ASC' : 'DESC'
});
// console.log(response?.data);
setMunicipios(response?.data.list);
};
fetchMunicipios([{ id: 'name', desc: false }]);
} catch (error) {
console.error('Error fetching municipios', error);
}
doFetchMunicipios([{ id: 'name', desc: false }]);
}, []);
// console.log(selectedPostoAdms);