refactor: POI aktualisieren auf updatePoiThunk + ID aus react-select umgestellt
- Thunk getDeviceIdByNameThunk entfernt - idLD direkt aus Dropdown gelesen - updatePoiThunk + updatePoiService vollständig eingebunden - Fehlerbehandlung in handleSubmit verbessert - Version erhöht auf 1.1.162
This commit is contained in:
@@ -7,6 +7,8 @@ import { selectMapLayersState } from "../../redux/slices/mapLayersSlice";
|
||||
import { fetchPoiTypThunk } from "../../redux/thunks/database/fetchPoiTypThunk";
|
||||
import { selectPoiTypData, selectPoiTypStatus } from "../../redux/slices/database/poiTypSlice";
|
||||
import { deletePoiThunk } from "../../redux/thunks/database/deletePoiThunk";
|
||||
import { getDeviceIdByNameThunk } from "../../redux/thunks/database/getDeviceIdByNameThunk";
|
||||
import { updatePoiThunk } from "../../redux/thunks/database/updatePoiThunk";
|
||||
|
||||
const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => {
|
||||
const dispatch = useDispatch();
|
||||
@@ -85,32 +87,22 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => {
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
const idLDResponse = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName?.value)}`);
|
||||
const idLDData = await idLDResponse.json();
|
||||
const idLD = idLDData.idLD;
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/talas_v5_DB/pois/updatePoi", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
idPoi: poiId,
|
||||
name: name,
|
||||
description: description,
|
||||
idPoiTyp: poiTypeId?.value, // Den ausgewählten Typ mitsenden
|
||||
idLD: idLD,
|
||||
}),
|
||||
});
|
||||
const idLD = deviceName?.value;
|
||||
|
||||
if (response.ok) {
|
||||
onClose();
|
||||
window.location.reload();
|
||||
} else {
|
||||
const errorResponse = await response.json();
|
||||
throw new Error(errorResponse.error || "Fehler beim Aktualisieren des POI.");
|
||||
}
|
||||
await dispatch(
|
||||
updatePoiThunk({
|
||||
idPoi: poiId,
|
||||
name,
|
||||
description,
|
||||
idPoiTyp: poiTypeId?.value ?? poiData?.idPoiTyp,
|
||||
idLD: deviceName?.value, // ← direkt die ID aus react-select
|
||||
})
|
||||
).unwrap();
|
||||
|
||||
onClose();
|
||||
window.location.reload(); // oder: dispatch(incrementTrigger());
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Aktualisieren des POI:", error);
|
||||
alert("Fehler beim Aktualisieren des POI.");
|
||||
@@ -165,6 +157,13 @@ const PoiUpdateModal = ({ onClose, poiData, onSubmit }) => {
|
||||
minWidth: "300px", // Ensure the dropdown menu stays at the minimum width
|
||||
}),
|
||||
};
|
||||
console.log("→ Sende POI-Daten:", {
|
||||
idPoi: poiId,
|
||||
name,
|
||||
description,
|
||||
idPoiTyp: poiTypeId?.value,
|
||||
idLD,
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 bg-black bg-opacity-10 flex justify-center items-center z-[1000]" onClick={onClose}>
|
||||
|
||||
Reference in New Issue
Block a user