Commit f2f17128 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Se modifico para que al obtener un pueblo se obtenga tambien el nombre del estado

parent 313d3587
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import { Town } from "../infraestructure/entities/town";
import { toast } from "react-toastify";
import axios, { AxiosError } from "axios";
import { showErrorAxios } from "../utils/Messages";
import { useGetStatesList } from "./useGetStatesList";

const townDatasource = new TownDatasourceProd();
const townRepository = new TownRepositoryProd(townDatasource);
@@ -63,6 +64,7 @@ export const useTown = (forceRenderList?: () => void) => {
  } = useForm<Town>({resolver});
  const [townsList, setTownsList] = useState<Town[]>([]);
  const [errorMessage, setErrorMessage] = useState("");
  const {getStateById} = useGetStatesList();
  
  const onSubmit: SubmitHandler<Town> = (data: Town) => {
    const fetch = async () => {
@@ -110,6 +112,10 @@ export const useTown = (forceRenderList?: () => void) => {
  const getTownById = async (idTown: number): Promise<Town | null> => {
    try{
      const town = await townRepository.getTown(idTown);
      const state = await getStateById(town.idState);
      if(state){
        town.state = state.name;
      }
      return town;
    }catch(error: any){
      if(axios.isAxiosError(error)){