This commit is contained in:
Raja Oktafrianto
2025-03-18 11:27:23 +07:00
parent 8026d6910a
commit 1445fc8ecf
28 changed files with 446 additions and 316 deletions

View File

@ -80,10 +80,28 @@ 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();
if (formField.name === '' || formField.municipio_id === 0) {
if (formField.name.trim() === '' || formField.municipio_id === 0) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}
@ -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 (