Commit 29ad32de authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files
parents 887f7e59 235fe434
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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<AdminFormValues> = async (data) => {
  const errors: FieldErrors<AdminFormValues> = {};
@@ -119,6 +121,13 @@ export const useAdmin = (

  // Handle form submission
  const onSubmit: SubmitHandler<AdminFormValues> = (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);
+8 −0
Original line number Diff line number Diff line
@@ -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<CategoryFormValues> = (
    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(() => {
+15 −0
Original line number Diff line number Diff line
@@ -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<Town> = async (data) => {
  const errors: FieldErrors<Town> = {};
@@ -95,6 +97,12 @@ export const useTown = (

  // Function to handle town registration
  const onSubmitRegister: SubmitHandler<Town> = (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<Town> = (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);
+12 −10
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ export const AdminTownInfo = ({
                  }}
                />
              </div>
              {!isLoading && (
                <FontAwesomeIcon
                  style={{ cursor: "pointer" }}
                  icon={faEdit}
@@ -121,6 +122,7 @@ export const AdminTownInfo = ({
                    }
                  }}
                />
              )}
            </div>
            {isEnglish ? (
              <textarea