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

Se renombra el hook

parent 9022f234
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -122,7 +122,7 @@ const resolver: Resolver<Place> = async (data) => {
  };
};

export const usePlaceRegister = () => {
export const usePlace = () => {
  const {
    register, 
    handleSubmit,
@@ -135,9 +135,11 @@ export const usePlaceRegister = () => {
  const [languageDescriptionIndexSelected, setLanguageDescriptionIndexSelected] = useState(0);
  const [descriptions, setDescriptions] = useState<string[]>(new Array(languaguesList.length).fill(""));
  const [availableDays, setAvailableDays] = useState<AvailableDays>(AvailableDays.WEEKEND);
  const [placeList, setPlaceList] = useState<Place[]>([]);
  const [isLoading, setIsLoading] = useState(false);
  const {townsList, getTownsByState} = useTown();
  const {getStates, statesList} = useGetStatesList();
  const [pending, setPending] = useState(false);
  
  useEffect(() => {
    setIsLoading(true);
@@ -201,15 +203,18 @@ export const usePlaceRegister = () => {
    }
  }

  const getPlacesByTown = async (idTown: number) => {
  const updatePlacesByTown = async (idTown: number) => {
    setPending(true);
    try{
      const towns = await townRepository.getTownsByState(stateId, stateName);
      setTownsList(towns);
      const places = await placeRepository.getPlacesByTown(idTown);
      setPlaceList(places);
      setPending(false);
    }catch(error: any){
      if(axios.isAxiosError(error)){
        error as AxiosError;
        showErrorAxios(error);
      }
      setPending(false);
    }
  }

@@ -231,6 +236,9 @@ export const usePlaceRegister = () => {
    updateTimeForm,
    availableDays,
    setAvailableDays,
    resetField
    resetField,
    updatePlacesByTown,
    placeList,
    pending
  };
}