Daten Aktualisierung done!

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

View File

@@ -120,59 +120,61 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
fetchData(); fetchData();
}, []); }, []);
// Form submission handler // Angenommen, deviceName enthält die Geräte-ID
const handleSubmit = async (event) => { const idLD = deviceName; // Stellen Sie sicher, dass dies eine ID ist und kein Name
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,
}),
});
if (response.ok) { const handleSubmit = async (event) => {
//alert("POI wurde erfolgreich aktualisiert."); event.preventDefault();
onClose(); // Schließen des Modals und Aktualisieren der Ansicht try {
window.location.reload(); const response = await fetch("/api/updatePoi", {
} else { method: "POST",
const errorResponse = await response.json(); headers: {
throw new Error( "Content-Type": "application/json",
errorResponse.error || "Fehler beim Aktualisieren des POI." },
); body: JSON.stringify({
} idPoi: poiId,
} catch (error) { name: name,
console.error("Fehler beim Aktualisieren des POI:", error); description: description,
alert("Fehler beim Aktualisieren des POI."); 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 ( return (
<form onSubmit={handleSubmit} className="m-0 p-2 w-full"> <form onSubmit={handleSubmit} className="m-0 p-2 w-full">
<div className="flex items-center mb-4"> <div className="flex items-center mb-4">
<label htmlFor="name" className="block mr-2 flex-none"> <label htmlFor="description" className="block mr-2 flex-none">
Name: Beschreibung:
</label> </label>
<input <input
type="text" type="text"
id="name" id="description"
name="name" name="description"
value={poiData.description || name} value={description}
onChange={(e) => setName(e.target.value)} onChange={(e) => setDescription(e.target.value)}
placeholder="Name der Station" placeholder="Beschreibung der Station"
className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"
/> />
</div> </div>
<div className="flex items-center mb-4"> <div className="flex items-center mb-4">
@@ -180,18 +182,21 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
Gerät: Gerät:
</label> </label>
<select <select
id="deviceName" id="deviceName"
name="deviceName" name="deviceName"
value={deviceName} value={deviceName}
onChange={(e) => setDeviceName(e.target.value)} onChange={(e) => setDeviceName(e.target.value)}
className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm" className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"
> >
{locationDeviceData.map((device, index) => ( {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} {device.name}
</option> </option>
))} ))}
</select> </select>
</div> </div>
<div className="flex items-center mb-4"> <div className="flex items-center mb-4">