Daten Aktualisierung done!

This commit is contained in:
isa
2024-05-22 22:11:02 +02:00
parent 43f23115af
commit 63265af59c

View File

@@ -120,14 +120,11 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
fetchData();
}, []);
// Form submission handler
const handleSubmit = async (event) => {
// Angenommen, deviceName enthält die Geräte-ID
const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name
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",
@@ -136,15 +133,15 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
},
body: JSON.stringify({
idPoi: poiId,
description: name,
name: name,
description: description,
idPoiTyp: poiTypeId,
idLD: idLD,
idLD: parseInt(deviceName, 10), // Konvertieren in eine Ganzzahl
}),
});
if (response.ok) {
//alert("POI wurde erfolgreich aktualisiert.");
onClose(); // Schließen des Modals und Aktualisieren der Ansicht
onClose();
window.location.reload();
} else {
const errorResponse = await response.json();
@@ -156,21 +153,26 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
console.error("Fehler beim Aktualisieren des POI:", error);
alert("Fehler beim Aktualisieren des POI.");
}
};
};
return (
<form onSubmit={handleSubmit} className="m-0 p-2 w-full">
<div className="flex items-center mb-4">
<label htmlFor="name" className="block mr-2 flex-none">
Name:
<label htmlFor="description" className="block mr-2 flex-none">
Beschreibung:
</label>
<input
type="text"
id="name"
name="name"
value={poiData.description || name}
onChange={(e) => setName(e.target.value)}
placeholder="Name der Station"
id="description"
name="description"
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder="Beschreibung der Station"
className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"
/>
</div>
@@ -185,13 +187,16 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
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) => (
<option key={index} value={device.name}>
<option key={index} value={device.id}> {/* Stellen Sie sicher, dass device.id eine Ganzzahl ist */}
{device.name}
</option>
))}
</select>
</select>
</div>
<div className="flex items-center mb-4">