From 63265af59c1772a9c5f52c8119b60b769aca7a63 Mon Sep 17 00:00:00 2001 From: isa Date: Wed, 22 May 2024 22:11:02 +0200 Subject: [PATCH] Daten Aktualisierung done! --- components/PoiUpdateModal.js | 123 ++++++++++++++++++----------------- 1 file changed, 64 insertions(+), 59 deletions(-) diff --git a/components/PoiUpdateModal.js b/components/PoiUpdateModal.js index f8541929b..a66149dc8 100644 --- a/components/PoiUpdateModal.js +++ b/components/PoiUpdateModal.js @@ -120,59 +120,61 @@ const PoiUpdateModal = ({ onClose, poiData }) => { fetchData(); }, []); - // Form submission handler - const handleSubmit = async (event) => { - event.preventDefault(); - const idLDResponse = await fetch( - `/api/getDeviceId?deviceName=${encodeURIComponent(deviceName)}` - ); - const idLDData = await idLDResponse.json(); - const idLD = idLDData.idLD; - try { - const response = await fetch("/api/updatePoi", { - method: "POST", - headers: { - "Content-Type": "application/json", - }, - body: JSON.stringify({ - idPoi: poiId, - description: name, - idPoiTyp: poiTypeId, - idLD: idLD, - }), - }); + // Angenommen, deviceName enthält die Geräte-ID +const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name - if (response.ok) { - //alert("POI wurde erfolgreich aktualisiert."); - onClose(); // Schließen des Modals und Aktualisieren der Ansicht - window.location.reload(); - } else { - const errorResponse = await response.json(); - throw new Error( - errorResponse.error || "Fehler beim Aktualisieren des POI." - ); - } - } catch (error) { - console.error("Fehler beim Aktualisieren des POI:", error); - alert("Fehler beim Aktualisieren des POI."); +const handleSubmit = async (event) => { + event.preventDefault(); + try { + const response = await fetch("/api/updatePoi", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + idPoi: poiId, + name: name, + description: description, + idPoiTyp: poiTypeId, + idLD: parseInt(deviceName, 10), // Konvertieren in eine Ganzzahl + }), + }); + + if (response.ok) { + onClose(); + window.location.reload(); + } else { + const errorResponse = await response.json(); + throw new Error( + errorResponse.error || "Fehler beim Aktualisieren des POI." + ); } - }; + } catch (error) { + console.error("Fehler beim Aktualisieren des POI:", error); + alert("Fehler beim Aktualisieren des POI."); + } +}; + + + + + return (
- - setName(e.target.value)} - placeholder="Name der Station" - className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" - /> + + setDescription(e.target.value)} + placeholder="Beschreibung der Station" + className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" + />
@@ -180,18 +182,21 @@ const PoiUpdateModal = ({ onClose, poiData }) => { Gerät: + id="deviceName" + name="deviceName" + value={deviceName} + onChange={(e) => setDeviceName(e.target.value)} + className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" +> + {locationDeviceData.map((device, index) => ( + + ))} + + + +