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(); 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
const handleSubmit = async (event) => {
event.preventDefault(); event.preventDefault();
const idLDResponse = await fetch(
`/api/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`
);
const idLDData = await idLDResponse.json();
const idLD = idLDData.idLD;
try { try {
const response = await fetch("/api/updatePoi", { const response = await fetch("/api/updatePoi", {
method: "POST", method: "POST",
@@ -136,15 +133,15 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
}, },
body: JSON.stringify({ body: JSON.stringify({
idPoi: poiId, idPoi: poiId,
description: name, name: name,
description: description,
idPoiTyp: poiTypeId, idPoiTyp: poiTypeId,
idLD: idLD, idLD: parseInt(deviceName, 10), // Konvertieren in eine Ganzzahl
}), }),
}); });
if (response.ok) { if (response.ok) {
//alert("POI wurde erfolgreich aktualisiert."); onClose();
onClose(); // Schließen des Modals und Aktualisieren der Ansicht
window.location.reload(); window.location.reload();
} else { } else {
const errorResponse = await response.json(); const errorResponse = await response.json();
@@ -156,21 +153,26 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
console.error("Fehler beim Aktualisieren des POI:", error); console.error("Fehler beim Aktualisieren des POI:", error);
alert("Fehler beim Aktualisieren des POI."); 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>
@@ -185,13 +187,16 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
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">