feat: increase fetchSucos limit and add doFetchData function
This commit is contained in:
@ -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"
|
||||
|
||||
Reference in New Issue
Block a user