From 38f983db5c00d482f7c892c89b7e5e20333077f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 14 Nov 2024 10:31:24 -0600 Subject: [PATCH 1/3] Correcion de error de carga infinita --- web/src/domain/useCase/useAdminHomePage.ts | 2 +- web/src/domain/useCase/useAdminTownInfo.ts | 23 ++++++------- .../admin/admin_town_info/admin_town_info.tsx | 34 ++++--------------- .../admin/panel/admin_home_page.tsx | 1 + 4 files changed, 19 insertions(+), 41 deletions(-) diff --git a/web/src/domain/useCase/useAdminHomePage.ts b/web/src/domain/useCase/useAdminHomePage.ts index e50539fc..c0f8ccd0 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 5b1fed51..1547ccb1 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/presentation/admin/admin_town_info/admin_town_info.tsx b/web/src/presentation/admin/admin_town_info/admin_town_info.tsx index 5ca208e3..c3609171 100644 --- a/web/src/presentation/admin/admin_town_info/admin_town_info.tsx +++ b/web/src/presentation/admin/admin_town_info/admin_town_info.tsx @@ -13,6 +13,7 @@ interface props { setIsWindowActive: Dispatch>; town: Town | undefined; updateTown: () => Promise; + isLoading: boolean; } // Main component function @@ -21,17 +22,11 @@ export const AdminTownInfo = ({ isWindowActive, setIsWindowActive, town, + isLoading, }: props) => { // Destructure values from the custom hook - const { - isEnglish, - isLoading, - setIsEnglish, - setIsLoading, - renderCount, - forceRenderList, - statesList, - } = useAdminTownInfo(updateTown); + const { isEnglish, setIsEnglish, renderCount, forceRenderList, statesList } = + useAdminTownInfo(updateTown); // State to manage the visibility of the town register window const [isTownRegisterWindowActive, setIsTownRegisterWindowActive] = @@ -59,6 +54,8 @@ export const AdminTownInfo = ({ ); } + if (isLoading) return ; + // Main render of the component return (
@@ -73,29 +70,12 @@ export const AdminTownInfo = ({ /> )}
- {isLoading && ( -
- -
- )} -

{town?.name}

- setIsLoading(false)} - alt="" - /> +
diff --git a/web/src/presentation/admin/panel/admin_home_page.tsx b/web/src/presentation/admin/panel/admin_home_page.tsx index 13e47c89..4fdff781 100644 --- a/web/src/presentation/admin/panel/admin_home_page.tsx +++ b/web/src/presentation/admin/panel/admin_home_page.tsx @@ -114,6 +114,7 @@ export const AdminHomePage = () => { setIsWindowActive={setIsWindowActive} isWindowActive={isWindowActive} town={town} + isLoading={isLoading} /> ); case AdminSelectedPanel.PLACES: -- GitLab From 77372c15cc3a042ccdd704843f3bf51339e40d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 14 Nov 2024 10:58:13 -0600 Subject: [PATCH 2/3] Correcion de mensajes de error --- web/src/core/utils/Messages.ts | 15 ++++++--------- web/src/domain/useCase/useCategory.ts | 6 +++--- web/src/domain/useCase/useLogin.ts | 12 ++++++------ web/src/domain/useCase/useResetPassword.ts | 7 ++++--- web/src/domain/useCase/useTown.ts | 7 ++++--- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/web/src/core/utils/Messages.ts b/web/src/core/utils/Messages.ts index 5418bbc4..96411d2b 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/useCategory.ts b/web/src/domain/useCase/useCategory.ts index 92d3e522..3b5845e3 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 04705892..13214acf 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 f38fa20d..147bbbe9 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 6fd43699..82d7b848 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); -- GitLab From a8fe68129fe57992935c917dd2f6f2d91a0c222b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 14 Nov 2024 10:58:24 -0600 Subject: [PATCH 3/3] Correcion de vista de pdf --- .../admin_panel_poi_list/admin_panel_poi_list.tsx | 5 ++++- .../admin_panel_poi_screen/admin_panel_poi_screen.tsx | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) 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 ef5dfa96..086ceb60 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 = ({ )}