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

@ -25,7 +25,7 @@ const EditDialog = () => {
const { showEditDialog, handleEditDialog, selectedMunicipios, municipios } =
useManageMunicipiosContext();
const { reload } = useDataGrid();
const { PutData } = useCallApi();
const { PutData, GetData } = useCallApi();
const parsedUser = getAuth()?.user;
const [alert, setAlert] = useState({
show: false,
@ -44,6 +44,7 @@ const EditDialog = () => {
const resetForm = () => {
setFormField(initialState);
setAlert({ show: false, message: '' });
};
const doUpdateMunicipios = useCallback(
@ -74,6 +75,22 @@ const EditDialog = () => {
[selectedMunicipios, formField]
);
const doFetchData = useCallback(async (id: string) => {
const response = await GetData(`${API_URL}/municipios/getdata/${id}`, { id });
if (response?.status) {
setFormField((prev) => ({
...prev,
name: response.data.name
}));
} else {
setFormField((prev) => ({
...prev,
name: ''
}));
}
}, []);
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
@ -82,20 +99,22 @@ const EditDialog = () => {
return;
}
// setFormField({
// name: formField.name,
// created_by: parsedUser.email,
// created_at: formattedTime
// });
doUpdateMunicipios(e);
console.log(formField);
setAlert({ show: false, message: '' });
};
// const doFetchMunicipios = useCallback(async (id: string) => {
// const response = await axios.get(`${API_URL}/municipios/${id}`);
// }, []);
useEffect(() => {
if (selectedMunicipios) {
doFetchData(selectedMunicipios);
}
}, [selectedMunicipios]);
useEffect(() => {
if (showEditDialog === false) {
resetForm();
}
}, [showEditDialog]);
useEffect(() => {
if (selectedMunicipios) {
@ -127,7 +146,9 @@ const EditDialog = () => {
<div className="card-body grid gap-5">
<div className="w-full">
<div className="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
<label className="form-label flex items-center gap-1 max-w-56">Name</label>
<label className="form-label flex items-center gap-1 max-w-56">
Name<span className="text-red-500">*</span>
</label>
<Input
className="input"
type="text"