From c55561f91f6f53243ec98e23198da3875d7e77a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 13 Nov 2024 22:04:52 -0600 Subject: [PATCH] Correccion de errores --- web/src/domain/useCase/useAdmin.ts | 9 ++++++++ web/src/domain/useCase/useCategory.ts | 8 +++++++ web/src/domain/useCase/useTown.ts | 15 +++++++++++++ .../admin/admin_town_info/admin_town_info.tsx | 22 ++++++++++--------- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/web/src/domain/useCase/useAdmin.ts b/web/src/domain/useCase/useAdmin.ts index 9e3e0bb3..476e3601 100644 --- a/web/src/domain/useCase/useAdmin.ts +++ b/web/src/domain/useCase/useAdmin.ts @@ -15,6 +15,8 @@ import { showErrorAxios } from "../../core/utils/Messages"; const adminDatasource = new AdminDatasourceProd(); const adminRepository = new AdminRepositoryProd(adminDatasource); +let lastSubmitTime = 0; + // Define resolver for form validation const resolver: Resolver = async (data) => { const errors: FieldErrors = {}; @@ -119,6 +121,13 @@ export const useAdmin = ( // Handle form submission const onSubmit: SubmitHandler = (data: AdminFormValues) => { + const currentTime = Date.now(); + if (currentTime - lastSubmitTime < 5000) { + toast.error("Debe esperar 5 segundos entre ejecuciones."); + return; + } + lastSubmitTime = currentTime; + const fetch = async () => { try { await adminRepository.registerAdmin(data); diff --git a/web/src/domain/useCase/useCategory.ts b/web/src/domain/useCase/useCategory.ts index dcd6447a..92d3e522 100644 --- a/web/src/domain/useCase/useCategory.ts +++ b/web/src/domain/useCase/useCategory.ts @@ -11,6 +11,8 @@ import { toast } from "react-toastify"; import { useEffect, useState } from "react"; import { showErrorAxios } from "../../core/utils/Messages"; +let lastSubmitTime = 0; + // Initialize data source and repository for categories const categoryDatasource = new CategoryDatasourceProd(); const categoryRepository = new CategoryRepositoryProd(categoryDatasource); @@ -73,6 +75,12 @@ export const useCategory = ( const onSubmit: SubmitHandler = ( data: CategoryFormValues ) => { + const currentTime = Date.now(); + if (currentTime - lastSubmitTime < 5000) { + toast.error("Debe esperar 5 segundos entre ejecuciones."); + return; + } + lastSubmitTime = currentTime; const fetch = async () => { try { await categoryRepository.registerCategory(data).then(() => { diff --git a/web/src/domain/useCase/useTown.ts b/web/src/domain/useCase/useTown.ts index f973de84..6fd43699 100644 --- a/web/src/domain/useCase/useTown.ts +++ b/web/src/domain/useCase/useTown.ts @@ -13,6 +13,8 @@ import { useGetStatesList } from "./useGetStatesList"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); +let lastSubmitTime = 0; + // Define resolver for form validation const resolver: Resolver = async (data) => { const errors: FieldErrors = {}; @@ -95,6 +97,12 @@ export const useTown = ( // Function to handle town registration const onSubmitRegister: SubmitHandler = (data: Town) => { + const currentTime = Date.now(); + if (currentTime - lastSubmitTime < 5000) { + toast.error("Debe esperar 5 segundos entre ejecuciones."); + return; + } + lastSubmitTime = currentTime; const fetch = async () => { try { await townRepository.registerTown(data); @@ -131,6 +139,13 @@ export const useTown = ( // Function to handle town update const onSubmitUpdate: SubmitHandler = (data: Town) => { + const currentTime = Date.now(); + if (currentTime - lastSubmitTime < 5000) { + toast.error("Debe esperar 5 segundos entre ejecuciones."); + return; + } + lastSubmitTime = currentTime; + const fetch = async () => { try { await townRepository.updateTown(data); 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 3186b1b7..5ca208e3 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 @@ -111,16 +111,18 @@ export const AdminTownInfo = ({ }} /> - { - if (!isWindowActive) { - setWindowVisibility(true); - } - }} - /> + {!isLoading && ( + { + if (!isWindowActive) { + setWindowVisibility(true); + } + }} + /> + )} {isEnglish ? (