Daten Aktualisierung done!
This commit is contained in:
@@ -120,14 +120,11 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
fetchData();
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Form submission handler
|
// 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) => {
|
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();
|
||||||
@@ -158,19 +155,24 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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>
|
||||||
@@ -187,11 +189,14 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
|
|||||||
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">
|
||||||
|
|||||||
Reference in New Issue
Block a user