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

Reorganizacion de archivos

parent ed1a4d4b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -2,14 +2,13 @@
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
    <link rel="icon" href="%PUBLIC_URL%/logotipo.png" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#000000" />
    <meta
      name="description"
      content="Web site created using create-react-app"
    />
    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
    <!--
      manifest.json provides metadata used when your web app is installed on a
      user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
@@ -24,7 +23,7 @@
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
    <title>React App</title>
    <title>Pueblos Magicos</title>
  </head>
  <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
+12.1 KiB
Loading image diff...
+3 −4
Original line number Diff line number Diff line
import { RouterProvider } from "react-router-dom";
import "./App.css";
import { AuthContextProvider } from "./context/auth_context";
import { MessageContextProvider } from "./context/message_context";
import { router } from "./router/router";
import { AuthContextProvider } from "./core/context/auth_context";
import { MessageContextProvider } from "./core/context/message_context";
import { router } from "./core/router/router";
import { ToastContainer } from "react-toastify";


function App() {
  return (
    <div className="App">
+0 −74
Original line number Diff line number Diff line
import DataTable, { TableColumn } from 'react-data-table-component';
import { usePlace } from '../../../hooks/usePlace';
import './assets/css/styles.css';
import { Place } from '../../../infraestructure/entities/place';
import { LoadingSpinner } from '../../loading_spinner/loading_spinner';
import { faEdit } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { Dispatch, SetStateAction, useEffect } from 'react';

interface props{
  idTown: number;
  isWindowActive: boolean;
  setWindowVisibility: (visibility: boolean) => void;
  setActualPlace: Dispatch<SetStateAction<Place | undefined>>;
  setIsRegisterPane: Dispatch<SetStateAction<boolean>>;
}

export const AdminPanelPlaceList = ({idTown, isWindowActive, setWindowVisibility, setActualPlace, setIsRegisterPane}: props) => {
  const {
    placeList,
    pending,
    updatePlacesByTown
  } = usePlace();

  const handleEditSelectedCategory = (place: Place) => {
    setIsRegisterPane(false);
    setActualPlace(place);
    setWindowVisibility(true);
  }

  useEffect(() => {
    updatePlacesByTown(idTown);
  },[]);
  
  const columns : TableColumn<Place>[] = [
    {
      name: "Identificador", 
      selector: row => row.idPlace || 0
    },
    {
      name: "Nombre", 
      selector: row => row.name,
      sortable: true
    }, 
    {
      name: "Estado", 
      selector: row => row.available
    },
    {
      name: "Acciones",
      cell: (row) => {
        return (
          <FontAwesomeIcon style={isWindowActive ? {color: 'gray'}: {cursor: 'pointer'}} icon={faEdit} 
            onClick={() => {
              if(!isWindowActive){
                handleEditSelectedCategory(row);
              }
            }}
          />
        );
      }
    }
  ];

  return (
    <div className="place_list_cnt">
      <DataTable noDataComponent="No hay lugares que mostrar" progressPending={pending}
        progressComponent={
          <LoadingSpinner style={{display: 'flex'}}/>
        }
        columns={columns} data={placeList} className="data_table"/> 
    </div>
  );
}
 No newline at end of file
+0 −205
Original line number Diff line number Diff line
import { faWindowClose } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { useEffect, useState} from "react";
import "./assets/css/styles.css";
import { languaguesList } from "../../../constants/languages";
import { LoadingScreen } from "../../loading_screen/loading_screen";
import { usePointOfInterest } from "../../../hooks/usePointOfInterest";
import { EmptyPointOfInterest, PointOfInterest } from "../../../infraestructure/entities/poi";
import { ImageDropzone } from "../../image_dropzone/image_dropzone";
import { usePlace } from "../../../hooks/usePlace";

interface props {
  setWindowVisibility: (visibility: boolean) => void;
  idTown: number;
  forceRenderList: () => void;
  isRegister: boolean;
  form?: PointOfInterest;
}

export const AdminPanelPoiRegister = ({setWindowVisibility, idTown,forceRenderList, isRegister, form}: props) => {
  const {
    register,
    errors,
    setDescriptions,
    setDirections,
    descriptions,
    directions,
    setLanguageDescriptionIndexSelected,
    handleSubmit,
    onSubmitRegister,
    getPointById,
    setValue,
    languageDescriptionIndexSelected,
    languageDirectionsIndexSelected,
    setLanguageDirectionsIndexSelected,
  } = usePointOfInterest(forceRenderList, setWindowVisibility);  
  const [isLoading, setIsLoading] = useState(false);
  const [preview, setPreview] = useState<string | ArrayBuffer | null>(null);
  const [image, setImage] = useState<File | null>(null);
  const {
    placeList,
    updatePlacesByTown
  } = usePlace();

  useEffect(() => {
    if(image){
      setValue('image', image, {shouldValidate: true});
    }
  },[image]);

  useEffect(() => {
    setIsLoading(true);
    const fetchData = async () => {
      await updatePlacesByTown(idTown);
      if (!isRegister && form) {
        const pointGetted = await getPointById(form.idPoint || 0);
        if(pointGetted){
          setValue('idPoint', pointGetted.idPlace);
          setValue('name', pointGetted.name);
          setValue('contentEN', pointGetted.contentEN);
          setValue('contentES', pointGetted.contentES);
          setValue('directionsEN', pointGetted.directionsEN);
          setValue('directionsES', pointGetted.directionsES);
        }
      }
    };
    fetchData();
    setIsLoading(false);
  },[]);

  return (
    <div className="poi_register_wrap">
      <div className="poi_register_header">
        Registra el punto de interés
        <FontAwesomeIcon icon={faWindowClose} className="close_btn"
          onClick={() => setWindowVisibility(false)}/>
      </div>
      <div className="poi_register_body">
        {isLoading
            ?
              <LoadingScreen/>
            :
        <form onSubmit={handleSubmit(onSubmitRegister)}>
          <div className="inputs_container">
            <div className="input">
              <div className="input_header">
                Nombre del punto de interés
              </div>
              <input 
                type="text"
                {...register('name')}
                autoComplete="off"
              />
              <p className="error">{errors.name?.message}</p>
            </div>

            <div className="input">
              <div className="input_header">
                Descripción del punto de interés
                <select  name="language_description_select" onChange={(e) => setLanguageDescriptionIndexSelected(Number(e.target.value))}>
                    {languaguesList.map((language, index) => {
                      return (
                        <option key={index} value={index}>{language}</option>
                      );
                    })}
                </select>
              </div>
              {
                languaguesList.map((language, index) => {
                    if(index===languageDescriptionIndexSelected){
                      return (
                        <textarea id={index.toString()} 
                          className="poi_description"
                          value={descriptions[index]}
                          key={language}
                          onChange={(e) => {
                            const updatedDescriptionsList = [...descriptions];
                            updatedDescriptionsList[index] = e.target.value;
                            setDescriptions(updatedDescriptionsList);
                            if(index===0){
                              setValue('contentES', updatedDescriptionsList[index], {shouldValidate: true});
                            }else{
                              setValue('contentEN', updatedDescriptionsList[index], {shouldValidate: true});
                            }
                          }}
                        />
                    );
                    }
                })
              }
              <p className="error">{errors.contentEN?.message || errors.contentES?.message}</p>
            </div>

            <div className="input">
              <div className="input_header">
                Direcciones hacia el siguiente punto de interés
                <select  name="language_description_select" onChange={(e) => setLanguageDirectionsIndexSelected(Number(e.target.value))}>
                    {languaguesList.map((language, index) => {
                      return (
                        <option key={index} value={index}>{language}</option>
                      );
                    })}
                </select>
              </div>
              {
                languaguesList.map((language, index) => {
                    if(index===languageDirectionsIndexSelected){
                      return (
                        <textarea id={index.toString()} 
                          className="poi_description"
                          value={directions[index]}
                          key={language}
                          onChange={(e) => {
                            const updatedDirectionsList = [...directions];
                            updatedDirectionsList[index] = e.target.value;
                            setDirections(updatedDirectionsList);
                            if(index===0){
                              setValue('directionsES', updatedDirectionsList[index], {shouldValidate: true});
                            }else{
                              setValue('directionsEN', updatedDirectionsList[index], {shouldValidate: true});
                            }
                          }}
                        />
                    );
                    }
                })
              }
              <p className="error">{errors.directionsEN?.message || errors.directionsES?.message}</p>
            </div>

            <div className="place_select">
              <label>Lugar al que pertenece el punto de interés</label>
              {placeList === null || placeList.length===0 ? 
                <option disabled defaultValue="" value="">No hay lugares</option>
              : 
                <select
                  {...register('idPlace')}>
                  <>
                    <option disabled selected={isRegister} value="">Selecciona el lugar</option>
                    {placeList.map((place) => {
                    return (
                      <option key={place.idPlace} selected={place.idPlace===form?.idPlace} value={place.idPlace}>{place.name}</option>
                    );
                    })}
                  </>
                </select>
              }
              <p className="error">{errors.idPlace?.message}</p>
            </div>

            <input type="submit"/>
          </div>
          <div className="image_cnt">
              <div className="input_header">
                Imagén relacionada
              </div>
            <ImageDropzone setImage={setImage} preview={preview} setPreview={setPreview}/>
            <p className="error">{errors.image?.message}</p>
          </div>
        </form>
        }
      </div>
    </div>
  );
}
 No newline at end of file
Loading