diff --git a/web/src/domain/useCase/useAdmin.ts b/web/src/domain/useCase/useAdmin.ts index 9e3e0bb35e1d03e5bc7700490fd7d45abedeb629..476e36018ffac5cc1fee53fcc32b04786d936ede 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 dcd6447a38e456f3649e10f63dd902792bdc4438..92d3e52254baa8a52d0b4f6624bb36018ef1778c 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 f973de8463db7c1cad54ab211e55de46ac6d45dd..6fd43699d3684b858de8164de4c81f80522d94ae 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 3186b1b783845077155625046060f9dc94e9b125..5ca208e3312abae56b099fcf5f542a406517ee73 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 ? (