Commit ad35a544 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Correccion de errores

parent 1fa58b65
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ import { showErrorAxios } from "../../core/utils/Messages";
const placeDatasouce = new PlaceDatasourceProd();
const placeRepository = new PlaceRepositoryProd(placeDatasouce);

let lastSubmitTime = 0;

// Define resolver for form validation
const resolver: Resolver<Place> = async (data) => {
  const errors: FieldErrors<Place> = {};
@@ -199,6 +201,13 @@ export const usePlace = (

  // Handle form submission for registering a place
  const onSubmitRegister: SubmitHandler<Place> = (data: Place) => {
    const currentTime = Date.now();
    if (currentTime - lastSubmitTime < 5000) {
      toast.error("Debe esperar 5 segundos entre ejecuciones.");
      return;
    }
    lastSubmitTime = currentTime;

    const fetch = async () => {
      try {
        await placeRepository.registerPlace(data).then(() => {
@@ -212,12 +221,12 @@ export const usePlace = (
        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);
@@ -244,6 +253,13 @@ export const usePlace = (

  // Handle form submission for updating a place
  const onSubmitUpdate: SubmitHandler<Place> = (data: Place) => {
    const currentTime = Date.now();
    if (currentTime - lastSubmitTime < 5000) {
      toast.error("Debe esperar 5 segundos entre ejecuciones.");
      return;
    }
    lastSubmitTime = currentTime;

    const fetch = async () => {
      try {
        await placeRepository.updatePlace(data);
@@ -256,12 +272,12 @@ export const usePlace = (
        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);
+9 −0
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ import { showErrorAxios } from "../../core/utils/Messages";
const POIDatasouce = new POIDatasourceProd();
const POIRepository = new POIRepositoryProd(POIDatasouce);

let lastSubmitTime = 0;

// Custom hook for point of interest functionality
export const usePointOfInterest = (
  forceRenderList?: () => void,
@@ -145,6 +147,13 @@ export const usePointOfInterest = (
  const onSubmitRegister: SubmitHandler<PointOfInterest> = (
    data: PointOfInterest
  ) => {
    const currentTime = Date.now();
    if (currentTime - lastSubmitTime < 5000) {
      toast.error("Debe esperar 5 segundos entre ejecuciones.");
      return;
    }
    lastSubmitTime = currentTime;

    const fetch = async () => {
      try {
        await POIRepository.registerPoint(data).then(() => {
+3 −3
Original line number Diff line number Diff line
@@ -48,9 +48,9 @@ export const AdminPanelPlaceList = ({
  // Function to delete the selected place with a toast notification
  const deleteSelectedPlace = (place: Place) => {
    toast.promise(deletePlace(place.idPlace || -1), {
      pending: "Eliminando categoría...",
      success: "La categoría se ha eliminado correctamente",
      error: "No se pudo eliminar la categoría",
      pending: "Eliminando lugar...",
      success: "El lugar se ha eliminado correctamente",
      error: "No se pudo eliminar el lugar",
    });
  };

+7 −2
Original line number Diff line number Diff line
@@ -154,7 +154,7 @@ export const AdminPanelPlaceRegister = ({
  return (
    <div className="place_register_wrap">
      <div className="place_register_header">
        Registra el lugar
        {isRegister ? "Registra" : "Actualiza"} el lugar
        <FontAwesomeIcon
          icon={faWindowClose}
          className="close_btn"
@@ -173,7 +173,12 @@ export const AdminPanelPlaceRegister = ({
            <div className="inputs_container">
              <div className="input">
                <div className="input_header">Nombre del lugar</div>
                <input type="text" {...register("name")} autoComplete="off" maxLength={255}/>
                <input
                  type="text"
                  {...register("name")}
                  autoComplete="off"
                  maxLength={255}
                />
                <p className="error">{errors.name?.message}</p>
              </div>

+16 −14
Original line number Diff line number Diff line
@@ -11,10 +11,11 @@
  margin: auto;
  width: 30vw;
  height: 70vh;
  background: green;
  background: white;
  display: flex;
  z-index: 999;
  flex-direction: column;
  border: solid 2px black;
}

.admin_register_header {
@@ -23,6 +24,7 @@
  align-items: center;
  justify-content: center;
  padding: 5px;
  background: #ccc;
}

.admin_register_close_btn {