From 0b4f1b1ec840eb15ab3bed1baba25d8237ca9479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Sun, 21 Jul 2024 13:04:24 -0600 Subject: [PATCH 1/9] =?UTF-8?q?Se=20agreg=C3=A1n=20los=20m=C3=A9todos=20pa?= =?UTF-8?q?ra=20obtener=20o=20actualizar=20a=20un=20lugar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/datasources/prod/place_datasource.ts | 81 ++++++++++++------- .../repositories/prod/place_repository.ts | 8 ++ .../datasources/place_datasource.ts | 2 + .../repositories/place_repository.ts | 2 + 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/web/src/data/datasources/prod/place_datasource.ts b/web/src/data/datasources/prod/place_datasource.ts index 938bdd97..3b9f89e9 100644 --- a/web/src/data/datasources/prod/place_datasource.ts +++ b/web/src/data/datasources/prod/place_datasource.ts @@ -2,7 +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"; +import { PlaceModel, placeModelToEntity } from "../../models/prod/PlaceModel"; export class PlaceDatasourceProd implements PlaceDatasourceInf{ async registerPlace(form: Place): Promise { @@ -10,7 +10,7 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ formToSend.append('available', form.available); formToSend.append('idTown', String(form.idTown)); formToSend.append('name', form.name); - formToSend.append('categoriesId', form.categoriesId); + formToSend.append('categoriesId', form.categoriesId as string | ''); formToSend.append('descriptionES', form.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', form.descriptions?.[1] ?? ''); formToSend.append('image', form.imagesList?.[0] ?? ''); @@ -37,37 +37,56 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ 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, - categoriesId: value.categoriesId, - openAt: value.openAt, - closeAt: value.closeAt - } - return place; + + const places = data.map((dataES) => { + return placeModelToEntity(dataES); }) return places; } + + async getPlaceById(idPlace: number): Promise { + const {data: dataES} = await axios.get(APIUrl+`/place/${idPlace}`, { + params: { + lang: 'ES' + } + }); + + const {data: dataEN} = await axios.get(APIUrl+`/place/${idPlace}`, { + params: { + lang: 'EN' + } + }); + + const place: Place = placeModelToEntity(dataES); + place.descriptions?.push(dataEN.description); + + return place; + } + + async updatePlace(place: Place): Promise { + const formToSend = new FormData(); + formToSend.append('available', place.available); + formToSend.append('idTown', String(place.idTown)); + formToSend.append('name', place.name); + formToSend.append('categoriesId', place.categoriesId as string | ''); + formToSend.append('descriptionES', place.descriptions?.[0] ?? ''); + formToSend.append('descriptionEN', place.descriptions?.[1] ?? ''); + formToSend.append('image', place.imagesList?.[0] ?? ''); + formToSend.append('latitude', String(place.latitude)); + formToSend.append('longitude', String(place.longitude)); + formToSend.append('openAt', String(place.openAt)); + formToSend.append('closeAt', String(place.closeAt)); + + if(place.available === AvailableDays.CUSTOM){ + formToSend.append('startDate', String(place.startDate)); + formToSend.append('endDate', String(place.endDate)); + } + + const headers = { + 'Content-Type': 'multipart/form-data' + }; + + await axios.patch(APIUrl+`/place/${place.idPlace}`, formToSend,{headers}); + } } \ 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 3f60490e..843fdb8d 100644 --- a/web/src/data/repositories/prod/place_repository.ts +++ b/web/src/data/repositories/prod/place_repository.ts @@ -13,4 +13,12 @@ export class PlaceRepositoryProd implements PlaceRepositoryInf{ async getPlacesByTown(idTown: number): Promise { return this.datasouce.getPlacesByTown(idTown); } + + async getPlaceById(idPlace: number): Promise { + return this.datasouce.getPlaceById(idPlace); + } + + async updatePlace(place: Place): Promise { + return this.datasouce.updatePlace(place); + } } \ 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 2fd94357..5edc862f 100644 --- a/web/src/infraestructure/datasources/place_datasource.ts +++ b/web/src/infraestructure/datasources/place_datasource.ts @@ -3,4 +3,6 @@ import { Place } from "../entities/place"; export interface PlaceDatasourceInf{ registerPlace(form: Place): Promise; getPlacesByTown(idTown: number): Promise; + getPlaceById(idPlace: number): Promise; + updatePlace(place: Place): 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 cd0d4551..733decb2 100644 --- a/web/src/infraestructure/repositories/place_repository.ts +++ b/web/src/infraestructure/repositories/place_repository.ts @@ -3,4 +3,6 @@ import { Place } from "../entities/place"; export interface PlaceRepositoryInf{ registerPlace(form: Place): Promise; getPlacesByTown(idTown: number): Promise; + getPlaceById(idPlace: number): Promise; + updatePlace(place: Place): Promise; } \ No newline at end of file -- GitLab From 5596f2bd462e00f92b7278f20bc99b6d26443d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:11:01 -0600 Subject: [PATCH 2/9] Se cambia el paquete de google maps --- web/package-lock.json | 86 +++++++++---------------------------------- web/package.json | 2 +- 2 files changed, 18 insertions(+), 70 deletions(-) diff --git a/web/package-lock.json b/web/package-lock.json index efcf5001..1a12efab 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -11,7 +11,6 @@ "@fortawesome/free-solid-svg-icons": "^6.5.1", "@fortawesome/react-fontawesome": "^0.2.0", "@hookform/resolvers": "^3.3.4", - "@react-google-maps/api": "^2.19.3", "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", @@ -19,6 +18,7 @@ "@types/node": "^16.18.87", "@types/react": "^18.2.64", "@types/react-dom": "^18.2.21", + "@vis.gl/react-google-maps": "^1.1.0", "axios": "^1.6.8", "react": "^18.2.0", "react-data-table-component": "^7.6.2", @@ -2599,23 +2599,6 @@ "react": ">=16.3" } }, - "node_modules/@googlemaps/js-api-loader": { - "version": "1.16.2", - "resolved": "https://registry.npmjs.org/@googlemaps/js-api-loader/-/js-api-loader-1.16.2.tgz", - "integrity": "sha512-psGw5u0QM6humao48Hn4lrChOM2/rA43ZCm3tKK9qQsEj1/VzqkCqnvGfEOshDbBQflydfaRovbKwZMF4AyqbA==", - "dependencies": { - "fast-deep-equal": "^3.1.3" - } - }, - "node_modules/@googlemaps/markerclusterer": { - "version": "2.5.3", - "resolved": "https://registry.npmjs.org/@googlemaps/markerclusterer/-/markerclusterer-2.5.3.tgz", - "integrity": "sha512-x7lX0R5yYOoiNectr10wLgCBasNcXFHiADIBdmn7jQllF2B5ENQw5XtZK+hIw4xnV0Df0xhN4LN98XqA5jaiOw==", - "dependencies": { - "fast-deep-equal": "^3.1.3", - "supercluster": "^8.0.1" - } - }, "node_modules/@hookform/resolvers": { "version": "3.3.4", "resolved": "https://registry.npmjs.org/@hookform/resolvers/-/resolvers-3.3.4.tgz", @@ -3590,33 +3573,6 @@ "url": "https://opencollective.com/popperjs" } }, - "node_modules/@react-google-maps/api": { - "version": "2.19.3", - "resolved": "https://registry.npmjs.org/@react-google-maps/api/-/api-2.19.3.tgz", - "integrity": "sha512-jiLqvuOt5lOowkLeq7d077AByTyJp+s6hZVlLhlq7SBacBD37aUNpXBz2OsazfeR6Aw4a+9RRhAEjEFvrR1f5A==", - "dependencies": { - "@googlemaps/js-api-loader": "1.16.2", - "@googlemaps/markerclusterer": "2.5.3", - "@react-google-maps/infobox": "2.19.2", - "@react-google-maps/marker-clusterer": "2.19.2", - "@types/google.maps": "3.55.2", - "invariant": "2.2.4" - }, - "peerDependencies": { - "react": "^16.8 || ^17 || ^18", - "react-dom": "^16.8 || ^17 || ^18" - } - }, - "node_modules/@react-google-maps/infobox": { - "version": "2.19.2", - "resolved": "https://registry.npmjs.org/@react-google-maps/infobox/-/infobox-2.19.2.tgz", - "integrity": "sha512-6wvBqeJsQ/eFSvoxg+9VoncQvNoVCdmxzxRpLvmjPD+nNC6mHM0vJH1xSqaKijkMrfLJT0nfkTGpovrF896jwg==" - }, - "node_modules/@react-google-maps/marker-clusterer": { - "version": "2.19.2", - "resolved": "https://registry.npmjs.org/@react-google-maps/marker-clusterer/-/marker-clusterer-2.19.2.tgz", - "integrity": "sha512-x9ibmsP0ZVqzyCo1Pitbw+4b6iEXRw/r1TCy3vOUR3eKrzWLnHYZMR325BkZW2r8fnuWE/V3Fp4QZOP9qYORCw==" - }, "node_modules/@remix-run/router": { "version": "1.15.3", "resolved": "https://registry.npmjs.org/@remix-run/router/-/router-1.15.3.tgz", @@ -4383,9 +4339,9 @@ } }, "node_modules/@types/google.maps": { - "version": "3.55.2", - "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.55.2.tgz", - "integrity": "sha512-JcTwzkxskR8DN/nnX96Pie3gGN3WHiPpuxzuQ9z3516o1bB243d8w8DHUJ8BohuzoT1o3HUFta2ns/mkZC8KRw==" + "version": "3.55.11", + "resolved": "https://registry.npmjs.org/@types/google.maps/-/google.maps-3.55.11.tgz", + "integrity": "sha512-F3VuPtjKj4UGuyym75pqmgPBOHbT/i7I6/D+4DdtSzbeu2aWZG1ENwpbZOd46uO+PSAz9flJEhxxi+b4MVb4gQ==" }, "node_modules/@types/graceful-fs": { "version": "4.1.9", @@ -4845,6 +4801,19 @@ "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==" }, + "node_modules/@vis.gl/react-google-maps": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@vis.gl/react-google-maps/-/react-google-maps-1.1.0.tgz", + "integrity": "sha512-MxDIhCfPRzTQY1c6sS0GFg8Ukl40o13fkIKEaCN0cR1BIrV4LPo+EuCov9WElbe0bOo8MApx5qAbqBKOmLQyKg==", + "dependencies": { + "@types/google.maps": "^3.54.10", + "fast-deep-equal": "^3.1.3" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, "node_modules/@webassemblyjs/ast": { "version": "1.11.6", "resolved": "https://registry.npmjs.org/@webassemblyjs/ast/-/ast-1.11.6.tgz", @@ -9727,14 +9696,6 @@ "node": ">= 0.4" } }, - "node_modules/invariant": { - "version": "2.2.4", - "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", - "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", - "dependencies": { - "loose-envify": "^1.0.0" - } - }, "node_modules/ipaddr.js": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-2.1.0.tgz", @@ -12452,11 +12413,6 @@ "node": ">=4.0" } }, - "node_modules/kdbush": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/kdbush/-/kdbush-4.0.2.tgz", - "integrity": "sha512-WbCVYJ27Sz8zi9Q7Q0xHC+05iwkm3Znipc2XTlrnJbsHMYktW4hPhXUE8Ys1engBrvffoSCqbil1JQAa7clRpA==" - }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -16913,14 +16869,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/supercluster": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/supercluster/-/supercluster-8.0.1.tgz", - "integrity": "sha512-IiOea5kJ9iqzD2t7QJq/cREyLHTtSmUT6gQsweojg9WH2sYJqZK9SswTu6jrscO6D1G5v5vYZ9ru/eq85lXeZQ==", - "dependencies": { - "kdbush": "^4.0.2" - } - }, "node_modules/supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", diff --git a/web/package.json b/web/package.json index f9d8a871..887ef2ba 100644 --- a/web/package.json +++ b/web/package.json @@ -6,7 +6,6 @@ "@fortawesome/free-solid-svg-icons": "^6.5.1", "@fortawesome/react-fontawesome": "^0.2.0", "@hookform/resolvers": "^3.3.4", - "@react-google-maps/api": "^2.19.3", "@testing-library/jest-dom": "^5.17.0", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", @@ -14,6 +13,7 @@ "@types/node": "^16.18.87", "@types/react": "^18.2.64", "@types/react-dom": "^18.2.21", + "@vis.gl/react-google-maps": "^1.1.0", "axios": "^1.6.8", "react": "^18.2.0", "react-data-table-component": "^7.6.2", -- GitLab From 1a95d7f37a16382c8db160a3955fcdd74f1c1e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:11:38 -0600 Subject: [PATCH 3/9] Se editan los tipos de algunos cambios y se crea un objeto vacio para la interface --- web/src/infraestructure/entities/place.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/web/src/infraestructure/entities/place.ts b/web/src/infraestructure/entities/place.ts index bdbe0fb1..46fe46ba 100644 --- a/web/src/infraestructure/entities/place.ts +++ b/web/src/infraestructure/entities/place.ts @@ -2,14 +2,14 @@ export interface Place{ idTown: number; idPlace? : number; name: string; - categoriesId: string; + categoriesId: number[]; descriptions?: string[]; latitude: number; longitude: number; openAt: number; closeAt: number; available: AvailableDays; - imagesList?: File[]; + imagesList?: File[] | string[]; startDate?: Date; endDate?: Date; } @@ -31,4 +31,17 @@ export const availableDaysList= [ { option: AvailableDays.ALL_DAYS, name: 'Todos los dias' }, { option: AvailableDays.WEEKDAYS, name: 'Lunes a Viernes' }, { option: AvailableDays.CUSTOM, name: 'Personalizado' } -]; \ No newline at end of file +]; + +export const EmptyPlace : Place = { + idTown: -1, + idPlace: -1, + name: "", + categoriesId: [], + descriptions: [], + latitude: 0.0, + longitude: 0.0, + openAt: 0, + closeAt: 0, + available: AvailableDays.WEEKEND, +} \ No newline at end of file -- GitLab From b43b1ac8fc627d4558c2449ac5e75e9afd4145da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:12:20 -0600 Subject: [PATCH 4/9] Se reduce la altura de la caja de texto de la descripcion --- .../admin_panel_place_register/assets/css/styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 2aefa5c0..48eeeb9e 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 @@ -95,7 +95,7 @@ } .place_description{ - height: 130px; + height: 100px; padding: 5px; overflow-y: auto; resize: none; -- GitLab From fadd84de7bc2ae255e8a374eace252600bf44e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:13:04 -0600 Subject: [PATCH 5/9] Se agrega un nuevo modelo para la categoria --- web/src/data/models/prod/CategoryModel.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/web/src/data/models/prod/CategoryModel.ts b/web/src/data/models/prod/CategoryModel.ts index f16740fe..2846a79c 100644 --- a/web/src/data/models/prod/CategoryModel.ts +++ b/web/src/data/models/prod/CategoryModel.ts @@ -1,4 +1,10 @@ export interface CategoryModel{ idCategory: number; name: string; +} + +export interface CategoryModelLan { + idCategory: number; + language: string; + name: string; } \ No newline at end of file -- GitLab From afb8fc93f7f82fb4cf88a44db679f27ac77f304d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:13:34 -0600 Subject: [PATCH 6/9] Se edita el campo de las categorias y se agrega un metodo para convertir un modelo en entidad --- web/src/data/models/prod/PlaceModel.ts | 40 +++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/web/src/data/models/prod/PlaceModel.ts b/web/src/data/models/prod/PlaceModel.ts index c8a674d8..4adb0593 100644 --- a/web/src/data/models/prod/PlaceModel.ts +++ b/web/src/data/models/prod/PlaceModel.ts @@ -1,3 +1,6 @@ +import { AvailableDays, Place } from "../../../infraestructure/entities/place"; +import { CategoryModelLan } from "./CategoryModel"; + export interface PlaceModel { idTown: number; idPlace: number; @@ -7,9 +10,44 @@ export interface PlaceModel { longitude: number; imageName: string; name: string; - categoriesId: string; + categories: CategoryModelLan[] openAt: number; closeAt: number; startDate?: Date; endDate?: Date; +} + +export const placeModelToEntity = (model: PlaceModel) =>{ + let availableDays = AvailableDays.WEEKEND; + switch(model.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 : model.idTown, + idPlace : model.idPlace, + available : availableDays, + latitude: model.latitude, + longitude: model.longitude, + descriptions: [model.description], + imagesList: [model.imageName], + name: model.name, + categoriesId: model.categories.map((category)=> category.idCategory), + openAt: model.openAt, + closeAt: model.closeAt, + startDate: model.startDate, + endDate: model.endDate + } + return place; } \ No newline at end of file -- GitLab From 5c455501683dacf0e51c926727f655a257059a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:14:01 -0600 Subject: [PATCH 7/9] Se modifica la forma en que se obtienen las categorias --- web/src/data/datasources/prod/category_datasource.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/web/src/data/datasources/prod/category_datasource.ts b/web/src/data/datasources/prod/category_datasource.ts index 264be779..1204701d 100644 --- a/web/src/data/datasources/prod/category_datasource.ts +++ b/web/src/data/datasources/prod/category_datasource.ts @@ -16,8 +16,16 @@ export class CategoryDatasourceProd implements CategoryDatasourceInf{ } async getCategories(): Promise { - const {data: dataES} = await axios.get(APIUrl+'/category/ES'); - const {data: dataEN} = await axios.get(APIUrl+'/category/EN'); + const {data: dataES} = await axios.get(APIUrl+'/category/', { + params: { + lang: 'ES' + } + }); + const {data: dataEN} = await axios.get(APIUrl+'/category/', { + params: { + lang: 'ES' + } + }); const categories : Category[] = []; for(let i=0; i Date: Thu, 25 Jul 2024 14:14:50 -0600 Subject: [PATCH 8/9] Se modifica un campo al mandar el lugar --- web/src/data/datasources/prod/place_datasource.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/src/data/datasources/prod/place_datasource.ts b/web/src/data/datasources/prod/place_datasource.ts index 3b9f89e9..7703c47f 100644 --- a/web/src/data/datasources/prod/place_datasource.ts +++ b/web/src/data/datasources/prod/place_datasource.ts @@ -10,7 +10,7 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ formToSend.append('available', form.available); formToSend.append('idTown', String(form.idTown)); formToSend.append('name', form.name); - formToSend.append('categoriesId', form.categoriesId as string | ''); + formToSend.append('categoriesId', form.categoriesId.join(',')); formToSend.append('descriptionES', form.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', form.descriptions?.[1] ?? ''); formToSend.append('image', form.imagesList?.[0] ?? ''); @@ -69,7 +69,7 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf{ formToSend.append('available', place.available); formToSend.append('idTown', String(place.idTown)); formToSend.append('name', place.name); - formToSend.append('categoriesId', place.categoriesId as string | ''); + formToSend.append('categoriesId', place.categoriesId.join(',')); formToSend.append('descriptionES', place.descriptions?.[0] ?? ''); formToSend.append('descriptionEN', place.descriptions?.[1] ?? ''); formToSend.append('image', place.imagesList?.[0] ?? ''); -- GitLab From 63f6822ddbbaa64f4a094a707c7fbdad06d5f587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Luna=20Hern=C3=A1ndez?= <42101656@uaz.edu.mx> Date: Thu, 25 Jul 2024 14:15:19 -0600 Subject: [PATCH 9/9] Se modifican para que se pueda actualizar el lugar --- .../admin_panel_place_list.tsx | 40 ++- .../admin_panel_place_register.tsx | 338 ++++++++++-------- .../admin_panel_place_screen.tsx | 18 +- web/src/components/map/map.tsx | 77 ++-- .../multiple_images_dropzone.tsx | 9 +- web/src/hooks/useDropzoneMultiplesImages.tsx | 29 +- web/src/hooks/usePlace.tsx | 81 +++-- 7 files changed, 371 insertions(+), 221 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 d56168fc..7ded0c77 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 @@ -3,16 +3,34 @@ import { usePlace } from '../../../hooks/usePlace'; import './assets/css/styles.css'; import { Place } from '../../../infraestructure/entities/place'; import { LoadingSpinner } from '../../loading_spinner/loading_spinner'; +import { faEdit } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { Dispatch, SetStateAction, useEffect } from 'react'; interface props{ idTown: number; + isWindowActive: boolean; + setIsWindowActive: Dispatch>; + setActualPlace: Dispatch>; + setIsRegisterPane: Dispatch>; } -export const AdminPanelPlaceList = ({idTown}: props) => { +export const AdminPanelPlaceList = ({idTown, isWindowActive, setIsWindowActive, setActualPlace, setIsRegisterPane}: props) => { const { placeList, - pending - } = usePlace(idTown); + pending, + updatePlacesByTown + } = usePlace(); + + const handleEditSelectedCategory = (place: Place) => { + setIsRegisterPane(false); + setActualPlace(place); + setIsWindowActive(true); + } + + useEffect(() => { + updatePlacesByTown(idTown); + },[]); const columns : TableColumn[] = [ { @@ -27,6 +45,20 @@ export const AdminPanelPlaceList = ({idTown}: props) => { { name: "Estado", selector: row => row.available + }, + { + name: "Acciones", + cell: (row) => { + return ( + { + if(!isWindowActive){ + handleEditSelectedCategory(row); + } + }} + /> + ); + } } ]; @@ -36,7 +68,7 @@ export const AdminPanelPlaceList = ({idTown}: props) => { progressComponent={ } - columns={columns} data={placeList} selectableRows className="data_table"/> + columns={columns} data={placeList} className="data_table"/> ); } \ No newline at end of file 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 7f5eda9a..fff742bc 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 @@ -1,13 +1,13 @@ import { faWindowClose } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { Dispatch, SetStateAction, useState} from "react"; +import { Dispatch, SetStateAction, useEffect, useState} from "react"; import "./assets/css/styles.css"; import { MapComponent } from "../../map/map"; import { usePlace } from "../../../hooks/usePlace"; import { languaguesList } from "../../../constants/languages"; import { LoadingScreen } from "../../loading_screen/loading_screen"; import { MultipleImagesDropzone } from "../../multiple_images_dropzone/multiple_images_dropzone"; -import { AvailableDays, availableDaysList } from "../../../infraestructure/entities/place"; +import { AvailableDays, availableDaysList, EmptyPlace, Place } from "../../../infraestructure/entities/place"; import { Category } from "../../../infraestructure/entities/category"; interface props { @@ -15,31 +15,40 @@ interface props { categoriesList: Category[]; idTown: number; forceRenderList: () => void; + isRegister: boolean; + form?: Place; } -export const AdminPanelPlaceRegister = ({setIsWindowActive, idTown, categoriesList, forceRenderList}: props) => { +export const AdminPanelPlaceRegister = ({setIsWindowActive, idTown, categoriesList, forceRenderList, isRegister, form}: props) => { const { register, handleSubmit, errors, - onSubmit, setValue, languageDescriptionIndexSelected, descriptions, setDescriptions, setLanguageDescriptionIndexSelected, - isLoading, updateTimeForm, availableDays, setAvailableDays, resetField, categoriesId, setCategoriesId, - } = usePlace(idTown, forceRenderList, setIsWindowActive); - const [clickedCategories, setClickedCategories] = useState(new Array(categoriesList.length).fill(false)); + getPlaceById, + onSubmitRegister, + onSubmitUpdate, + clearErrors + } = usePlace(forceRenderList, setIsWindowActive); + const [clickedCategories, setClickedCategories] = useState(new Array(categoriesList.length).fill(false)); + const [isLoading, setIsLoading] = useState(false); + const [actualPlace, setActualPlace] = useState(EmptyPlace); + const [openHourInput, setOpenHourInput] = useState(''); + const [closeHourInput, setCloseHourInput] = useState(''); - const onClickCategory = (idCategory: number, indexList: number) => { + const onClickCategory = (idCategory: number) => { const index = categoriesId.indexOf(idCategory); + const indexList = categoriesList.findIndex(category => category.idCategory === idCategory); const clickedCategoriesBackup = clickedCategories.map((clickedCategory, index)=> { if(index === indexList){ return !clickedCategory; @@ -61,6 +70,43 @@ export const AdminPanelPlaceRegister = ({setIsWindowActive, idTown, categoriesLi setClickedCategories(clickedCategoriesBackup); } + useEffect(() => { + setIsLoading(true); + const fetchData = async () => { + setValue('idTown', idTown); + if (!isRegister && form) { + const placeGetted = await getPlaceById(form.idPlace || 0); + if(placeGetted){ + setActualPlace(placeGetted); + setValue('idPlace', placeGetted.idPlace); + setValue('name', placeGetted.name); + setValue('descriptions', placeGetted.descriptions); + setDescriptions(placeGetted.descriptions || ['', '']); + setValue('openAt', placeGetted.openAt); + setOpenHourInput(placeGetted.openAt < 10 ? `0${placeGetted.openAt}:00` : `${placeGetted.openAt}:00`); + setCloseHourInput(placeGetted.closeAt < 10 ? `0${placeGetted.closeAt}:00` : `${placeGetted.closeAt}:00`); + setValue('closeAt', placeGetted.closeAt); + setValue('available', placeGetted.available); + setAvailableDays(placeGetted.available); + const clickedCategoriesBackup : boolean[] = []; + categoriesList.forEach((category) => { + if(placeGetted.categoriesId.indexOf(category.idCategory) > -1){ + clickedCategoriesBackup.push(true); + }else{ + clickedCategoriesBackup.push(false); + } + }); + setClickedCategories(clickedCategoriesBackup); + setCategoriesId(placeGetted.categoriesId); + } + } else { + setValue('available', availableDays, { shouldValidate: true }); + } + }; + fetchData(); + setIsLoading(false); + },[]); + return (
@@ -69,167 +115,175 @@ export const AdminPanelPlaceRegister = ({setIsWindowActive, idTown, categoriesLi onClick={() => setIsWindowActive(false)}/>
-
- { - isLoading + {isLoading ? : -
-
-
- Nombre del lugar -
- -

{errors.name?.message}

+ +
+
+
+ Nombre del lugar
+ +

{errors.name?.message}

+
-
-
- Descripción del lugar - -
- { - languaguesList.map((language, index) => { - if(index===languageDescriptionIndexSelected){ - return ( -