diff --git a/web/src/core/utils/Messages.ts b/web/src/core/utils/Messages.ts index 5418bbc4931d411485ca7853e34360b4eb5cd863..96411d2b2d36158a0d84c8311e6ed38ffcc62b58 100644 --- a/web/src/core/utils/Messages.ts +++ b/web/src/core/utils/Messages.ts @@ -3,22 +3,19 @@ import { toast } from "react-toastify"; /** * Displays an error message using react-toastify based on the type of Axios error. - * + * * @param {AxiosError} error - The error object returned by Axios. */ export const showErrorAxios = (error: AxiosError) => { let message = ""; // Determine the error message based on the error code - switch(error.code){ - case(axios.AxiosError.ERR_BAD_REQUEST): - message = "Acceso no autorizado"; // Unauthorized access - break; - case(axios.AxiosError.ERR_NETWORK): + switch (error.code) { + case axios.AxiosError.ERR_NETWORK: message = "Conexión con el servidor fallida"; // Server connection failed break; default: - message = error.message; // Default to the error message provided by Axios + message = (error.response?.data as any).message || "Error de servidor"; // Default to the error message provided by Axios break; } @@ -31,6 +28,6 @@ export const showErrorAxios = (error: AxiosError) => { pauseOnHover: false, // Do not pause the toast on hover draggable: true, // Allow the toast to be draggable progress: undefined, // Use the default progress bar behavior - theme: "colored" // Use the colored theme for the toast + theme: "colored", // Use the colored theme for the toast }); -} \ No newline at end of file +}; diff --git a/web/src/domain/useCase/useAdminHomePage.ts b/web/src/domain/useCase/useAdminHomePage.ts index e50539fccc5331dcd49eb303b49207cf9ac60a4a..c0f8ccd0d2d7b507d6186b71016329044ee0e7d9 100644 --- a/web/src/domain/useCase/useAdminHomePage.ts +++ b/web/src/domain/useCase/useAdminHomePage.ts @@ -47,7 +47,7 @@ export const useAdminHomePage = () => { setIsLoading(false); }; checkAdminRole(); - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [user]); // Update town information diff --git a/web/src/domain/useCase/useAdminTownInfo.ts b/web/src/domain/useCase/useAdminTownInfo.ts index 5b1fed5160670da71237391c3ca20c8d1fd60278..1547ccb17af13a9c94647a907be5f29633f5182c 100644 --- a/web/src/domain/useCase/useAdminTownInfo.ts +++ b/web/src/domain/useCase/useAdminTownInfo.ts @@ -3,31 +3,28 @@ import { useEffect, useState } from "react"; import { useGetStatesList } from "./useGetStatesList"; // Custom hook for managing town information in admin panel -export const useAdminTownInfo = (updateTown: ()=>void) => { +export const useAdminTownInfo = (updateTown: () => void) => { const [isEnglish, setIsEnglish] = useState(false); - const [isLoading, setIsLoading] = useState(true); const [renderCount, setRenderCount] = useState(0); - const {getStates, statesList} = useGetStatesList(); + const { getStates, statesList } = useGetStatesList(); // Function to force re-render the list - const forceRenderList = () =>{ + const forceRenderList = () => { updateTown(); - setRenderCount(prevCount => prevCount + 1); - } + setRenderCount((prevCount) => prevCount + 1); + }; // Fetch states on component mount - useEffect(()=> { + useEffect(() => { getStates(); - // eslint-disable-next-line react-hooks/exhaustive-deps - },[]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); return { isEnglish, - isLoading, setIsEnglish, - setIsLoading, forceRenderList, renderCount, statesList, - } -} \ No newline at end of file + }; +}; diff --git a/web/src/domain/useCase/useCategory.ts b/web/src/domain/useCase/useCategory.ts index 92d3e52254baa8a52d0b4f6624bb36018ef1778c..3b5845e372a1fe3d29a357d65e057061ad4e3e38 100644 --- a/web/src/domain/useCase/useCategory.ts +++ b/web/src/domain/useCase/useCategory.ts @@ -95,12 +95,12 @@ export const useCategory = ( if (axios.isAxiosError(error)) { error as AxiosError; switch (error.code) { - case axios.AxiosError.ERR_BAD_REQUEST: - errorMessage = "Acceso no autorizado"; - break; case axios.AxiosError.ERR_NETWORK: errorMessage = "Conexión con el servidor fallida"; break; + default: + errorMessage = error.response?.data.message; + break; } } throw new Error(errorMessage); diff --git a/web/src/domain/useCase/useLogin.ts b/web/src/domain/useCase/useLogin.ts index 047058926c517f22eeae1260e318fa7c3ce67000..13214acf774f5d5158c11820ae06104dbc8bd73d 100644 --- a/web/src/domain/useCase/useLogin.ts +++ b/web/src/domain/useCase/useLogin.ts @@ -72,16 +72,16 @@ export const useLogin = (setIsLoading: Dispatch>) => { if (axios.isAxiosError(error)) { error as AxiosError; switch (error.code) { - case axios.AxiosError.ERR_BAD_REQUEST: + case axios.AxiosError.ERR_NETWORK: setError("root.serverError", { - type: "401", - message: "Correo electrónico o contraseña incorrectos", + type: "500", + message: "Conexión con el servidor fallida", }); break; - case axios.AxiosError.ERR_NETWORK: + default: setError("root.serverError", { type: "500", - message: "Conexión con el servidor fallida", + message: error.response?.data.message || "Error de servidor", }); break; } @@ -97,7 +97,7 @@ export const useLogin = (setIsLoading: Dispatch>) => { if (user) { navigate("/"); } - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return { register, handleSubmit, onSubmit, errors, clearErrors }; diff --git a/web/src/domain/useCase/useResetPassword.ts b/web/src/domain/useCase/useResetPassword.ts index f38fa20deadbda9f8152481b2eae0b683a6290c2..147bbbe972fec801f2c6a5287eb528199cc7a557 100644 --- a/web/src/domain/useCase/useResetPassword.ts +++ b/web/src/domain/useCase/useResetPassword.ts @@ -122,12 +122,13 @@ export const useResetPassword = (handleClickToClose?: () => void) => { if (axios.isAxiosError(error)) { error as AxiosError; switch (error.code) { - case axios.AxiosError.ERR_BAD_REQUEST: - errorMessage = "Acceso no autorizado"; - break; case axios.AxiosError.ERR_NETWORK: errorMessage = "Conexión con el servidor fallida"; break; + default: + errorMessage = + error.response?.data.message || "Error de servidor"; + break; } } throw new Error(errorMessage); diff --git a/web/src/domain/useCase/useTown.ts b/web/src/domain/useCase/useTown.ts index 6fd43699d3684b858de8164de4c81f80522d94ae..82d7b8481284b89be4941dbd22273da51b4e7655 100644 --- a/web/src/domain/useCase/useTown.ts +++ b/web/src/domain/useCase/useTown.ts @@ -158,12 +158,13 @@ export const useTown = ( if (axios.isAxiosError(error)) { error as AxiosError; switch (error.code) { - case axios.AxiosError.ERR_BAD_REQUEST: - errorMessage = "Acceso no autorizado"; - break; case axios.AxiosError.ERR_NETWORK: errorMessage = "Conexión con el servidor fallida"; break; + default: + errorMessage = + error.response?.data.message || "Error de servidor"; + break; } } throw new Error(errorMessage); diff --git a/web/src/presentation/admin/admin_panel_poi/admin_panel_poi_list/admin_panel_poi_list.tsx b/web/src/presentation/admin/admin_panel_poi/admin_panel_poi_list/admin_panel_poi_list.tsx index ef5dfa9612b2943a3bd86ac6d9ed8c980cf46728..086ceb60ad0f944bd7caf17f0a4866a38a24af86 100644 --- a/web/src/presentation/admin/admin_panel_poi/admin_panel_poi_list/admin_panel_poi_list.tsx +++ b/web/src/presentation/admin/admin_panel_poi/admin_panel_poi_list/admin_panel_poi_list.tsx @@ -17,6 +17,7 @@ interface props { setWindowVisibilityViewer: (visibility: boolean) => void; setBinaryData: Dispatch>; setIsPDFViewerActive: Dispatch>; + setIsWindowsActive: Dispatch>; } // Main component for the Admin Panel POI List @@ -27,6 +28,7 @@ export const AdminPanelPoiList = ({ setWindowVisibilityViewer, setBinaryData, setIsPDFViewerActive, + setIsWindowsActive, }: props) => { // State variables const [isLoading, setIsLoading] = useState(false); @@ -65,6 +67,7 @@ export const AdminPanelPoiList = ({ const res = await getPdfById(actualPlaceId, selectedRows); if (res !== null) { setIsPDFViewerActive(true); + setIsWindowsActive(true); setBinaryData(res); } setIsPDFLoading(false); @@ -161,7 +164,7 @@ export const AdminPanelPoiList = ({ )}