From 867e683eabcd7bf860e18c36a7fb7a9492fa19bb Mon Sep 17 00:00:00 2001 From: ISA Date: Mon, 16 Sep 2024 15:48:04 +0200 Subject: [PATCH] =?UTF-8?q?Filter=20Ger=C3=A4t=20und=20Typ=20in=20Add=20un?= =?UTF-8?q?d=20Update=20POI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/pois/AddPoiModalWindow.js | 36 +++++++------ components/pois/PoiUpdateModal.js | 79 ++++++++++++++++++++-------- 2 files changed, 77 insertions(+), 38 deletions(-) diff --git a/components/pois/AddPoiModalWindow.js b/components/pois/AddPoiModalWindow.js index 01f077fdd..1120efd6e 100644 --- a/components/pois/AddPoiModalWindow.js +++ b/components/pois/AddPoiModalWindow.js @@ -1,6 +1,6 @@ // components/pois/AddPoiModalWindow.js import React, { useState, useEffect } from "react"; -import Select from "react-select"; // Import react-select +import Select from "react-select"; // Importiere react-select import { useSetRecoilState } from "recoil"; import { readPoiMarkersStore } from "../../store/selectors/readPoiMarkersStore"; import { poiReadFromDbTriggerAtom } from "../../store/atoms/poiReadFromDbTriggerAtom"; @@ -8,12 +8,12 @@ import { poiReadFromDbTriggerAtom } from "../../store/atoms/poiReadFromDbTrigger const AddPoiModalWindow = ({ onClose, map, latlng }) => { const [poiTypData, setpoiTypData] = useState([]); const [name, setName] = useState(""); - const [poiTypeId, setPoiTypeId] = useState(""); // Initialize as empty string + const [poiTypeId, setPoiTypeId] = useState(null); // Verwende null für react-select const [latitude] = useState(latlng.lat.toFixed(5)); const [longitude] = useState(latlng.lng.toFixed(5)); const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom); const [locationDeviceData, setLocationDeviceData] = useState([]); - const [deviceName, setDeviceName] = useState(null); // Initialize as null + const [deviceName, setDeviceName] = useState(null); // Verwende null für react-select useEffect(() => { const fetchInitialData = async () => { @@ -27,7 +27,7 @@ const AddPoiModalWindow = ({ onClose, map, latlng }) => { setLocationDeviceData(locationDeviceData); if (locationDeviceData.length > 0) { - setDeviceName(locationDeviceData[0].name); // Set initial device name + setDeviceName({ value: locationDeviceData[0].name, label: locationDeviceData[0].name }); // Set initial device name } } catch (error) { console.error("Fehler beim Abrufen der Daten:", error); @@ -48,7 +48,7 @@ const AddPoiModalWindow = ({ onClose, map, latlng }) => { const formData = { name, - poiTypeId, + poiTypeId: poiTypeId.value, // Verwende den Wert von react-select latitude, longitude, idLD: locationDeviceData.find((device) => device.name === deviceName?.value).idLD, @@ -75,6 +75,11 @@ const AddPoiModalWindow = ({ onClose, map, latlng }) => { }; // Erstelle Optionen für react-select + const poiTypeOptions = poiTypData.map((poiTyp) => ({ + value: poiTyp.idPoiTyp, + label: poiTyp.name, + })); + const deviceOptions = locationDeviceData.map((device) => ({ value: device.name, label: device.name, @@ -119,20 +124,19 @@ const AddPoiModalWindow = ({ onClose, map, latlng }) => { /> + {/* React Select for POI Types */}
-
+ {/* React Select for Devices */}
- + setPoiTypeId(e.target.value)} className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"> - {poiTypData.map((poiTyp) => ( - - ))} - +