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 (