Loading web/src/hooks/useTown.tsx +15 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import { TownRepositoryProd } from "../data/repositories/prod/town_repository"; import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form"; import { Town, TownFormValues } from "../infraestructure/entities/town"; import { toast } from "react-toastify"; import axios, { AxiosError } from "axios"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); Loading Loading @@ -60,6 +61,7 @@ export const useTown = (forceRenderList?: () => void) => { setValue } = useForm<TownFormValues>({resolver}); const [townsList, setTownsList] = useState<Town[] | null>(null); const [errorMessage, setErrorMessage] = useState(""); const onSubmit: SubmitHandler<TownFormValues> = (data: TownFormValues) => { const fetch = async () => { Loading @@ -69,14 +71,25 @@ export const useTown = (forceRenderList?: () => void) => { forceRenderList(); } }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; switch(error.code){ case(axios.AxiosError.ERR_BAD_REQUEST): setErrorMessage("Acceso no autorizado"); break; case(axios.AxiosError.ERR_NETWORK): setErrorMessage("Conexión con el servidor fallida"); break; } } throw new Error; } } toast.promise( fetch(),{ pending: "Subiendo datos...", success: "Los datos se han subido correctamente", error: "Sucedio un error" error: errorMessage } ) } Loading Loading
web/src/hooks/useTown.tsx +15 −2 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ import { TownRepositoryProd } from "../data/repositories/prod/town_repository"; import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form"; import { Town, TownFormValues } from "../infraestructure/entities/town"; import { toast } from "react-toastify"; import axios, { AxiosError } from "axios"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); Loading Loading @@ -60,6 +61,7 @@ export const useTown = (forceRenderList?: () => void) => { setValue } = useForm<TownFormValues>({resolver}); const [townsList, setTownsList] = useState<Town[] | null>(null); const [errorMessage, setErrorMessage] = useState(""); const onSubmit: SubmitHandler<TownFormValues> = (data: TownFormValues) => { const fetch = async () => { Loading @@ -69,14 +71,25 @@ export const useTown = (forceRenderList?: () => void) => { forceRenderList(); } }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; switch(error.code){ case(axios.AxiosError.ERR_BAD_REQUEST): setErrorMessage("Acceso no autorizado"); break; case(axios.AxiosError.ERR_NETWORK): setErrorMessage("Conexión con el servidor fallida"); break; } } throw new Error; } } toast.promise( fetch(),{ pending: "Subiendo datos...", success: "Los datos se han subido correctamente", error: "Sucedio un error" error: errorMessage } ) } Loading