Der Name von POI lesen und in Aktualisierung-Popup einfügen

This commit is contained in:
ISA
2024-05-22 12:18:00 +02:00
parent 3bd491e825
commit 211192c3f0
3 changed files with 120 additions and 9 deletions

View File

@@ -13,6 +13,52 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
poiData ? poiData.description : ""
);
// Log the initial POI data
useEffect(() => {
if (poiData) {
setPoiId(poiData.idPoi);
setName(poiData.name);
setPoiTypeId(poiData.idPoiTyp);
setDescription(poiData.description);
console.log("Loaded POI Data for editing:", poiData);
console.log("POI ID:", poiData.idPoi);
console.log("POI Name:", poiData.name);
console.log("POI Typ ID:", poiData.idPoiTyp);
console.log("POI Beschreibung:", poiData.description);
console.log("POI Geräte-ID:", poiData.idLD);
}
}, [poiData]);
const fetchDeviceNameById = async (idLD) => {
try {
const response = await fetch(`/api/getDeviceNameById?idLD=${idLD}`);
const data = await response.json();
setDeviceName(data.deviceName);
} catch (error) {
console.error("Error fetching device name:", error);
}
};
// Beim Öffnen des Modals die Geräte-ID basierend auf dem Gerätenamen abrufen, wenn vorhanden
useEffect(() => {
const fetchDeviceId = async () => {
if (poiData && poiData.idLD) {
try {
const response = await fetch(
`/api/getDeviceIdById?idLD=${poiData.idLD}`
);
const data = await response.json();
if (data) setDeviceName(data.name);
} catch (error) {
console.error("Fehler beim Abrufen der Geräteinformation:", error);
}
}
};
fetchDeviceId();
}, [poiData]);
// Function to handle deleting a POI
const handleDeletePoi = async () => {
if (confirm("Sind Sie sicher, dass Sie diesen POI löschen möchten?")) {
@@ -41,6 +87,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
try {
const response = await fetch("/api/readPoiTyp");
const data = await response.json();
//console.log("POI Typ Daten:", data);
setPoiTypData(data);
if (data && data.length > 0) {
setPoiTypeId(data[0].idPoiTyp); // Set the first type as default
@@ -58,6 +105,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
try {
const response = await fetch("/api/talas_v5/location_device");
const data = await response.json();
//console.log("Standort- und Gerätedaten:", data);
setLocationDeviceData(data);
if (data.length > 0) {
setDeviceName(data[0].name); // Set initial device name
@@ -95,8 +143,9 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
});
if (response.ok) {
alert("POI wurde erfolgreich aktualisiert.");
//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(
@@ -119,7 +168,7 @@ const PoiUpdateModal = ({ onClose, poiData }) => {
type="text"
id="name"
name="name"
value={name}
value={poiData.description || name}
onChange={(e) => setName(e.target.value)}
placeholder="Name der Station"
className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm"