From 0674c0cd3e93ee34f76d591784199bbb0dd45c7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 12:44:48 -0600 Subject: [PATCH 01/60] Se renombro el nombre de la interface --- web/src/components/map/map.tsx | 4 +- .../multiple_images_dropzone.tsx | 4 +- .../data/datasources/prod/place_datasource.ts | 4 +- .../repositories/prod/place_repository.ts | 4 +- web/src/hooks/useDropzoneMultiplesImages.tsx | 4 +- web/src/hooks/usePlaceRegister.tsx | 43 ++++++++----------- .../datasources/place_datasource.ts | 4 +- web/src/infraestructure/entities/place.ts | 3 +- .../repositories/place_repository.ts | 4 +- 9 files changed, 35 insertions(+), 39 deletions(-) diff --git a/web/src/components/map/map.tsx b/web/src/components/map/map.tsx index d1c45e29..8af74acb 100644 --- a/web/src/components/map/map.tsx +++ b/web/src/components/map/map.tsx @@ -3,10 +3,10 @@ import { useState, useMemo } from "react"; import { REACT_APP_GOOGLE_API_KEY } from "../../constants/api_keys"; import { LoadingScreen } from "../loading_screen/loading_screen"; import { UseFormSetValue } from "react-hook-form"; -import { PlaceFormValues } from "../../infraestructure/entities/place"; +import { Place } from "../../infraestructure/entities/place"; interface props{ - setValue: UseFormSetValue; + setValue: UseFormSetValue; } export const MapComponent = ({setValue}: props) => { diff --git a/web/src/components/multiple_images_dropzone/multiple_images_dropzone.tsx b/web/src/components/multiple_images_dropzone/multiple_images_dropzone.tsx index 72daeca9..06f5357a 100644 --- a/web/src/components/multiple_images_dropzone/multiple_images_dropzone.tsx +++ b/web/src/components/multiple_images_dropzone/multiple_images_dropzone.tsx @@ -1,12 +1,12 @@ import { UseFormSetValue } from "react-hook-form"; -import { PlaceFormValues } from "../../infraestructure/entities/place"; +import { Place } from "../../infraestructure/entities/place"; import { useDropzoneMultiplesImages } from "../../hooks/useDropzoneMultiplesImages"; import "./assets/css/styles.css"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faTimesCircle } from "@fortawesome/free-solid-svg-icons"; interface props{ - setValue: UseFormSetValue; + setValue: UseFormSetValue; } export const MultipleImagesDropzone = ({setValue}:props) => { diff --git a/web/src/data/datasources/prod/place_datasource.ts b/web/src/data/datasources/prod/place_datasource.ts index ff214c3b..84d5ab90 100644 --- a/web/src/data/datasources/prod/place_datasource.ts +++ b/web/src/data/datasources/prod/place_datasource.ts @@ -1,10 +1,10 @@ import axios from "axios"; import { APIUrl } from "../../../constants/api_url"; import { PlaceDatasourceInf } from "../../../infraestructure/datasources/place_datasource"; -import { AvailableDays, PlaceFormValues } from "../../../infraestructure/entities/place"; +import { AvailableDays, Place } from "../../../infraestructure/entities/place"; export class PlaceDatasourceProd implements PlaceDatasourceInf{ - async registerPlace(form: PlaceFormValues): Promise { + async registerPlace(form: Place): Promise { const formToSend = new FormData(); formToSend.append('available', form.available); formToSend.append('idTown', String(form.idTown)); diff --git a/web/src/data/repositories/prod/place_repository.ts b/web/src/data/repositories/prod/place_repository.ts index 25da3777..7a7b3ffe 100644 --- a/web/src/data/repositories/prod/place_repository.ts +++ b/web/src/data/repositories/prod/place_repository.ts @@ -1,12 +1,12 @@ import { PlaceDatasourceInf } from "../../../infraestructure/datasources/place_datasource"; -import { PlaceFormValues } from "../../../infraestructure/entities/place"; +import { Place } from "../../../infraestructure/entities/place"; import { PlaceRepositoryInf } from "../../../infraestructure/repositories/place_repository"; export class PlaceRepositoryProd implements PlaceRepositoryInf{ constructor( private datasouce: PlaceDatasourceInf ){} - async registerPlace(form: PlaceFormValues): Promise { + async registerPlace(form: Place): Promise { return this.datasouce.registerPlace(form); } } \ No newline at end of file diff --git a/web/src/hooks/useDropzoneMultiplesImages.tsx b/web/src/hooks/useDropzoneMultiplesImages.tsx index ac96f91a..1c0b562d 100644 --- a/web/src/hooks/useDropzoneMultiplesImages.tsx +++ b/web/src/hooks/useDropzoneMultiplesImages.tsx @@ -3,9 +3,9 @@ import { useDropzone } from "react-dropzone"; import { toast } from "react-toastify"; import { Image } from "../infraestructure/entities/image"; import { UseFormSetValue } from "react-hook-form"; -import { PlaceFormValues } from "../infraestructure/entities/place"; +import { Place } from "../infraestructure/entities/place"; -export const useDropzoneMultiplesImages = (setValue: UseFormSetValue) => { +export const useDropzoneMultiplesImages = (setValue: UseFormSetValue) => { const [imagesFiles, setImagesFiles] = useState([]); const [files, setFiles] = useState([]); const MAX_SIZE = 10485760; diff --git a/web/src/hooks/usePlaceRegister.tsx b/web/src/hooks/usePlaceRegister.tsx index 6fb19965..77271e4f 100644 --- a/web/src/hooks/usePlaceRegister.tsx +++ b/web/src/hooks/usePlaceRegister.tsx @@ -1,5 +1,5 @@ import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form" -import { PlaceFormValues, AvailableDays } from "../infraestructure/entities/place"; +import { Place, AvailableDays } from "../infraestructure/entities/place"; import { toast } from "react-toastify"; import { useEffect, useState } from "react"; import axios, { AxiosError } from "axios"; @@ -9,12 +9,13 @@ import { useTown } from "./useTown"; import { MIN_NUMBER_PLACE_IMAGES } from "../constants/images_nuber"; import { PlaceDatasourceProd } from "../data/datasources/prod/place_datasource"; import { PlaceRepositoryProd } from "../data/repositories/prod/place_repository"; +import { showErrorAxios } from "../utils/Messages"; const placeDatasouce = new PlaceDatasourceProd(); const placeRepository = new PlaceRepositoryProd(placeDatasouce); -const resolver: Resolver = async (data) => { - const errors: FieldErrors = {}; +const resolver: Resolver = async (data) => { + const errors: FieldErrors = {}; if(!data.idTown){ errors.idTown = { @@ -129,7 +130,7 @@ export const usePlaceRegister = () => { formState: {errors}, clearErrors, resetField, - } = useForm({resolver}); + } = useForm({resolver}); const [errorMessage, setErrorMessage] = useState(""); const [languageDescriptionIndexSelected, setLanguageDescriptionIndexSelected] = useState(0); const [descriptions, setDescriptions] = useState(new Array(languaguesList.length).fill("")); @@ -146,25 +147,7 @@ export const usePlaceRegister = () => { }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; - let message = ""; - switch(error.code){ - case(axios.AxiosError.ERR_BAD_REQUEST): - message = "Acceso no autorizado"; - break; - case(axios.AxiosError.ERR_NETWORK): - message = "Conexión con el servidor fallida"; - break; - } - toast.error(message, { - position: "bottom-right", - autoClose: 1500, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: false, - draggable: true, - progress: undefined, - theme: "colored" - }); + showErrorAxios(error); } } } @@ -177,7 +160,7 @@ export const usePlaceRegister = () => { getTownsByState(idState, stateName); } - const onSubmit : SubmitHandler = (data: PlaceFormValues) => { + const onSubmit : SubmitHandler = (data: Place) => { const fetch = async () => { try{ await placeRepository.registerPlace(data); @@ -218,6 +201,18 @@ export const usePlaceRegister = () => { } } + const getPlacesByTown = async (idTown: number) => { + try{ + const towns = await townRepository.getTownsByState(stateId, stateName); + setTownsList(towns); + }catch(error: any){ + if(axios.isAxiosError(error)){ + error as AxiosError; + showErrorAxios(error); + } + } + } + return { register, handleSubmit, diff --git a/web/src/infraestructure/datasources/place_datasource.ts b/web/src/infraestructure/datasources/place_datasource.ts index a49a2128..14e62c49 100644 --- a/web/src/infraestructure/datasources/place_datasource.ts +++ b/web/src/infraestructure/datasources/place_datasource.ts @@ -1,5 +1,5 @@ -import { PlaceFormValues } from "../entities/place"; +import { Place } from "../entities/place"; export interface PlaceDatasourceInf{ - registerPlace(form: PlaceFormValues): Promise; + registerPlace(form: Place): Promise; } \ No newline at end of file diff --git a/web/src/infraestructure/entities/place.ts b/web/src/infraestructure/entities/place.ts index 6c983762..924cd7f1 100644 --- a/web/src/infraestructure/entities/place.ts +++ b/web/src/infraestructure/entities/place.ts @@ -1,5 +1,6 @@ -export interface PlaceFormValues{ +export interface Place{ idTown: number; + idPlace? : number; name: string; descriptions: string[]; latitude: number; diff --git a/web/src/infraestructure/repositories/place_repository.ts b/web/src/infraestructure/repositories/place_repository.ts index 42267ef1..7cf06582 100644 --- a/web/src/infraestructure/repositories/place_repository.ts +++ b/web/src/infraestructure/repositories/place_repository.ts @@ -1,5 +1,5 @@ -import { PlaceFormValues } from "../entities/place"; +import { Place } from "../entities/place"; export interface PlaceRepositoryInf{ - registerPlace(form: PlaceFormValues): Promise; + registerPlace(form: Place): Promise; } \ No newline at end of file -- GitLab From 9022f2341c269bed115b2eb06ae4cd47e6d9f83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:01:01 -0600 Subject: [PATCH 02/60] Se crea un componente para un loader --- .../loading_spinner/loading_spinner.tsx | 7 +++++++ web/src/components/loading_spinner/styles.css | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 web/src/components/loading_spinner/loading_spinner.tsx create mode 100644 web/src/components/loading_spinner/styles.css diff --git a/web/src/components/loading_spinner/loading_spinner.tsx b/web/src/components/loading_spinner/loading_spinner.tsx new file mode 100644 index 00000000..6fda4358 --- /dev/null +++ b/web/src/components/loading_spinner/loading_spinner.tsx @@ -0,0 +1,7 @@ +import React, { HTMLAttributes } from "react"; + +export const LoadingSpinner :React.FC> = () => { + return ( +
+ ); +} \ No newline at end of file diff --git a/web/src/components/loading_spinner/styles.css b/web/src/components/loading_spinner/styles.css new file mode 100644 index 00000000..17bf1b10 --- /dev/null +++ b/web/src/components/loading_spinner/styles.css @@ -0,0 +1,17 @@ +.loading_spinner{ + z-index: 999; + width: 150px; + padding: 20px; + aspect-ratio: 1; + border-radius: 50%; + background: #25b09b; + --_m: + conic-gradient(#0000 10%,#000), + linear-gradient(#000 0 0) content-box; + -webkit-mask: var(--_m); + mask: var(--_m); + -webkit-mask-composite: source-out; + mask-composite: subtract; + animation: l3 1s infinite linear; +} +@keyframes l3 {to{transform: rotate(1turn)}} \ No newline at end of file -- GitLab From 5d3f79f4c6dd8a4ba5af1036be9c34924213db23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:08:23 -0600 Subject: [PATCH 03/60] Se renombra el hook --- .../{usePlaceRegister.tsx => usePlace.tsx} | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) rename web/src/hooks/{usePlaceRegister.tsx => usePlace.tsx} (93%) diff --git a/web/src/hooks/usePlaceRegister.tsx b/web/src/hooks/usePlace.tsx similarity index 93% rename from web/src/hooks/usePlaceRegister.tsx rename to web/src/hooks/usePlace.tsx index 77271e4f..9476cbc0 100644 --- a/web/src/hooks/usePlaceRegister.tsx +++ b/web/src/hooks/usePlace.tsx @@ -122,7 +122,7 @@ const resolver: Resolver = async (data) => { }; }; -export const usePlaceRegister = () => { +export const usePlace = () => { const { register, handleSubmit, @@ -135,9 +135,11 @@ export const usePlaceRegister = () => { const [languageDescriptionIndexSelected, setLanguageDescriptionIndexSelected] = useState(0); const [descriptions, setDescriptions] = useState(new Array(languaguesList.length).fill("")); const [availableDays, setAvailableDays] = useState(AvailableDays.WEEKEND); + const [placeList, setPlaceList] = useState([]); const [isLoading, setIsLoading] = useState(false); const {townsList, getTownsByState} = useTown(); const {getStates, statesList} = useGetStatesList(); + const [pending, setPending] = useState(false); useEffect(() => { setIsLoading(true); @@ -201,15 +203,18 @@ export const usePlaceRegister = () => { } } - const getPlacesByTown = async (idTown: number) => { + const updatePlacesByTown = async (idTown: number) => { + setPending(true); try{ - const towns = await townRepository.getTownsByState(stateId, stateName); - setTownsList(towns); + const places = await placeRepository.getPlacesByTown(idTown); + setPlaceList(places); + setPending(false); }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; showErrorAxios(error); } + setPending(false); } } @@ -231,6 +236,9 @@ export const usePlaceRegister = () => { updateTimeForm, availableDays, setAvailableDays, - resetField + resetField, + updatePlacesByTown, + placeList, + pending }; } -- GitLab From d8e9e0bc1c4f2cb5eb2976d8454b54655f7bc0ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:08:46 -0600 Subject: [PATCH 04/60] =?UTF-8?q?Se=20crea=20una=20funci=C3=B3n=20para=20m?= =?UTF-8?q?ostrar=20mensajes=20de=20error=20de=20axios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/utils/Messages.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 web/src/utils/Messages.ts diff --git a/web/src/utils/Messages.ts b/web/src/utils/Messages.ts new file mode 100644 index 00000000..24ddcb8d --- /dev/null +++ b/web/src/utils/Messages.ts @@ -0,0 +1,24 @@ +import axios, { AxiosError } from "axios"; +import { toast } from "react-toastify"; + +export const showErrorAxios = (error: AxiosError) => { + let message = ""; + switch(error.code){ + case(axios.AxiosError.ERR_BAD_REQUEST): + message = "Acceso no autorizado"; + break; + case(axios.AxiosError.ERR_NETWORK): + message = "Conexión con el servidor fallida"; + break; + } + toast.error(message, { + position: "bottom-right", + autoClose: 1500, + hideProgressBar: false, + closeOnClick: true, + pauseOnHover: false, + draggable: true, + progress: undefined, + theme: "colored" + }); +} \ No newline at end of file -- GitLab From 2779dc7f57d68effff41b2d93bd7204181495622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:09:09 -0600 Subject: [PATCH 05/60] Se modifican algunos campos --- web/src/infraestructure/entities/place.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/infraestructure/entities/place.ts b/web/src/infraestructure/entities/place.ts index 924cd7f1..67669276 100644 --- a/web/src/infraestructure/entities/place.ts +++ b/web/src/infraestructure/entities/place.ts @@ -2,13 +2,13 @@ export interface Place{ idTown: number; idPlace? : number; name: string; - descriptions: string[]; + descriptions?: string[]; latitude: number; longitude: number; openAt: number; closeAt: number; available: AvailableDays; - imagesList: File[]; + imagesList?: File[]; startDate?: Date; endDate?: Date; } -- GitLab From 7071b00671a0280190e36fde40aff6859529b9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:09:43 -0600 Subject: [PATCH 06/60] Se crea un modelo del lugar que se obtiene en las peticiones a la API --- web/src/data/models/prod/PlaceModel.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 web/src/data/models/prod/PlaceModel.ts diff --git a/web/src/data/models/prod/PlaceModel.ts b/web/src/data/models/prod/PlaceModel.ts new file mode 100644 index 00000000..b201143a --- /dev/null +++ b/web/src/data/models/prod/PlaceModel.ts @@ -0,0 +1,14 @@ +export interface PlaceModel { + idTown: number; + idPlace: number; + available: string; + description: string; + latitude: number; + longitude: number; + imageName: string; + name: string; + openAt: number; + closeAt: number; + startDate?: Date; + endDate?: Date; +} \ No newline at end of file -- GitLab From 7d8e0613bca68ff93849055b4cee00b90f17e4db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:10:38 -0600 Subject: [PATCH 07/60] =?UTF-8?q?Se=20crea=20la=20l=C3=B3gica=20para=20obt?= =?UTF-8?q?ener=20los=20lugares=20de=20un=20pueblo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasources/prod/place_datasource.ts | 46 +++++++++++++++++-- .../repositories/prod/place_repository.ts | 4 ++ .../datasources/place_datasource.ts | 1 + .../repositories/place_repository.ts | 1 + 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/web/src/data/datasources/prod/place_datasource.ts b/web/src/data/datasources/prod/place_datasource.ts index 84d5ab90..353e38e7 100644 --- a/web/src/data/datasources/prod/place_datasource.ts +++ b/web/src/data/datasources/prod/place_datasource.ts @@ -2,6 +2,7 @@ import axios from "axios"; import { APIUrl } from "../../../constants/api_url"; import { PlaceDatasourceInf } from "../../../infraestructure/datasources/place_datasource"; import { AvailableDays, Place } from "../../../infraestructure/entities/place"; +import { PlaceModel } from "../../models/prod/PlaceModel"; export class PlaceDatasourceProd implements PlaceDatasourceInf{ async registerPlace(form: Place): Promise { @@ -9,9 +10,9 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ formToSend.append('available', form.available); formToSend.append('idTown', String(form.idTown)); formToSend.append('name', form.name); - formToSend.append('descriptionES', form.descriptions[0]); - formToSend.append('descriptionEN', form.descriptions[1]); - formToSend.append('image', form.imagesList[0]); + formToSend.append('descriptionES', form.descriptions?.[0] ?? ''); + formToSend.append('descriptionEN', form.descriptions?.[1] ?? ''); + formToSend.append('image', form.imagesList?.[0] ?? ''); formToSend.append('latitude', String(form.latitude)); formToSend.append('longitude', String(form.longitude)); formToSend.append('openAt', String(form.openAt)); @@ -28,4 +29,43 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ await axios.post(APIUrl + '/place', formToSend,{headers}); } + + async getPlacesByTown(idTown: number): Promise { + const {data} = await axios.get(APIUrl+`/place/town/${idTown}/place`, { + params: { + lang: 'ES' + } + }); + const places = data.map((value) => { + let availableDays = AvailableDays.WEEKEND; + switch(value.available){ + case AvailableDays.ALL_DAYS: + availableDays = AvailableDays.ALL_DAYS; + break; + case AvailableDays.CUSTOM: + availableDays = AvailableDays.CUSTOM; + break; + case AvailableDays.WEEKDAYS: + availableDays = AvailableDays.WEEKDAYS; + break; + default: + availableDays = AvailableDays.WEEKEND; + break; + } + + const place: Place = { + idTown : value.idTown, + idPlace : value.idPlace, + available : availableDays, + latitude: value.latitude, + longitude: value.longitude, + name: value.name, + openAt: value.openAt, + closeAt: value.closeAt + } + return place; + }) + + return places; + } } \ No newline at end of file diff --git a/web/src/data/repositories/prod/place_repository.ts b/web/src/data/repositories/prod/place_repository.ts index 7a7b3ffe..3f60490e 100644 --- a/web/src/data/repositories/prod/place_repository.ts +++ b/web/src/data/repositories/prod/place_repository.ts @@ -9,4 +9,8 @@ export class PlaceRepositoryProd implements PlaceRepositoryInf{ async registerPlace(form: Place): Promise { return this.datasouce.registerPlace(form); } + + async getPlacesByTown(idTown: number): Promise { + return this.datasouce.getPlacesByTown(idTown); + } } \ No newline at end of file diff --git a/web/src/infraestructure/datasources/place_datasource.ts b/web/src/infraestructure/datasources/place_datasource.ts index 14e62c49..2fd94357 100644 --- a/web/src/infraestructure/datasources/place_datasource.ts +++ b/web/src/infraestructure/datasources/place_datasource.ts @@ -2,4 +2,5 @@ import { Place } from "../entities/place"; export interface PlaceDatasourceInf{ registerPlace(form: Place): Promise; + getPlacesByTown(idTown: number): Promise; } \ No newline at end of file diff --git a/web/src/infraestructure/repositories/place_repository.ts b/web/src/infraestructure/repositories/place_repository.ts index 7cf06582..cd0d4551 100644 --- a/web/src/infraestructure/repositories/place_repository.ts +++ b/web/src/infraestructure/repositories/place_repository.ts @@ -2,4 +2,5 @@ import { Place } from "../entities/place"; export interface PlaceRepositoryInf{ registerPlace(form: Place): Promise; + getPlacesByTown(idTown: number): Promise; } \ No newline at end of file -- GitLab From 3c9fe613b624bec198f8d18326295814460fad95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:11:14 -0600 Subject: [PATCH 08/60] =?UTF-8?q?Se=20hace=20uso=20de=20la=20funci=C3=B3n?= =?UTF-8?q?=20para=20mostrar=20un=20error=20de=20axios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/hooks/useTown.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/web/src/hooks/useTown.tsx b/web/src/hooks/useTown.tsx index c260d6b1..180ec4c2 100644 --- a/web/src/hooks/useTown.tsx +++ b/web/src/hooks/useTown.tsx @@ -5,6 +5,7 @@ import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form"; import { Town, TownFormValues } from "../infraestructure/entities/town"; import { toast } from "react-toastify"; import axios, { AxiosError } from "axios"; +import { showErrorAxios } from "../utils/Messages"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); @@ -82,7 +83,7 @@ export const useTown = (forceRenderList?: () => void) => { break; } } - throw new Error; + throw new Error(); } } toast.promise( @@ -99,7 +100,10 @@ export const useTown = (forceRenderList?: () => void) => { const towns = await townRepository.getTownsByState(stateId, stateName); setTownsList(towns); }catch(error: any){ - + if(axios.isAxiosError(error)){ + error as AxiosError; + showErrorAxios(error); + } } } -- GitLab From 7e996063a699e1c38196637f12ce3b323f69ae2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:11:49 -0600 Subject: [PATCH 09/60] Se renombra el hook --- .../admin_panel_place_register/admin_panel_place_register.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx b/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx index cbfda67f..78bda39c 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx +++ b/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Dispatch, SetStateAction} from "react"; import "./assets/css/styles.css"; import { MapComponent } from "../../map/map"; -import { usePlaceRegister } from "../../../hooks/usePlaceRegister"; +import { usePlace } from "../../../hooks/usePlace"; import { languaguesList } from "../../../constants/languages"; import { ToastContainer, toast } from "react-toastify"; import { LoadingScreen } from "../../loading_screen/loading_screen"; @@ -33,7 +33,7 @@ export const AdminPanelPlaceRegister = ({setIsWindowActive}: props) => { availableDays, setAvailableDays, resetField, - } = usePlaceRegister(); + } = usePlace(); return (
-- GitLab From bd66dddfce567668b542093806389c7d66fd79d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:12:24 -0600 Subject: [PATCH 10/60] =?UTF-8?q?Se=20crea=20el=20componente=20y=20los=20e?= =?UTF-8?q?stilos=20para=20la=20tabla=20de=20visualizaci=C3=B3n=20de=20lug?= =?UTF-8?q?ares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin_panel_place_list.tsx | 93 +++++++++++++++++++ .../assets/css/styles.css | 22 +++++ 2 files changed, 115 insertions(+) create mode 100644 web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx create mode 100644 web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css diff --git a/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx b/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx new file mode 100644 index 00000000..36c5020e --- /dev/null +++ b/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx @@ -0,0 +1,93 @@ +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'; + +export const AdminPanelPlaceList = () => { + const { + updateTownsList, + statesList, + townsList, + placeList, + updatePlacesByTown, + pending + } = usePlace(); + + const columns : TableColumn[] = [ + { + name: "Identificador", + selector: row => row.idPlace || 0 + }, + { + name: "Nombre", + selector: row => row.name, + sortable: true + }, + { + name: "Estado", + selector: row => row.available + } + ]; + + return ( +
+
+
+ Estado + +
+ +
+ Pueblo mágico + +
+
+ +
+ + } + columns={columns} data={placeList} selectableRows className="town_list_table"/> +
+
+ ); +} \ No newline at end of file diff --git a/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css b/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css new file mode 100644 index 00000000..10d24734 --- /dev/null +++ b/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css @@ -0,0 +1,22 @@ +.place_list_cnt{ + display: flex; + flex-direction: column; + height: 100%; + width: 100%; +} + +.place_list_header{ + width: 100%; + height: 10%; + display: flex; + justify-content: center; + align-items: center; + flex-direction: row; +} + +.place_list_body{ + width: 100%; + display: flex; + flex-direction: column; + height: 90%; +} -- GitLab From 69424ab003d0a9885cd0e5b07167f1c2788cf9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Mon, 17 Jun 2024 15:12:43 -0600 Subject: [PATCH 11/60] =?UTF-8?q?Se=20agrega=20la=20tabla=20de=20visualiza?= =?UTF-8?q?ci=C3=B3n=20de=20los=20lugares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin_panel_place_screen/admin_panel_place_screen.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx b/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx index f082ae26..af5358dc 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx +++ b/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx @@ -1,6 +1,7 @@ import { Dispatch, SetStateAction } from "react"; import { AdminPanelPlaceRegister } from "../admin_panel_place_register/admin_panel_place_register"; import "./assets/css/styles.css"; +import { AdminPanelPlaceList } from "../admin_panel_place_list/admin_panel_place_list"; interface props { isWindowActive: boolean; @@ -8,8 +9,6 @@ interface props { } export const AdminPanelPlaceScreen = ({isWindowActive,setIsWindowActive}: props) => { - - return (
@@ -25,6 +24,7 @@ export const AdminPanelPlaceScreen = ({isWindowActive,setIsWindowActive}: props) { isWindowActive && } +
); -- GitLab From 16fdebff5db99edc1fe03b26e0c1696e85a67296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 09:54:55 -0600 Subject: [PATCH 12/60] Se renombra el hook --- web/src/components/admin_panel_navbar/admin_navbar.tsx | 4 ++-- web/src/hooks/{useAdminNavbar.tsx => useUserData.tsx} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename web/src/hooks/{useAdminNavbar.tsx => useUserData.tsx} (93%) diff --git a/web/src/components/admin_panel_navbar/admin_navbar.tsx b/web/src/components/admin_panel_navbar/admin_navbar.tsx index 19af893c..0dad5f8d 100644 --- a/web/src/components/admin_panel_navbar/admin_navbar.tsx +++ b/web/src/components/admin_panel_navbar/admin_navbar.tsx @@ -3,14 +3,14 @@ import { faSignOut, faUser } from "@fortawesome/free-solid-svg-icons"; import { Link } from "react-router-dom"; import './assets/styles/style.css'; import { UserRole } from "../../constants/roles"; -import { useAdminNavbar } from "../../hooks/useAdminNavbar"; +import { useUserData } from "../../hooks/useUserData"; interface props{ windowActive: boolean; } export const AdminPanelNavBar = ({windowActive}:props) => { - const {user, handleLogout, setToggle, toggle, userData} = useAdminNavbar(); + const {user, handleLogout, setToggle, toggle, userData} = useUserData(); if(!user ){ return null; diff --git a/web/src/hooks/useAdminNavbar.tsx b/web/src/hooks/useUserData.tsx similarity index 93% rename from web/src/hooks/useAdminNavbar.tsx rename to web/src/hooks/useUserData.tsx index c4792abb..83c2f1d2 100644 --- a/web/src/hooks/useAdminNavbar.tsx +++ b/web/src/hooks/useUserData.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { useAuth } from "../context/auth_context"; import { Convert, UserEntity } from "../infraestructure/entities/user"; -export const useAdminNavbar = () => { +export const useUserData = () => { const {user, logout} = useAuth(); const [toggle, setToggle] = useState(false); -- GitLab From 53d0114aecb5793e9455b3e97bef1bbe145b6521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 10:49:25 -0600 Subject: [PATCH 13/60] =?UTF-8?q?Se=20agrega=20la=20l=C3=B3gica=20para=20a?= =?UTF-8?q?ctualizar=20un=20pueblo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/data/datasources/prod/town_datasource.ts | 15 +++++++++++++++ web/src/data/repositories/prod/town_repository.ts | 3 +++ .../datasources/town_datasource.ts | 1 + .../repositories/town_repository.ts | 1 + 4 files changed, 20 insertions(+) diff --git a/web/src/data/datasources/prod/town_datasource.ts b/web/src/data/datasources/prod/town_datasource.ts index b74169f5..fdff1801 100644 --- a/web/src/data/datasources/prod/town_datasource.ts +++ b/web/src/data/datasources/prod/town_datasource.ts @@ -54,4 +54,19 @@ export class TownDatasourceProd implements TownDatasourceInf{ return towns; } + + async updateTown(form: Town): Promise { + const formToSend = new FormData(); + formToSend.append('name',form.name); + formToSend.append('descriptionES',form.descriptionES || ''); + formToSend.append('descriptionEN',form.descriptionEN || ''); + formToSend.append('image',form.imageURL || ''); + formToSend.append('state', form.state); + + const headers = { + 'Content-Type': 'multipart/form-data' + }; + + await axios.patch(APIUrl+`/town/${form.idTown}`, formToSend,{headers}); + } } \ No newline at end of file diff --git a/web/src/data/repositories/prod/town_repository.ts b/web/src/data/repositories/prod/town_repository.ts index 31c8edd0..ae58508a 100644 --- a/web/src/data/repositories/prod/town_repository.ts +++ b/web/src/data/repositories/prod/town_repository.ts @@ -16,4 +16,7 @@ export class TownRepositoryProd implements TownRepositoryInf{ async getTownsByState(idState: number, stateName:string) : Promise { return this.datasource.getTownsByState(idState, stateName); } + async updateTown(form: Town): Promise { + return this.datasource.updateTown(form); + } } \ No newline at end of file diff --git a/web/src/infraestructure/datasources/town_datasource.ts b/web/src/infraestructure/datasources/town_datasource.ts index 7dfed2eb..97dd8a4c 100644 --- a/web/src/infraestructure/datasources/town_datasource.ts +++ b/web/src/infraestructure/datasources/town_datasource.ts @@ -5,4 +5,5 @@ export interface TownDatasourceInf{ getStates(): Promise; registerTown(form: TownFormValues): void; getTownsByState(idState: number, stateName:string) : Promise; + updateTown(form: Town): Promise; } \ No newline at end of file diff --git a/web/src/infraestructure/repositories/town_repository.ts b/web/src/infraestructure/repositories/town_repository.ts index 1c7388c2..14029e02 100644 --- a/web/src/infraestructure/repositories/town_repository.ts +++ b/web/src/infraestructure/repositories/town_repository.ts @@ -5,4 +5,5 @@ export interface TownRepositoryInf{ getStates(): Promise; registerTown(form: TownFormValues): Promise; getTownsByState(idState: number, stateName:string) : Promise; + updateTown(form: Town): Promise; } \ No newline at end of file -- GitLab From 40cbf1d86a6c4dbd299d3d1f31389f8819604374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 11:06:29 -0600 Subject: [PATCH 14/60] Se agrega que se muestre el mensaje que genera axios --- web/src/utils/Messages.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/src/utils/Messages.ts b/web/src/utils/Messages.ts index 24ddcb8d..3232eb23 100644 --- a/web/src/utils/Messages.ts +++ b/web/src/utils/Messages.ts @@ -10,6 +10,9 @@ export const showErrorAxios = (error: AxiosError) => { case(axios.AxiosError.ERR_NETWORK): message = "Conexión con el servidor fallida"; break; + default: + message = error.message; + break; } toast.error(message, { position: "bottom-right", -- GitLab From ae18d9f314d21f5cd262d2349b8212afa2193251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 11:06:52 -0600 Subject: [PATCH 15/60] Se modifica una variable para que no pueda ser null --- web/src/hooks/useTown.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/hooks/useTown.tsx b/web/src/hooks/useTown.tsx index 180ec4c2..e51a970a 100644 --- a/web/src/hooks/useTown.tsx +++ b/web/src/hooks/useTown.tsx @@ -61,7 +61,7 @@ export const useTown = (forceRenderList?: () => void) => { formState: {errors}, setValue } = useForm({resolver}); - const [townsList, setTownsList] = useState(null); + const [townsList, setTownsList] = useState([]); const [errorMessage, setErrorMessage] = useState(""); const onSubmit: SubmitHandler = (data: TownFormValues) => { -- GitLab From fa7ee33b93ad3e6790330751ede19493a476754a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 11:22:05 -0600 Subject: [PATCH 16/60] Se modifica para que la ventana de registro se muestre por encima de todo --- .../admin_panel_place_register/assets/css/styles.css | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/components/admin_panel_places/admin_panel_place_register/assets/css/styles.css b/web/src/components/admin_panel_places/admin_panel_place_register/assets/css/styles.css index c0057a5e..4f0b19f3 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_register/assets/css/styles.css +++ b/web/src/components/admin_panel_places/admin_panel_place_register/assets/css/styles.css @@ -4,6 +4,7 @@ .place_register_wrap{ position: absolute; + z-index: 99; left: 0; right: 0; top: 0; -- GitLab From a3be4c82d1b06da5deb27abd9bdf2bb45a85c44f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 11:23:01 -0600 Subject: [PATCH 17/60] =?UTF-8?q?Se=20elimina=20el=20componente=20innecesa?= =?UTF-8?q?rio=20y=20se=20cambia=20de=20ubicaci=C3=B3n=20el=20componente?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/css/styles.css | 0 .../sa_panel_town_list/sa_panel_town_list.tsx | 73 +++++++++++++++++++ .../sa_panel_town_list.tsx | 57 --------------- .../assets/css/styles.css | 13 ---- .../sa_panel_town_table.tsx | 35 --------- .../sa_panel_town_screen.tsx | 2 +- 6 files changed, 74 insertions(+), 106 deletions(-) rename web/src/components/sa_panel_town/sa_panel_town_list/{sa_panel_town_list_content => }/assets/css/styles.css (100%) create mode 100644 web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list.tsx delete mode 100644 web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_content/sa_panel_town_list.tsx delete mode 100644 web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/assets/css/styles.css delete mode 100644 web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/sa_panel_town_table.tsx diff --git a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_content/assets/css/styles.css b/web/src/components/sa_panel_town/sa_panel_town_list/assets/css/styles.css similarity index 100% rename from web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_content/assets/css/styles.css rename to web/src/components/sa_panel_town/sa_panel_town_list/assets/css/styles.css diff --git a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list.tsx b/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list.tsx new file mode 100644 index 00000000..78ea3da3 --- /dev/null +++ b/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list.tsx @@ -0,0 +1,73 @@ +import { useEffect, useState } from "react"; +import { useTown } from "../../../hooks/useTown"; +import { State } from "../../../infraestructure/entities/state"; +import axios, { AxiosError } from "axios"; +import "./assets/css/styles.css"; +import { Town } from "../../../infraestructure/entities/town"; +import DataTable, { TableColumn } from "react-data-table-component"; +import { LoadingSpinner } from "../../loading_spinner/loading_spinner"; +import { showErrorAxios } from "../../../utils/Messages"; + +interface props { + statesList: State[]; +} + +export const SuperadminPanelTownList = ({statesList}: props) => { + const {townsList, getTownsByState, setTownsList} = useTown(); + const [pending, setPending] = useState(false); + + const columns : TableColumn[] = [ + { + name: "Identificador", + selector: row => row.idTown + }, + { + name: "Nombre", + selector: row => row.name, + sortable: true + }, + { + name: "Estado", + selector: row => row.state + } + ]; + + + const refreshList = () => { + setPending(true); + const getTownsList = async () => { + try { + if (statesList) { + const townsListBackup: Town[] = []; + statesList.forEach((state) => { + getTownsByState(state.stateId, state.name); + if (townsList) { + townsListBackup.push(...townsList); + } + }); + setTownsList(townsListBackup); + } + } catch (error: any) { + if (axios.isAxiosError(error)) { + error as AxiosError; + showErrorAxios(error); + } + } + } + getTownsList(); + setPending(false); + }; + + useEffect(() => { + refreshList(); + }, []); + + return ( + + } + columns={columns} data={townsList} selectableRows className="data_table" + /> + ); +} \ No newline at end of file diff --git a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_content/sa_panel_town_list.tsx b/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_content/sa_panel_town_list.tsx deleted file mode 100644 index a06aa589..00000000 --- a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_content/sa_panel_town_list.tsx +++ /dev/null @@ -1,57 +0,0 @@ -import { useEffect, useState } from "react"; -import { useTown } from "../../../../hooks/useTown"; -import { State } from "../../../../infraestructure/entities/state"; -import axios from "axios"; -import "./assets/css/styles.css"; -import { TownListTable } from "../sa_panel_town_list_element/sa_panel_town_table"; -import { Town } from "../../../../infraestructure/entities/town"; -import { LoadingScreen } from "../../../loading_screen/loading_screen"; - -interface props { - statesList: State[]; -} - -export const SuperadminPanelTownList = ({statesList}: props) => { - const {townsList, getTownsByState, setTownsList} = useTown(); - const [isLoadingList, setIsLoadingList] = useState(true); - - useEffect(() => { - refreshList(); - }, []); - - const refreshList = () => { - setIsLoadingList(true); - const getTownsList = async () => { - try { - if (statesList) { - const townsListBackup: Town[] = []; - statesList.forEach((state) => { - getTownsByState(state.stateId, state.name); - if (townsList) { - townsListBackup.push(...townsList); - } - }); - setTownsList(townsListBackup); - } - } catch (error: any) { - if (axios.isAxiosError(error)) { - //console.log(error) - } - } - } - getTownsList(); - }; - - return ( -
- { - isLoadingList && - - } - { - townsList && townsList.length>0 && - - } -
- ); -} \ No newline at end of file diff --git a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/assets/css/styles.css b/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/assets/css/styles.css deleted file mode 100644 index 7e61c5a7..00000000 --- a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/assets/css/styles.css +++ /dev/null @@ -1,13 +0,0 @@ -.town_list_table { - height: 100%; -} - -.bhFeAR{ - display: flex !important; - height: 100%; -} - -.rdt_TableBody{ - max-height: 100%; - overflow-y: auto; -} \ No newline at end of file diff --git a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/sa_panel_town_table.tsx b/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/sa_panel_town_table.tsx deleted file mode 100644 index fceb4b04..00000000 --- a/web/src/components/sa_panel_town/sa_panel_town_list/sa_panel_town_list_element/sa_panel_town_table.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import { Dispatch, SetStateAction, useEffect } from "react"; -import { Town } from "../../../../infraestructure/entities/town"; -import "./assets/css/styles.css"; -import DataTable, { TableColumn } from "react-data-table-component"; - -interface props { - towns: Town[]; - setIsLoading: Dispatch>; -} - -export const TownListTable= ({towns, setIsLoading}: props) => { - const columns : TableColumn[] = [ - { - name: "Identificador", - selector: row => row.idTown - }, - { - name: "Nombre", - selector: row => row.name, - sortable: true - }, - { - name: "Estado", - selector: row => row.state - } - ]; - - useEffect(() => { - setIsLoading(false); - }, []); - - return ( - - ); -} \ No newline at end of file diff --git a/web/src/components/sa_panel_town/sa_panel_town_screen/sa_panel_town_screen.tsx b/web/src/components/sa_panel_town/sa_panel_town_screen/sa_panel_town_screen.tsx index 9938e108..3c735a14 100644 --- a/web/src/components/sa_panel_town/sa_panel_town_screen/sa_panel_town_screen.tsx +++ b/web/src/components/sa_panel_town/sa_panel_town_screen/sa_panel_town_screen.tsx @@ -2,7 +2,7 @@ import { Dispatch, SetStateAction, useState } from 'react'; import { SuperadminPanelTownRegister } from '../sa_panel_town_register/sa_panel_town_register'; import './css/styles.css' import { State } from '../../../infraestructure/entities/state'; -import { SuperadminPanelTownList } from '../sa_panel_town_list/sa_panel_town_list_content/sa_panel_town_list'; +import { SuperadminPanelTownList } from '../sa_panel_town_list/sa_panel_town_list'; interface props { windowActive: boolean; -- GitLab From 707a50798d4c4bfbf2c146d2b03c931aa8dc83e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Fri, 21 Jun 2024 12:47:08 -0600 Subject: [PATCH 18/60] Se elimina una interface innecesaria --- web/src/data/datasources/prod/town_datasource.ts | 10 +++++----- web/src/data/repositories/prod/town_repository.ts | 4 ++-- web/src/infraestructure/datasources/town_datasource.ts | 4 ++-- web/src/infraestructure/entities/town.ts | 8 -------- .../infraestructure/repositories/town_repository.ts | 4 ++-- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/web/src/data/datasources/prod/town_datasource.ts b/web/src/data/datasources/prod/town_datasource.ts index fdff1801..3a90c8f6 100644 --- a/web/src/data/datasources/prod/town_datasource.ts +++ b/web/src/data/datasources/prod/town_datasource.ts @@ -3,7 +3,7 @@ import { APIUrl } from "../../../constants/api_url"; import { TownDatasourceInf } from "../../../infraestructure/datasources/town_datasource"; import { StateModel } from "../../models/prod/StateModel"; import { State } from "../../../infraestructure/entities/state"; -import { Town, TownFormValues } from "../../../infraestructure/entities/town"; +import { Town } from "../../../infraestructure/entities/town"; import { TownModel } from "../../models/prod/TownModel"; export class TownDatasourceProd implements TownDatasourceInf{ @@ -21,13 +21,13 @@ export class TownDatasourceProd implements TownDatasourceInf{ return states; } - async registerTown(form: TownFormValues): Promise { + async registerTown(form: Town): Promise { const formToSend = new FormData(); formToSend.append('name',form.name); - formToSend.append('descriptionES',form.descriptionES); - formToSend.append('descriptionEN',form.descriptionEN); + formToSend.append('descriptionES',form.descriptionES || ''); + formToSend.append('descriptionEN',form.descriptionEN || ''); formToSend.append('state', form.state); - formToSend.append('image',form.imageURL); + formToSend.append('image',form.imageURL || ''); const headers = { 'Content-Type': 'multipart/form-data' diff --git a/web/src/data/repositories/prod/town_repository.ts b/web/src/data/repositories/prod/town_repository.ts index ae58508a..7fe0b116 100644 --- a/web/src/data/repositories/prod/town_repository.ts +++ b/web/src/data/repositories/prod/town_repository.ts @@ -1,6 +1,6 @@ import { TownDatasourceInf } from "../../../infraestructure/datasources/town_datasource"; import { State } from "../../../infraestructure/entities/state"; -import { Town, TownFormValues } from "../../../infraestructure/entities/town"; +import { Town } from "../../../infraestructure/entities/town"; import { TownRepositoryInf } from "../../../infraestructure/repositories/town_repository"; export class TownRepositoryProd implements TownRepositoryInf{ @@ -10,7 +10,7 @@ export class TownRepositoryProd implements TownRepositoryInf{ async getStates(): Promise { return this.datasource.getStates(); } - async registerTown(form: TownFormValues): Promise { + async registerTown(form: Town): Promise { return this.datasource.registerTown(form); } async getTownsByState(idState: number, stateName:string) : Promise { diff --git a/web/src/infraestructure/datasources/town_datasource.ts b/web/src/infraestructure/datasources/town_datasource.ts index 97dd8a4c..f8bbbdff 100644 --- a/web/src/infraestructure/datasources/town_datasource.ts +++ b/web/src/infraestructure/datasources/town_datasource.ts @@ -1,9 +1,9 @@ import { State } from "../entities/state"; -import { Town, TownFormValues } from "../entities/town"; +import { Town } from "../entities/town"; export interface TownDatasourceInf{ getStates(): Promise; - registerTown(form: TownFormValues): void; + registerTown(form: Town): void; getTownsByState(idState: number, stateName:string) : Promise; updateTown(form: Town): Promise; } \ No newline at end of file diff --git a/web/src/infraestructure/entities/town.ts b/web/src/infraestructure/entities/town.ts index e591aed3..bd540cce 100644 --- a/web/src/infraestructure/entities/town.ts +++ b/web/src/infraestructure/entities/town.ts @@ -1,11 +1,3 @@ -export interface TownFormValues { - name : string; - descriptionES : string; - descriptionEN : string; - state : string; - imageURL : File; -} - export interface Town { idTown: number; name : string; diff --git a/web/src/infraestructure/repositories/town_repository.ts b/web/src/infraestructure/repositories/town_repository.ts index 14029e02..aae548fd 100644 --- a/web/src/infraestructure/repositories/town_repository.ts +++ b/web/src/infraestructure/repositories/town_repository.ts @@ -1,9 +1,9 @@ import { State } from "../entities/state"; -import { Town, TownFormValues } from "../entities/town"; +import { Town } from "../entities/town"; export interface TownRepositoryInf{ getStates(): Promise; - registerTown(form: TownFormValues): Promise; + registerTown(form: Town): Promise; getTownsByState(idState: number, stateName:string) : Promise; updateTown(form: Town): Promise; } \ No newline at end of file -- GitLab From 1ec4cd79ee238f4403155067a024c18415c8ef0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 11:18:06 -0600 Subject: [PATCH 19/60] Se agrega una nueva interface para un pueblo --- web/src/data/models/prod/TownModel.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/src/data/models/prod/TownModel.ts b/web/src/data/models/prod/TownModel.ts index 9505c9dc..4b79e916 100644 --- a/web/src/data/models/prod/TownModel.ts +++ b/web/src/data/models/prod/TownModel.ts @@ -1,7 +1,16 @@ -export interface TownModel { +export interface TownModelTrad { townId: number; name : string; imageName : string; description : string; stateId : number; +} + +export interface TownModel { + townId: number; + name : string; + descriptionEN : string; + descriptionES : string; + imageName : string; + stateId : number; } \ No newline at end of file -- GitLab From 2b0d1314b9c37d22f1f3e2392169cb77d13a503f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 11:35:23 -0600 Subject: [PATCH 20/60] =?UTF-8?q?Se=20agreg=C3=B3=20la=20l=C3=B3gica=20par?= =?UTF-8?q?a=20obtener=20un=20pueblo=20por=20medio=20de=20su=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasources/prod/town_datasource.ts | 18 ++++++++++++++++-- .../data/repositories/prod/town_repository.ts | 3 +++ .../datasources/town_datasource.ts | 1 + .../repositories/town_repository.ts | 1 + 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/web/src/data/datasources/prod/town_datasource.ts b/web/src/data/datasources/prod/town_datasource.ts index 3a90c8f6..87493d4c 100644 --- a/web/src/data/datasources/prod/town_datasource.ts +++ b/web/src/data/datasources/prod/town_datasource.ts @@ -4,7 +4,7 @@ import { TownDatasourceInf } from "../../../infraestructure/datasources/town_dat import { StateModel } from "../../models/prod/StateModel"; import { State } from "../../../infraestructure/entities/state"; import { Town } from "../../../infraestructure/entities/town"; -import { TownModel } from "../../models/prod/TownModel"; +import { TownModel, TownModelTrad } from "../../models/prod/TownModel"; export class TownDatasourceProd implements TownDatasourceInf{ async getStates(): Promise { @@ -37,7 +37,7 @@ export class TownDatasourceProd implements TownDatasourceInf{ } async getTownsByState(idState: number, stateName:string): Promise { - const {data} = await axios.get(APIUrl+`/state/${idState}/town`, { + const {data} = await axios.get(APIUrl+`/state/${idState}/town`, { params: { lang: 'ES' } @@ -55,6 +55,20 @@ export class TownDatasourceProd implements TownDatasourceInf{ return towns; } + async getTown(idTown: number): Promise { + const {data} = await axios.get(APIUrl+`/town/${idTown}`); + const town: Town = { + idTown : data.townId, + name: data.name, + idState: data.stateId, + descriptionES: data.descriptionES, + descriptionEN: data.descriptionEN, + state: '', + imageURL: data.imageName + } + return town; + } + async updateTown(form: Town): Promise { const formToSend = new FormData(); formToSend.append('name',form.name); diff --git a/web/src/data/repositories/prod/town_repository.ts b/web/src/data/repositories/prod/town_repository.ts index 7fe0b116..72996d29 100644 --- a/web/src/data/repositories/prod/town_repository.ts +++ b/web/src/data/repositories/prod/town_repository.ts @@ -16,6 +16,9 @@ export class TownRepositoryProd implements TownRepositoryInf{ async getTownsByState(idState: number, stateName:string) : Promise { return this.datasource.getTownsByState(idState, stateName); } + async getTown(idTown: number): Promise { + return this.datasource.getTown(idTown); + } async updateTown(form: Town): Promise { return this.datasource.updateTown(form); } diff --git a/web/src/infraestructure/datasources/town_datasource.ts b/web/src/infraestructure/datasources/town_datasource.ts index f8bbbdff..2e24a5d5 100644 --- a/web/src/infraestructure/datasources/town_datasource.ts +++ b/web/src/infraestructure/datasources/town_datasource.ts @@ -5,5 +5,6 @@ export interface TownDatasourceInf{ getStates(): Promise; registerTown(form: Town): void; getTownsByState(idState: number, stateName:string) : Promise; + getTown(idTown: number): Promise; updateTown(form: Town): Promise; } \ No newline at end of file diff --git a/web/src/infraestructure/repositories/town_repository.ts b/web/src/infraestructure/repositories/town_repository.ts index aae548fd..9e390a0b 100644 --- a/web/src/infraestructure/repositories/town_repository.ts +++ b/web/src/infraestructure/repositories/town_repository.ts @@ -5,5 +5,6 @@ export interface TownRepositoryInf{ getStates(): Promise; registerTown(form: Town): Promise; getTownsByState(idState: number, stateName:string) : Promise; + getTown(idTown: number): Promise; updateTown(form: Town): Promise; } \ No newline at end of file -- GitLab From 5313c4bba947d25351eb20acc66a2e5d05728307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 11:37:05 -0600 Subject: [PATCH 21/60] =?UTF-8?q?Se=20agreg=C3=B3=20una=20interface=20y=20?= =?UTF-8?q?un=20modelo=20para=20un=20admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/data/models/prod/AdminModel.ts | 7 +++++++ web/src/infraestructure/entities/admin_form_values.ts | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 web/src/data/models/prod/AdminModel.ts diff --git a/web/src/data/models/prod/AdminModel.ts b/web/src/data/models/prod/AdminModel.ts new file mode 100644 index 00000000..99e74235 --- /dev/null +++ b/web/src/data/models/prod/AdminModel.ts @@ -0,0 +1,7 @@ +export interface AdminModel { + email: string; + name: string; + lastName: string; + role: string; + idTown?: number; +} \ No newline at end of file diff --git a/web/src/infraestructure/entities/admin_form_values.ts b/web/src/infraestructure/entities/admin_form_values.ts index 09d39e2b..3fbd7fcd 100644 --- a/web/src/infraestructure/entities/admin_form_values.ts +++ b/web/src/infraestructure/entities/admin_form_values.ts @@ -4,4 +4,12 @@ export interface AdminFormValues { password: string; confirmPassword: string; townAdmin: number; +} + +export interface Admin { + email: string; + name: string; + lastName: string; + role: string; + idTown?: number; } \ No newline at end of file -- GitLab From 384ce402b03a8f7db1f5ac0837aa098149f8073e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 11:39:40 -0600 Subject: [PATCH 22/60] Se agrega el tiipo de dato File al campo de imageURL --- web/src/infraestructure/entities/town.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/infraestructure/entities/town.ts b/web/src/infraestructure/entities/town.ts index bd540cce..08687165 100644 --- a/web/src/infraestructure/entities/town.ts +++ b/web/src/infraestructure/entities/town.ts @@ -5,5 +5,5 @@ export interface Town { descriptionEN? : string; idState : number; state: string; - imageURL? : string; + imageURL? : string | File; } \ No newline at end of file -- GitLab From dd201b74b8adf52d5f76df53e11ffb4975bfa42e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:07:19 -0600 Subject: [PATCH 23/60] Se crea un componente para mostrar un error --- .../error_window/assets/css/styles.css | 67 +++++++++++++++++++ .../components/error_window/error_window.tsx | 36 ++++++++++ 2 files changed, 103 insertions(+) create mode 100644 web/src/components/error_window/assets/css/styles.css create mode 100644 web/src/components/error_window/error_window.tsx diff --git a/web/src/components/error_window/assets/css/styles.css b/web/src/components/error_window/assets/css/styles.css new file mode 100644 index 00000000..edde9704 --- /dev/null +++ b/web/src/components/error_window/assets/css/styles.css @@ -0,0 +1,67 @@ +.error-window { + position: absolute; + left: 0; + right: 0; + top: 0; + bottom: 0; + margin: auto; + width: 500px; + height: 200px; + z-index: 2; + box-shadow: 0px 15px 20px rgba(0,0,0,0.1); + background-color: red; + display: flex; + flex-direction: column; + font-size: 30px; + font-weight: 500; + line-height: 50px; + text-align: center; + user-select: none; +} + +.window-error-header{ + display: flex; + flex-direction: row; + align-items: center; + color: white; + justify-content: center; + height: 20%; +} + +.window-title{ + height: 100%; + display: flex; + justify-content: center; + align-items: center; + width: 100%; +} + +.window-title div{ + color: white; +} + +.window-close-button{ + color: white; + display: inline-block; + cursor: pointer; + position: absolute; + right: 5px; +} + +.window-error-body{ + display: flex; + flex-grow: 1; + background: white; + align-items: center; + justify-content: center; + height: 80%; + font-size: 25px; + font-weight: 400; + line-height: 50px; +} + +.circle-exclamation-icon{ + color: red; + height: 50px; + margin: 20px; +} \ No newline at end of file diff --git a/web/src/components/error_window/error_window.tsx b/web/src/components/error_window/error_window.tsx new file mode 100644 index 00000000..950997ca --- /dev/null +++ b/web/src/components/error_window/error_window.tsx @@ -0,0 +1,36 @@ +import { faWindowClose, faCircleExclamation } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { useState } from "react"; +import './assets/css/styles.css'; + +interface props { + title?: string; + message: string; +} + +export const ErrorWindow = ({title, message}:props) => { + const [isVisible, setIsVisible] = useState(true); + + if(!isVisible) return null; + + return ( +
+
+
+ {title || "Error"} +
+ { + setIsVisible(false); + }} + /> +
+
+ + {message} +
+
+ ); +} \ No newline at end of file -- GitLab From c84f4834370bbd0047c8e11190dc7842fc80f10c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:07:59 -0600 Subject: [PATCH 24/60] Se cambia una propiedad --- .../components/multiple_images_dropzone/assets/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/multiple_images_dropzone/assets/css/styles.css b/web/src/components/multiple_images_dropzone/assets/css/styles.css index 8078660d..f8c0ddc1 100644 --- a/web/src/components/multiple_images_dropzone/assets/css/styles.css +++ b/web/src/components/multiple_images_dropzone/assets/css/styles.css @@ -29,7 +29,7 @@ display: flex; flex-direction: row; align-items: center; - justify-content: start; + justify-content: flex-start; overflow-x: auto; } -- GitLab From 67de58d9df35d1764dd10e7317e71616075e59ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:09:07 -0600 Subject: [PATCH 25/60] Se modifica el como se muestra la preview de la imagen --- .../image_dropzone/image_dropzone.tsx | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/web/src/components/image_dropzone/image_dropzone.tsx b/web/src/components/image_dropzone/image_dropzone.tsx index bd2101c7..34a12cdc 100644 --- a/web/src/components/image_dropzone/image_dropzone.tsx +++ b/web/src/components/image_dropzone/image_dropzone.tsx @@ -4,16 +4,16 @@ import { useDropzone } from "react-dropzone"; import { useState } from 'react'; import "react-toastify/dist/ReactToastify.css"; import { UseFormSetValue } from 'react-hook-form'; -import { TownFormValues } from '../../infraestructure/entities/town'; +import { Town } from '../../infraestructure/entities/town'; interface props { - setValue : UseFormSetValue + setValue : UseFormSetValue } export const ImageDropzone = ({setValue}: props) => { const MAX_SIZE = 10485760; const [preview, setPreview] = useState(null); - const {fileRejections,getRootProps, getInputProps} = useDropzone( + const {getRootProps, getInputProps} = useDropzone( { multiple: false, maxSize: MAX_SIZE, @@ -22,8 +22,6 @@ export const ImageDropzone = ({setValue}: props) => { 'image/png': [] }, onDrop(acceptedFiles, fileRejections) { - const file = new FileReader; - fileRejections.map(({file, errors}) => ( toast.error(errors[0].message, { position: "bottom-right", @@ -36,15 +34,11 @@ export const ImageDropzone = ({setValue}: props) => { theme: "colored" }))); - acceptedFiles.map((file)=>{ - {setValue('imageURL',file,{shouldValidate: true})} + acceptedFiles.forEach((file)=>{ + const preview = URL.createObjectURL(file); + setValue('imageURL',file,{shouldValidate: true}); + setPreview(preview); }); - - file.onload = () => { - setPreview(file.result); - }; - - file.readAsDataURL(acceptedFiles[0]); } } ); -- GitLab From 64c24cc6b710b357201734ff2c8f503cc31a1ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:32:22 -0600 Subject: [PATCH 26/60] Se modifica un el tipo de un campo --- web/src/infraestructure/entities/admin_form_values.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/src/infraestructure/entities/admin_form_values.ts b/web/src/infraestructure/entities/admin_form_values.ts index 3fbd7fcd..b0c179b5 100644 --- a/web/src/infraestructure/entities/admin_form_values.ts +++ b/web/src/infraestructure/entities/admin_form_values.ts @@ -1,3 +1,5 @@ +import { UserRole } from "../../constants/roles"; + export interface AdminFormValues { email: string; name: string; @@ -10,6 +12,6 @@ export interface Admin { email: string; name: string; lastName: string; - role: string; + role: UserRole; idTown?: number; } \ No newline at end of file -- GitLab From 6609bb1a5a6f88d46a165dd133a3252055f634a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:36:50 -0600 Subject: [PATCH 27/60] Se agrega el apellido al formulario de admin --- web/src/infraestructure/entities/admin_form_values.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/infraestructure/entities/admin_form_values.ts b/web/src/infraestructure/entities/admin_form_values.ts index b0c179b5..256319ee 100644 --- a/web/src/infraestructure/entities/admin_form_values.ts +++ b/web/src/infraestructure/entities/admin_form_values.ts @@ -3,6 +3,7 @@ import { UserRole } from "../../constants/roles"; export interface AdminFormValues { email: string; name: string; + lastName: string; password: string; confirmPassword: string; townAdmin: number; -- GitLab From ee9c6b1237cde675e73093a0379cb555625239a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:38:49 -0600 Subject: [PATCH 28/60] =?UTF-8?q?Se=20agrega=20la=20l=C3=B3gica=20de=20agr?= =?UTF-8?q?egar=20un=20admin=20y=20de=20obtener=20la=20informaci=C3=B3n=20?= =?UTF-8?q?basado=20en=20su=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasources/prod/admin_datasource.ts | 33 +++++++++++++++++-- .../repositories/prod/admin_repository.ts | 8 +++-- .../datasources/admin_datasource.ts | 5 +-- .../repositories/admin_repository.ts | 5 +-- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/web/src/data/datasources/prod/admin_datasource.ts b/web/src/data/datasources/prod/admin_datasource.ts index fe19d185..26ed67fc 100644 --- a/web/src/data/datasources/prod/admin_datasource.ts +++ b/web/src/data/datasources/prod/admin_datasource.ts @@ -1,8 +1,37 @@ +import axios from "axios"; import { AdminDatasourceInf } from "../../../infraestructure/datasources/admin_datasource"; -import { AdminFormValues } from "../../../infraestructure/entities/admin_form_values"; +import { Admin, AdminFormValues } from "../../../infraestructure/entities/admin_form_values"; +import { APIUrl } from "../../../constants/api_url"; +import { AdminModel } from "../../models/prod/AdminModel"; +import { UserRole } from "../../../constants/roles"; export class AdminDatasourceProd implements AdminDatasourceInf{ async registerAdmin(form: AdminFormValues): Promise { - + await axios.post( + APIUrl + "/admin/signup", + { + email: form.email, + idTowm: form.townAdmin, + password: form.password, + name: form.name, + lastName: form.lastName + } + ); + } + + async getAdminInfo(token: string): Promise { + const {data} = await axios.get(APIUrl+'/admin/whoami',{ + headers: { + 'Authorization': `Bearer ${token}` + } + }); + const admin: Admin = { + email: data.email, + name: data.name, + lastName: data.lastName, + role: data.role === UserRole.SUPERADMIN ? UserRole.SUPERADMIN : UserRole.ADMIN, + idTown: data.idTown + } + return admin; } } \ No newline at end of file diff --git a/web/src/data/repositories/prod/admin_repository.ts b/web/src/data/repositories/prod/admin_repository.ts index 81724b76..3f53c8c6 100644 --- a/web/src/data/repositories/prod/admin_repository.ts +++ b/web/src/data/repositories/prod/admin_repository.ts @@ -1,5 +1,5 @@ import { AdminDatasourceInf } from "../../../infraestructure/datasources/admin_datasource"; -import { AdminFormValues } from "../../../infraestructure/entities/admin_form_values"; +import { Admin, AdminFormValues } from "../../../infraestructure/entities/admin_form_values"; import { AdminRepositoryInf } from "../../../infraestructure/repositories/admin_repository"; export class AdminRepositoryProd implements AdminRepositoryInf{ @@ -8,6 +8,10 @@ export class AdminRepositoryProd implements AdminRepositoryInf{ ){} async registerAdmin(form: AdminFormValues): Promise { - return this.datasource.registerAdmin(form); + return this.datasource.registerAdmin(form); + } + + async getAdminInfo(token: string): Promise { + return this.datasource.getAdminInfo(token); } } \ No newline at end of file diff --git a/web/src/infraestructure/datasources/admin_datasource.ts b/web/src/infraestructure/datasources/admin_datasource.ts index 1b6ca143..f167677b 100644 --- a/web/src/infraestructure/datasources/admin_datasource.ts +++ b/web/src/infraestructure/datasources/admin_datasource.ts @@ -1,5 +1,6 @@ -import { AdminFormValues } from "../entities/admin_form_values"; +import { Admin, AdminFormValues } from "../entities/admin_form_values"; export interface AdminDatasourceInf{ - registerAdmin(form: AdminFormValues): Promise; + registerAdmin(form: AdminFormValues): Promise; + getAdminInfo(token: string): Promise; } \ No newline at end of file diff --git a/web/src/infraestructure/repositories/admin_repository.ts b/web/src/infraestructure/repositories/admin_repository.ts index c4af71ab..311bdfae 100644 --- a/web/src/infraestructure/repositories/admin_repository.ts +++ b/web/src/infraestructure/repositories/admin_repository.ts @@ -1,5 +1,6 @@ -import { AdminFormValues } from "../entities/admin_form_values"; +import { Admin, AdminFormValues } from "../entities/admin_form_values"; export interface AdminRepositoryInf{ - registerAdmin(form: AdminFormValues): void; + registerAdmin(form: AdminFormValues): Promise; + getAdminInfo(token: string): Promise; } \ No newline at end of file -- GitLab From e5bd494ae202b7ced1fde9f6bffce407b6df554e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 12:41:28 -0600 Subject: [PATCH 29/60] Se renombra el hook --- web/src/hooks/{useAdminRegister.tsx => useAdmin.tsx} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename web/src/hooks/{useAdminRegister.tsx => useAdmin.tsx} (98%) diff --git a/web/src/hooks/useAdminRegister.tsx b/web/src/hooks/useAdmin.tsx similarity index 98% rename from web/src/hooks/useAdminRegister.tsx rename to web/src/hooks/useAdmin.tsx index 02b38e9b..5d6c60bc 100644 --- a/web/src/hooks/useAdminRegister.tsx +++ b/web/src/hooks/useAdmin.tsx @@ -64,7 +64,7 @@ const resolver: Resolver = async (data) => { }; }; -export const useAdminRegister = () => { +export const useAdmin = () => { const { register, handleSubmit, -- GitLab From 4d8589da1f707eddbe7c7fa85355d7c40219cbbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 13:25:26 -0600 Subject: [PATCH 30/60] Se modifica para que la ventana se muestre por encima de todo --- web/src/components/error_window/assets/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/error_window/assets/css/styles.css b/web/src/components/error_window/assets/css/styles.css index edde9704..83ea6d8b 100644 --- a/web/src/components/error_window/assets/css/styles.css +++ b/web/src/components/error_window/assets/css/styles.css @@ -7,7 +7,7 @@ margin: auto; width: 500px; height: 200px; - z-index: 2; + z-index: 999; box-shadow: 0px 15px 20px rgba(0,0,0,0.1); background-color: red; display: flex; -- GitLab From d834ea79e9c1c47207ebf6fa91753c16e3056272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 13:29:51 -0600 Subject: [PATCH 31/60] Se modifica el estilo del spinner --- web/src/components/loading_spinner/{ => assets/css}/styles.css | 2 +- web/src/components/loading_spinner/loading_spinner.tsx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename web/src/components/loading_spinner/{ => assets/css}/styles.css (96%) diff --git a/web/src/components/loading_spinner/styles.css b/web/src/components/loading_spinner/assets/css/styles.css similarity index 96% rename from web/src/components/loading_spinner/styles.css rename to web/src/components/loading_spinner/assets/css/styles.css index 17bf1b10..bf6048a2 100644 --- a/web/src/components/loading_spinner/styles.css +++ b/web/src/components/loading_spinner/assets/css/styles.css @@ -1,4 +1,4 @@ -.loading_spinner{ +.spinner{ z-index: 999; width: 150px; padding: 20px; diff --git a/web/src/components/loading_spinner/loading_spinner.tsx b/web/src/components/loading_spinner/loading_spinner.tsx index 6fda4358..539de628 100644 --- a/web/src/components/loading_spinner/loading_spinner.tsx +++ b/web/src/components/loading_spinner/loading_spinner.tsx @@ -1,7 +1,8 @@ import React, { HTMLAttributes } from "react"; +import "./assets/css/styles.css"; export const LoadingSpinner :React.FC> = () => { return ( -
+
); } \ No newline at end of file -- GitLab From 96bd6da10d178ace5653aecd094e0fd6a449b1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 14:56:56 -0600 Subject: [PATCH 32/60] Se eliminan componentes innecesarios --- .../admin_panel_place_list.tsx | 75 +++---------------- .../assets/css/styles.css | 25 +++---- 2 files changed, 23 insertions(+), 77 deletions(-) diff --git a/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx b/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx index 36c5020e..d56168fc 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx +++ b/web/src/components/admin_panel_places/admin_panel_place_list/admin_panel_place_list.tsx @@ -4,16 +4,16 @@ import './assets/css/styles.css'; import { Place } from '../../../infraestructure/entities/place'; import { LoadingSpinner } from '../../loading_spinner/loading_spinner'; -export const AdminPanelPlaceList = () => { +interface props{ + idTown: number; +} + +export const AdminPanelPlaceList = ({idTown}: props) => { const { - updateTownsList, - statesList, - townsList, placeList, - updatePlacesByTown, pending - } = usePlace(); - + } = usePlace(idTown); + const columns : TableColumn[] = [ { name: "Identificador", @@ -32,62 +32,11 @@ export const AdminPanelPlaceList = () => { return (
-
-
- Estado - -
- -
- Pueblo mágico - -
-
- -
- - } - columns={columns} data={placeList} selectableRows className="town_list_table"/> -
+ + } + columns={columns} data={placeList} selectableRows className="data_table"/>
); } \ No newline at end of file diff --git a/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css b/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css index 10d24734..8533e5ab 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css +++ b/web/src/components/admin_panel_places/admin_panel_place_list/assets/css/styles.css @@ -1,22 +1,19 @@ .place_list_cnt{ display: flex; - flex-direction: column; height: 100%; width: 100%; } -.place_list_header{ - width: 100%; - height: 10%; - display: flex; - justify-content: center; - align-items: center; - flex-direction: row; +.data_table{ + height: 100%; } -.place_list_body{ - width: 100%; - display: flex; - flex-direction: column; - height: 90%; -} +.bhFeAR{ + display: flex !important; + height: 100%; +} + +.rdt_TableBody{ + max-height: 100%; + overflow-y: auto; +} \ No newline at end of file -- GitLab From 5b5efdafc9e6aca484b84ab0da5c93e58ec78448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 14:57:39 -0600 Subject: [PATCH 33/60] Se elimina un input innecesario --- .../admin_panel_place_register.tsx | 67 ++----------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx b/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx index 78bda39c..dc04cd17 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx +++ b/web/src/components/admin_panel_places/admin_panel_place_register/admin_panel_place_register.tsx @@ -5,16 +5,17 @@ import "./assets/css/styles.css"; import { MapComponent } from "../../map/map"; import { usePlace } from "../../../hooks/usePlace"; import { languaguesList } from "../../../constants/languages"; -import { ToastContainer, toast } from "react-toastify"; import { LoadingScreen } from "../../loading_screen/loading_screen"; import { MultipleImagesDropzone } from "../../multiple_images_dropzone/multiple_images_dropzone"; import { AvailableDays, availableDaysList } from "../../../infraestructure/entities/place"; interface props { setIsWindowActive: Dispatch>; + idTown: number; + forceRenderList: () => void; } -export const AdminPanelPlaceRegister = ({setIsWindowActive}: props) => { +export const AdminPanelPlaceRegister = ({setIsWindowActive, idTown, forceRenderList}: props) => { const { register, handleSubmit, @@ -26,14 +27,11 @@ export const AdminPanelPlaceRegister = ({setIsWindowActive}: props) => { setDescriptions, setLanguageDescriptionIndexSelected, isLoading, - statesList, - updateTownsList, - townsList, updateTimeForm, availableDays, setAvailableDays, resetField, - } = usePlace(); + } = usePlace(idTown, forceRenderList, setIsWindowActive); return (
@@ -165,54 +163,7 @@ export const AdminPanelPlaceRegister = ({setIsWindowActive}: props) => {

{errors.available?.message || errors.startDate?.message || errors.endDate?.message}

- -
-
- Pueblo mágico al que pertenece el lugar -
-
-
- Estado - -
-
- Pueblo mágico - -
-
-

{errors.idTown?.message}

-
- +

{errors.imagesList?.message}

@@ -227,14 +178,6 @@ export const AdminPanelPlaceRegister = ({setIsWindowActive}: props) => {

{errors.latitude?.message}

-
-- GitLab From 6ba92cbcfd3c0e6ad06a6a14d3ef0b87febb8eb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 14:58:13 -0600 Subject: [PATCH 34/60] =?UTF-8?q?Se=20agrega=20una=20funci=C3=B3n=20que=20?= =?UTF-8?q?actualiza=20el=20componente=20de=20la=20lista=20de=20lugares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin_panel_place_screen.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx b/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx index af5358dc..621f47a3 100644 --- a/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx +++ b/web/src/components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen.tsx @@ -1,20 +1,28 @@ -import { Dispatch, SetStateAction } from "react"; +import { Dispatch, SetStateAction, useState } from "react"; import { AdminPanelPlaceRegister } from "../admin_panel_place_register/admin_panel_place_register"; import "./assets/css/styles.css"; import { AdminPanelPlaceList } from "../admin_panel_place_list/admin_panel_place_list"; +import { Town } from "../../../infraestructure/entities/town"; interface props { isWindowActive: boolean; setIsWindowActive: Dispatch>; + town: Town | undefined; } -export const AdminPanelPlaceScreen = ({isWindowActive,setIsWindowActive}: props) => { +export const AdminPanelPlaceScreen = ({isWindowActive,setIsWindowActive, town}: props) => { + const [renderCount, setRenderCount] = useState(0); + + const forceRenderList = () =>{ + setRenderCount(prevCount => prevCount + 1); + } + return (
Administrar lugares dentro de Pueblo Mágico
{ - isWindowActive && + isWindowActive && } - +
); -- GitLab From c2c038d5b6ce88641ea66fb97f49e9c8b057892e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 14:59:15 -0600 Subject: [PATCH 35/60] =?UTF-8?q?Se=20agrega=20las=20funciones=20para=20ob?= =?UTF-8?q?tener=20la=20informaci=C3=B3n=20de=20un=20admin=20y=20registrar?= =?UTF-8?q?=20uno=20nuevo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/hooks/useAdmin.tsx | 46 +++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/web/src/hooks/useAdmin.tsx b/web/src/hooks/useAdmin.tsx index 5d6c60bc..79eb2e94 100644 --- a/web/src/hooks/useAdmin.tsx +++ b/web/src/hooks/useAdmin.tsx @@ -1,8 +1,11 @@ import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form"; import { AdminDatasourceProd } from "../data/datasources/prod/admin_datasource"; import { AdminRepositoryProd } from "../data/repositories/prod/admin_repository"; -import { AdminFormValues } from "../infraestructure/entities/admin_form_values"; +import { Admin, AdminFormValues } from "../infraestructure/entities/admin_form_values"; import { toast } from "react-toastify"; +import axios, { AxiosError } from "axios"; +import { useState } from "react"; +import { showErrorAxios } from "../utils/Messages"; const adminDatasource = new AdminDatasourceProd(); const adminRepository = new AdminRepositoryProd(adminDatasource); @@ -37,7 +40,7 @@ const resolver: Resolver = async (data) => { type: "required", message: "La contraseña es requerida" }; - }else if(data.confirmPassword!=data.password){ + }else if(data.confirmPassword!==data.password){ errors.confirmPassword = { type: "validate", message: "Las contraseñas deben coincidir" @@ -69,26 +72,53 @@ export const useAdmin = () => { register, handleSubmit, formState: {errors}, - setValue } = useForm({resolver}); + const [errorMessage, setErrorMessage] = useState(''); const onSubmit: SubmitHandler = (data: AdminFormValues) => { const fetch = async () => { try{ - //await adminRepository.registerAdmin(data); - console.log(data); + await adminRepository.registerAdmin(data); }catch(error: any){ - + if(axios.isAxiosError(error)){ + error as AxiosError; + switch(error.code){ + case(axios.AxiosError.ERR_BAD_REQUEST): + setErrorMessage("Acceso no autorizado"); + break; + case(axios.AxiosError.ERR_NETWORK): + setErrorMessage("Conexión con el servidor fallida"); + break; + } + } + throw new Error(); } } toast.promise( fetch(),{ pending: "Subiendo datos...", success: "Los datos se han subido correctamente", - error: "Sucedio un error" + error: errorMessage } ) } - return {register, handleSubmit, errors, onSubmit}; + const getAdminInfo = async (): Promise => { + const token = localStorage.getItem('token'); + if(token){ + try{ + const actualAdmin = await adminRepository.getAdminInfo(token); + return actualAdmin; + }catch(error: any){ + if(axios.isAxiosError(error)){ + error as AxiosError; + showErrorAxios(error); + } + } + return null; + } + return null; + } + + return {register, handleSubmit, errors, onSubmit, getAdminInfo}; } \ No newline at end of file -- GitLab From b868ec96eb5206129dbb3ad973464812c30dffe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:00:44 -0600 Subject: [PATCH 36/60] Se modifica para que se obtengan los lugares de un pueblo al llamar al hook --- web/src/hooks/usePlace.tsx | 39 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/web/src/hooks/usePlace.tsx b/web/src/hooks/usePlace.tsx index 9476cbc0..19d32499 100644 --- a/web/src/hooks/usePlace.tsx +++ b/web/src/hooks/usePlace.tsx @@ -1,11 +1,9 @@ import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form" import { Place, AvailableDays } from "../infraestructure/entities/place"; import { toast } from "react-toastify"; -import { useEffect, useState } from "react"; +import { Dispatch, SetStateAction, useEffect, useState } from "react"; import axios, { AxiosError } from "axios"; import { languaguesList } from "../constants/languages"; -import { useGetStatesList } from "./useGetStatesList"; -import { useTown } from "./useTown"; import { MIN_NUMBER_PLACE_IMAGES } from "../constants/images_nuber"; import { PlaceDatasourceProd } from "../data/datasources/prod/place_datasource"; import { PlaceRepositoryProd } from "../data/repositories/prod/place_repository"; @@ -122,7 +120,8 @@ const resolver: Resolver = async (data) => { }; }; -export const usePlace = () => { +export const usePlace = (idTown: number, forceRenderList?: () => void, +setIsWindowActive?: Dispatch>) => { const { register, handleSubmit, @@ -137,35 +136,25 @@ export const usePlace = () => { const [availableDays, setAvailableDays] = useState(AvailableDays.WEEKEND); const [placeList, setPlaceList] = useState([]); const [isLoading, setIsLoading] = useState(false); - const {townsList, getTownsByState} = useTown(); - const {getStates, statesList} = useGetStatesList(); const [pending, setPending] = useState(false); useEffect(() => { setIsLoading(true); - const getStatesList = async () => { - try{ - getStates(); - }catch(error: any){ - if(axios.isAxiosError(error)){ - error as AxiosError; - showErrorAxios(error); - } - } - } - getStatesList(); + updatePlacesByTown(idTown); + setValue('idTown', idTown); setValue('available',availableDays,{shouldValidate: true}); setIsLoading(false); },[]); - const updateTownsList = (idState: number, stateName: string) => { - getTownsByState(idState, stateName); - } - const onSubmit : SubmitHandler = (data: Place) => { const fetch = async () => { try{ - await placeRepository.registerPlace(data); + await placeRepository.registerPlace(data).then(() =>{ + if(forceRenderList && setIsWindowActive){ + forceRenderList(); + setIsWindowActive(false); + } + }); }catch(error: any){ if(axios.isAxiosError(error)){ error as AxiosError; @@ -176,6 +165,9 @@ export const usePlace = () => { case(axios.AxiosError.ERR_NETWORK): setErrorMessage("Conexión con el servidor fallida"); break; + default: + setErrorMessage(error.message); + break; } } throw new Error(); @@ -230,9 +222,6 @@ export const usePlace = () => { setDescriptions, clearErrors, isLoading, - statesList, - townsList, - updateTownsList, updateTimeForm, availableDays, setAvailableDays, -- GitLab From 73d8e1760c5ba88654e9785c164bcdd605163c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:03:05 -0600 Subject: [PATCH 37/60] =?UTF-8?q?Se=20crea=20un=20hook=20que=20guarda=20la?= =?UTF-8?q?=20l=C3=B3gica=20de=20la=20p=C3=A1gina=20de=20inicio=20de=20un?= =?UTF-8?q?=20administrador?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/hooks/useAdminHomePage.tsx | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 web/src/hooks/useAdminHomePage.tsx diff --git a/web/src/hooks/useAdminHomePage.tsx b/web/src/hooks/useAdminHomePage.tsx new file mode 100644 index 00000000..97b7939b --- /dev/null +++ b/web/src/hooks/useAdminHomePage.tsx @@ -0,0 +1,59 @@ +import { useEffect, useState } from "react"; +import { AdminSelectedPanel } from "../constants/selected_panel"; +import { useAuth } from "../context/auth_context"; +import { Town } from "../infraestructure/entities/town"; +import { useWindowShow } from "./useWindowShow"; +import { useAdmin } from "./useAdmin"; +import { UserRole } from "../constants/roles"; +import { useTown } from "./useTown"; + +export const useAdminHomePage = () => { + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(false); + const [errorMessage, setErrorMessage] = useState(""); + const [collapsed, setCollapsed] = useState(true); + const {setIsWindowActive, isWindowActive} = useWindowShow(); + const [selectedPanel, setSelectedPanel] = useState(AdminSelectedPanel.PLACES); + const {getTownById} = useTown(); + const [town, setTown] = useState(); + const {user, logout} = useAuth(); + const {getAdminInfo} = useAdmin(); + + useEffect(() => { + const checkAdminRole = async () => { + const admin = await getAdminInfo(); + if(admin){ + if(admin.role!==UserRole.ADMIN){ + setError(true); + setErrorMessage("No estas autorizado para acceder a esta página") + setTimeout(() => { + logout(); + }, 5000); + return; + } + + if(admin.idTown){ + const townFetched = await getTownById(admin.idTown); + if(townFetched){ + setTown(townFetched); + } + } + } + setIsLoading(false); + }; + checkAdminRole(); + },[user]); + + return { + collapsed, + isWindowActive, + selectedPanel, + setCollapsed, + setSelectedPanel, + setIsWindowActive, + isLoading, + error, + errorMessage, + town + }; +} \ No newline at end of file -- GitLab From 94b07b9016e25c42639777629d00926f2ac2f23d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:04:26 -0600 Subject: [PATCH 38/60] =?UTF-8?q?Se=20cambia=20la=20l=C3=B3gica=20a=20un?= =?UTF-8?q?=20hook,=20se=20agrega=20una=20ventana=20que=20muestra=20errore?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pages/home/admin_page/admin_home_page.tsx | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/web/src/pages/home/admin_page/admin_home_page.tsx b/web/src/pages/home/admin_page/admin_home_page.tsx index 54eed225..4a8d4e41 100644 --- a/web/src/pages/home/admin_page/admin_home_page.tsx +++ b/web/src/pages/home/admin_page/admin_home_page.tsx @@ -1,19 +1,41 @@ import { Menu, MenuItem, Sidebar } from "react-pro-sidebar" import './assets/styles/style.css'; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { faLocation, faMonument, faPlaceOfWorship, faUserTie } from "@fortawesome/free-solid-svg-icons"; -import { useState } from "react"; +import { faLocation, faPlaceOfWorship } from "@fortawesome/free-solid-svg-icons"; import { AdminPanelNavBar } from "../../../components/admin_panel_navbar/admin_navbar"; import { SidebarHeader } from "../../../components/sidebar_header/sidebar_header"; import { AdminPanelPlaceScreen } from "../../../components/admin_panel_places/admin_panel_place_screen/admin_panel_place_screen"; import { AdminSelectedPanel } from "../../../constants/selected_panel"; -import { useWindowShow } from "../../../hooks/useWindowShow"; +import { useAdminHomePage } from "../../../hooks/useAdminHomePage"; +import { LoadingScreen } from "../../../components/loading_screen/loading_screen"; +import { ErrorWindow } from "../../../components/error_window/error_window"; +import { LoadingSpinner } from "../../../components/loading_spinner/loading_spinner"; +import { ToastContainer } from "react-toastify"; export const AdminHomePage = () => { - const [collapsed, setCollapsed] = useState(true); - const {setIsWindowActive, isWindowActive} = useWindowShow(); - const [selectedPanel, setSelectedPanel] = useState(AdminSelectedPanel.PLACES); - + const { + collapsed, + isWindowActive, + setCollapsed, + selectedPanel, + setSelectedPanel, + setIsWindowActive, + isLoading, + error, + errorMessage, + town + } = useAdminHomePage(); + + if(isLoading) return ; + + if(error) return ( +
+ + Redirigiendo... + +
+ ); + return (
{ {(() => { switch (selectedPanel) { case AdminSelectedPanel.PLACES: - return ; + return ; case AdminSelectedPanel.ACTIVITIES: return
default: @@ -56,6 +78,14 @@ export const AdminHomePage = () => { } })()}
+
-- GitLab From 49933407614cf81d54209fa35a6e0d4930ea904d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:05:02 -0600 Subject: [PATCH 39/60] =?UTF-8?q?Se=20renombra=20una=20variable=20y=20se?= =?UTF-8?q?=20agrega=20un=20m=C3=A9todo=20para=20obtener=20un=20pueblo=20p?= =?UTF-8?q?or=20medio=20de=20su=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/hooks/useTown.tsx | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/web/src/hooks/useTown.tsx b/web/src/hooks/useTown.tsx index e51a970a..031249c8 100644 --- a/web/src/hooks/useTown.tsx +++ b/web/src/hooks/useTown.tsx @@ -2,7 +2,7 @@ import { useState } from "react"; import { TownDatasourceProd } from "../data/datasources/prod/town_datasource" import { TownRepositoryProd } from "../data/repositories/prod/town_repository"; import { FieldErrors, Resolver, SubmitHandler, useForm } from "react-hook-form"; -import { Town, TownFormValues } from "../infraestructure/entities/town"; +import { Town } from "../infraestructure/entities/town"; import { toast } from "react-toastify"; import axios, { AxiosError } from "axios"; import { showErrorAxios } from "../utils/Messages"; @@ -10,8 +10,8 @@ import { showErrorAxios } from "../utils/Messages"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); -const resolver: Resolver = async (data) => { - const errors: FieldErrors = {}; +const resolver: Resolver = async (data) => { + const errors: FieldErrors = {}; if (!data.name) { errors.name = { @@ -60,11 +60,11 @@ export const useTown = (forceRenderList?: () => void) => { handleSubmit, formState: {errors}, setValue - } = useForm({resolver}); + } = useForm({resolver}); const [townsList, setTownsList] = useState([]); const [errorMessage, setErrorMessage] = useState(""); - const onSubmit: SubmitHandler = (data: TownFormValues) => { + const onSubmit: SubmitHandler = (data: Town) => { const fetch = async () => { try{ await townRepository.registerTown(data); @@ -107,5 +107,18 @@ export const useTown = (forceRenderList?: () => void) => { } } - return {register, handleSubmit, errors, onSubmit, setValue, townsList, getTownsByState, setTownsList}; + const getTownById = async (idTown: number): Promise => { + try{ + const town = await townRepository.getTown(idTown); + return town; + }catch(error: any){ + if(axios.isAxiosError(error)){ + error as AxiosError; + showErrorAxios(error); + } + } + return null; + } + + return {register, handleSubmit, errors, onSubmit, setValue, townsList, getTownsByState, setTownsList, getTownById}; } \ No newline at end of file -- GitLab From 46c6cc1b89ed1baa8e06ff6931aa6e924f122274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:24:12 -0600 Subject: [PATCH 40/60] Se agrega el campo del apellido y se modifica la forma en que se selecciona el pueblo --- .../sa_panel_admin_register.tsx | 116 ++++++++---------- 1 file changed, 50 insertions(+), 66 deletions(-) diff --git a/web/src/components/sa_panel_admin/sa_panel_admin_register/sa_panel_admin_register.tsx b/web/src/components/sa_panel_admin/sa_panel_admin_register/sa_panel_admin_register.tsx index 89bb73a1..eab22586 100644 --- a/web/src/components/sa_panel_admin/sa_panel_admin_register/sa_panel_admin_register.tsx +++ b/web/src/components/sa_panel_admin/sa_panel_admin_register/sa_panel_admin_register.tsx @@ -1,14 +1,11 @@ -import { Dispatch, SetStateAction, useEffect, useState } from "react"; +import { Dispatch, SetStateAction } from "react"; import './assets/css/styles.css' import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faWindowClose, faEye, faEyeSlash } from "@fortawesome/free-solid-svg-icons"; -import { useAdminRegister } from "../../../hooks/useAdminRegister"; +import { useAdmin } from "../../../hooks/useAdmin"; import { usePasswoordVisibility } from "../../../hooks/usePasswordVisibility"; import { State } from "../../../infraestructure/entities/state"; import { useTown } from "../../../hooks/useTown"; -import { Town } from "../../../infraestructure/entities/town"; -import axios, { AxiosError } from "axios"; -import { ToastContainer, toast } from "react-toastify"; interface props { setWindowActive: Dispatch>, @@ -22,7 +19,7 @@ export const SuperadminPanelAdminRegister = ({setWindowActive, setShowRegisterPa errors, handleSubmit, onSubmit, - } = useAdminRegister(); + } = useAdmin(); const { values, @@ -32,47 +29,6 @@ export const SuperadminPanelAdminRegister = ({setWindowActive, setShowRegisterPa const {townsList, getTownsByState, setTownsList} = useTown(); - useEffect(() => { - const getTownsList = async () => { - try { - if (statesList) { - const townsListBackup: Town[] = []; - statesList.forEach((state) => { - getTownsByState(state.stateId, state.name); - if (townsList) { - townsListBackup.push(...townsList); - } - }); - setTownsList(townsListBackup); - } - } catch (error: any) { - if (axios.isAxiosError(error)) { - error as AxiosError; - let message = ""; - switch(error.code){ - case(axios.AxiosError.ERR_BAD_REQUEST): - message = "Acceso no autorizado"; - break; - case(axios.AxiosError.ERR_NETWORK): - message = "Conexión con el servidor fallida"; - break; - } - toast.error(message, { - position: "bottom-right", - autoClose: 1500, - hideProgressBar: false, - closeOnClick: true, - pauseOnHover: false, - draggable: true, - progress: undefined, - theme: "colored" - }); - } - } - } - getTownsList(); - }, []); - return (
@@ -102,6 +58,16 @@ export const SuperadminPanelAdminRegister = ({setWindowActive, setShowRegisterPa

{errors.name?.message}

+
+ + +

{errors.lastName?.message}

+
+
- {townsList === null || townsList.length===0 - ? - - : +
+ Estado +
+
+ Pueblo mágico + - } +

{errors.townAdmin?.message}

- - -
-- GitLab From 16afdf05f9f21807cdba84bbcedf192d82d3fdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:25:43 -0600 Subject: [PATCH 41/60] Se modifica la altura de la ventana --- .../sa_panel_admin_register/assets/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/sa_panel_admin/sa_panel_admin_register/assets/css/styles.css b/web/src/components/sa_panel_admin/sa_panel_admin_register/assets/css/styles.css index 5eca8d6e..12fd3910 100644 --- a/web/src/components/sa_panel_admin/sa_panel_admin_register/assets/css/styles.css +++ b/web/src/components/sa_panel_admin/sa_panel_admin_register/assets/css/styles.css @@ -10,7 +10,7 @@ bottom: 0; margin: auto; width: 30vw; - height: 60vh; + height: 70vh; background: green; display: flex; flex-direction: column; -- GitLab From 1dcc377f996d20c631a9ef3c2e02660f89901e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:26:08 -0600 Subject: [PATCH 42/60] Se agrega el validador para el apellido --- web/src/hooks/useAdmin.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/src/hooks/useAdmin.tsx b/web/src/hooks/useAdmin.tsx index 79eb2e94..b45bccd3 100644 --- a/web/src/hooks/useAdmin.tsx +++ b/web/src/hooks/useAdmin.tsx @@ -20,6 +20,13 @@ const resolver: Resolver = async (data) => { }; } + if (!data.lastName) { + errors.lastName = { + type: "required", + message: "El apellido del administrador es requerido" + }; + } + if (!data.email) { errors.email = { type: "required", -- GitLab From 2819251f007998b15354d04c2191eb5807e43731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:26:31 -0600 Subject: [PATCH 43/60] Se agrega un componente que visualiza las notificaciones --- .../super_admin_page/super_admin_home_page.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/pages/home/super_admin_page/super_admin_home_page.tsx b/web/src/pages/home/super_admin_page/super_admin_home_page.tsx index 59645e97..b0a861ee 100644 --- a/web/src/pages/home/super_admin_page/super_admin_home_page.tsx +++ b/web/src/pages/home/super_admin_page/super_admin_home_page.tsx @@ -8,8 +8,10 @@ import { SidebarHeader } from "../../../components/sidebar_header/sidebar_header import { SuperadminPanelTownScreen } from "../../../components/sa_panel_town/sa_panel_town_screen/sa_panel_town_screen"; import { SuperadminPanelAdminScreen } from "../../../components/sa_panel_admin/sa_panel_admin_screen/sa_panel_admin_screen"; import { useGetStatesList } from "../../../hooks/useGetStatesList"; -import axios from "axios"; +import axios, { AxiosError } from "axios"; import { LoadingScreen } from "../../../components/loading_screen/loading_screen"; +import { ToastContainer } from "react-toastify"; +import { showErrorAxios } from "../../../utils/Messages"; export const SuperAdminHomePage = () => { const [collapsed, setCollapsed] = useState(true); @@ -25,7 +27,8 @@ export const SuperAdminHomePage = () => { setIsLoading(false); }catch(error: any){ if(axios.isAxiosError(error)){ - //console.log(error) + error as AxiosError; + showErrorAxios(error); } } } @@ -80,6 +83,14 @@ export const SuperAdminHomePage = () => { statesList={statesList} /> } +
-- GitLab From a8dfbc828d9dd829c877c0e42c27eabd55a38899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 23 Jun 2024 15:27:18 -0600 Subject: [PATCH 44/60] Se agregan los estilos para el encabezado y el cuerpo de la lista de pueblos --- .../sa_panel_town_list/assets/css/styles.css | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/web/src/components/sa_panel_town/sa_panel_town_list/assets/css/styles.css b/web/src/components/sa_panel_town/sa_panel_town_list/assets/css/styles.css index 5834a88a..4dbeaae5 100644 --- a/web/src/components/sa_panel_town/sa_panel_town_list/assets/css/styles.css +++ b/web/src/components/sa_panel_town/sa_panel_town_list/assets/css/styles.css @@ -1,5 +1,20 @@ -.town_list_content{ +.town_list_cnt{ background: white; width: 100%; height: 100%; + display: flex; + flex-direction: column; +} + +.town_list_header{ + display: flex; + justify-content: center; + align-items: center; + height: 10%; + width: 100%; +} + +.town_list_body{ + width: 100%; + height: 90%; } \ No newline at end of file -- GitLab From 313d3587a757740ee7665ccb3a9fd3e25a33cd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 12:40:05 -0600 Subject: [PATCH 45/60] Se agrega un metodo para obtener un estado en base en su id --- web/src/hooks/useGetStatesList.tsx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/web/src/hooks/useGetStatesList.tsx b/web/src/hooks/useGetStatesList.tsx index b862ff74..69edc249 100644 --- a/web/src/hooks/useGetStatesList.tsx +++ b/web/src/hooks/useGetStatesList.tsx @@ -1,8 +1,9 @@ import { useState } from "react"; import { State } from "../infraestructure/entities/state"; -import axios from "axios"; +import axios, { AxiosError } from "axios"; import { TownDatasourceProd } from "../data/datasources/prod/town_datasource"; import { TownRepositoryProd } from "../data/repositories/prod/town_repository"; +import { showErrorAxios } from "../utils/Messages"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); @@ -15,9 +16,29 @@ export const useGetStatesList = () => { setStatesList(states); }catch(error: any){ if(axios.isAxiosError(error)){ - //console.log(error) + error as AxiosError; + showErrorAxios(error); } } } - return {getStates, statesList}; + + const getStateById = async (idState: number) : Promise => { + let stateReturned: State | null = null; + try{ + const states = await townRepository.getStates(); + states.forEach((state) => { + if(state.stateId===idState){ + stateReturned = state; + return; + } + }) + }catch(error: any){ + if(axios.isAxiosError(error)){ + error as AxiosError; + showErrorAxios(error); + } + } + return stateReturned; + } + return {getStates, statesList, getStateById}; } \ No newline at end of file -- GitLab From f2f171283d7adea5d9f415aacfb04782b919e42d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 12:40:11 -0600 Subject: [PATCH 46/60] Se modifico para que al obtener un pueblo se obtenga tambien el nombre del estado --- web/src/hooks/useTown.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/hooks/useTown.tsx b/web/src/hooks/useTown.tsx index 031249c8..551e2802 100644 --- a/web/src/hooks/useTown.tsx +++ b/web/src/hooks/useTown.tsx @@ -6,6 +6,7 @@ import { Town } from "../infraestructure/entities/town"; import { toast } from "react-toastify"; import axios, { AxiosError } from "axios"; import { showErrorAxios } from "../utils/Messages"; +import { useGetStatesList } from "./useGetStatesList"; const townDatasource = new TownDatasourceProd(); const townRepository = new TownRepositoryProd(townDatasource); @@ -63,6 +64,7 @@ export const useTown = (forceRenderList?: () => void) => { } = useForm({resolver}); const [townsList, setTownsList] = useState([]); const [errorMessage, setErrorMessage] = useState(""); + const {getStateById} = useGetStatesList(); const onSubmit: SubmitHandler = (data: Town) => { const fetch = async () => { @@ -110,6 +112,10 @@ export const useTown = (forceRenderList?: () => void) => { const getTownById = async (idTown: number): Promise => { try{ const town = await townRepository.getTown(idTown); + const state = await getStateById(town.idState); + if(state){ + town.state = state.name; + } return town; }catch(error: any){ if(axios.isAxiosError(error)){ -- GitLab From 2e0c5cbf55db51fc1e009811db1a3a9a135eed6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 12:40:36 -0600 Subject: [PATCH 47/60] Se agrego una opcion para la informacion del pueblo --- web/src/constants/selected_panel.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/constants/selected_panel.ts b/web/src/constants/selected_panel.ts index 90b3d4e6..3498fa32 100644 --- a/web/src/constants/selected_panel.ts +++ b/web/src/constants/selected_panel.ts @@ -1,4 +1,5 @@ export enum AdminSelectedPanel { + TOWN_INFO = 'town_info', PLACES = "places", ACTIVITIES = "activities" } \ No newline at end of file -- GitLab From cb73ec356c61a7784f93c9ee80abd48558255ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 12:41:24 -0600 Subject: [PATCH 48/60] Se cambio el panel seleccionado por defecto al que muestra la informacion del pueblo --- web/src/hooks/useAdminHomePage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/hooks/useAdminHomePage.tsx b/web/src/hooks/useAdminHomePage.tsx index 97b7939b..7673f694 100644 --- a/web/src/hooks/useAdminHomePage.tsx +++ b/web/src/hooks/useAdminHomePage.tsx @@ -13,7 +13,7 @@ export const useAdminHomePage = () => { const [errorMessage, setErrorMessage] = useState(""); const [collapsed, setCollapsed] = useState(true); const {setIsWindowActive, isWindowActive} = useWindowShow(); - const [selectedPanel, setSelectedPanel] = useState(AdminSelectedPanel.PLACES); + const [selectedPanel, setSelectedPanel] = useState(AdminSelectedPanel.TOWN_INFO); const {getTownById} = useTown(); const [town, setTown] = useState(); const {user, logout} = useAuth(); -- GitLab From 33deefe4feb8a6d01997b90ea4884395d4ca6391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 15:57:20 -0600 Subject: [PATCH 49/60] Se mueven la preview a las props --- web/src/components/image_dropzone/image_dropzone.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/src/components/image_dropzone/image_dropzone.tsx b/web/src/components/image_dropzone/image_dropzone.tsx index 34a12cdc..fab94e8f 100644 --- a/web/src/components/image_dropzone/image_dropzone.tsx +++ b/web/src/components/image_dropzone/image_dropzone.tsx @@ -1,18 +1,19 @@ import { ToastContainer, toast } from 'react-toastify'; import './assets/css/styles.css' import { useDropzone } from "react-dropzone"; -import { useState } from 'react'; +import { Dispatch, SetStateAction, useState } from 'react'; import "react-toastify/dist/ReactToastify.css"; import { UseFormSetValue } from 'react-hook-form'; import { Town } from '../../infraestructure/entities/town'; interface props { - setValue : UseFormSetValue + setValue : UseFormSetValue; + preview : string | ArrayBuffer | null; + setPreview: Dispatch>; } -export const ImageDropzone = ({setValue}: props) => { - const MAX_SIZE = 10485760; - const [preview, setPreview] = useState(null); +export const ImageDropzone = ({setValue, preview, setPreview}: props) => { + const MAX_SIZE = 10485760; const {getRootProps, getInputProps} = useDropzone( { multiple: false, -- GitLab From 59a61247e07debec1fe23afd7d4a14fb286855ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 15:57:45 -0600 Subject: [PATCH 50/60] Se modifica para que la ventana aparezca por encima de todo --- .../sa_panel_town/sa_panel_town_register/css/styles.css | 1 + 1 file changed, 1 insertion(+) diff --git a/web/src/components/sa_panel_town/sa_panel_town_register/css/styles.css b/web/src/components/sa_panel_town/sa_panel_town_register/css/styles.css index 67c03469..db24e75b 100644 --- a/web/src/components/sa_panel_town/sa_panel_town_register/css/styles.css +++ b/web/src/components/sa_panel_town/sa_panel_town_register/css/styles.css @@ -11,6 +11,7 @@ margin: auto; width: 70vw; height: 90vh; + z-index: 999; background: green; display: flex; flex-direction: column; -- GitLab From 58a16b53cc9af6e8e154b0ea21a60fb5646f7a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 15:58:18 -0600 Subject: [PATCH 51/60] Se cambia el campo de estado del pueblo por su id --- web/src/data/datasources/prod/town_datasource.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/data/datasources/prod/town_datasource.ts b/web/src/data/datasources/prod/town_datasource.ts index 87493d4c..fcbba15e 100644 --- a/web/src/data/datasources/prod/town_datasource.ts +++ b/web/src/data/datasources/prod/town_datasource.ts @@ -26,7 +26,7 @@ export class TownDatasourceProd implements TownDatasourceInf{ formToSend.append('name',form.name); formToSend.append('descriptionES',form.descriptionES || ''); formToSend.append('descriptionEN',form.descriptionEN || ''); - formToSend.append('state', form.state); + formToSend.append('state', String(form.idState)); formToSend.append('image',form.imageURL || ''); const headers = { @@ -75,7 +75,7 @@ export class TownDatasourceProd implements TownDatasourceInf{ formToSend.append('descriptionES',form.descriptionES || ''); formToSend.append('descriptionEN',form.descriptionEN || ''); formToSend.append('image',form.imageURL || ''); - formToSend.append('state', form.state); + formToSend.append('state', String(form.idState)); const headers = { 'Content-Type': 'multipart/form-data' -- GitLab From ed3d614e0262cd272aaa27d66441232e6693973a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Wed, 26 Jun 2024 16:14:59 -0600 Subject: [PATCH 52/60] Se crea el componente y los estilos para el panel que muestra la informacion del pueblo que se administra --- .../admin_town_info/admin_town_info.tsx | 113 ++++++++++++++++++ .../admin_town_info/assets/css/styles.css | 66 ++++++++++ 2 files changed, 179 insertions(+) create mode 100644 web/src/components/admin_town_info/admin_town_info.tsx create mode 100644 web/src/components/admin_town_info/assets/css/styles.css diff --git a/web/src/components/admin_town_info/admin_town_info.tsx b/web/src/components/admin_town_info/admin_town_info.tsx new file mode 100644 index 00000000..ed28ca88 --- /dev/null +++ b/web/src/components/admin_town_info/admin_town_info.tsx @@ -0,0 +1,113 @@ +import { Dispatch, SetStateAction} from "react"; +import { Town } from "../../infraestructure/entities/town"; +import "./assets/css/styles.css"; +import { faEdit, faLanguage } from "@fortawesome/free-solid-svg-icons"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { LoadingScreen } from "../loading_screen/loading_screen"; +import { useAdminTownInfo } from "../../hooks/useAdminTownInfo"; +import { SuperadminPanelTownRegister } from "../sa_panel_town/sa_panel_town_register/sa_panel_town_register"; + +interface props { + isWindowActive: boolean; + setIsWindowActive: Dispatch>; + town: Town | undefined; + updateTown: () => Promise; +} + +export const AdminTownInfo = ({updateTown, isWindowActive, setIsWindowActive, town}: props) => { + const { + isEnglish, + isLoading, + setIsEnglish, + setIsLoading, + renderCount, + forceRenderList, + statesList + } = useAdminTownInfo(updateTown); + + if(!town){ + return ( +
+ No tienes un pueblo asignado +
+ ); + } + + return ( +
+ {isWindowActive && + + } +
+ {isLoading && +
+ +
+ } + +
+

{town?.name}

+
+
+
+ setIsLoading(false)}/> +
+
+
+
+ + + { + if(!isWindowActive){ + setIsEnglish(!isEnglish); + } + } + } + /> +
+ { + if(!isWindowActive){ + setIsWindowActive(true); + } + } + } + /> +
+ { + isEnglish ? +