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:
25
CHANGELOG.md
25
CHANGELOG.md
@@ -4,6 +4,31 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie
|
||||
|
||||
---
|
||||
|
||||
## [1.1.162] – 2025-05-23
|
||||
|
||||
### ♻️ Refactor
|
||||
|
||||
- `PoiUpdateModal.js` vollständig auf direkte Geräte-ID (`idLD`) über `react-select` umgestellt
|
||||
- Thunk `getDeviceIdByNameThunk` entfernt, da ID direkt im Dropdown verfügbar ist
|
||||
- `updatePoiThunk` + `updatePoiService.js` erfolgreich integriert für POST-Anfrage
|
||||
- `handleSubmit()` aktualisiert, robust gegen fehlende Felder
|
||||
|
||||
### 🧠 Architektur
|
||||
|
||||
- Geräteselektion nutzt nun die eindeutige ID (`idLD`) aus der Auswahl – stabiler und performanter
|
||||
- Alle POI-Änderungen laufen nun über Service + Thunk + Dispatch, ohne fetch()
|
||||
|
||||
### 🛠 Sicherheit & Wartbarkeit
|
||||
|
||||
- keine API-Abhängigkeit mehr für Gerätesuche
|
||||
- einheitliche Redux-Thunk-Strategie eingehalten
|
||||
|
||||
### 🔧 Version
|
||||
|
||||
- 📦 Version erhöht auf **1.1.162**
|
||||
|
||||
---
|
||||
|
||||
## [1.1.161] – 2025-05-23
|
||||
|
||||
### ♻️ Refactor
|
||||
|
||||
@@ -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}>
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
// /config/appVersion
|
||||
export const APP_VERSION = "1.1.162";
|
||||
export const APP_VERSION = "1.1.163";
|
||||
|
||||
12
redux/thunks/database/getDeviceIdByNameThunk.js
Normal file
12
redux/thunks/database/getDeviceIdByNameThunk.js
Normal file
@@ -0,0 +1,12 @@
|
||||
// /redux/thunks/database/getDeviceIdByNameThunk.js
|
||||
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { getDeviceIdByNameService } from "../../../services/database/getDeviceIdByNameService";
|
||||
|
||||
export const getDeviceIdByNameThunk = createAsyncThunk("devices/getIdByName", async (deviceName, thunkAPI) => {
|
||||
try {
|
||||
return await getDeviceIdByNameService(deviceName);
|
||||
} catch (error) {
|
||||
return thunkAPI.rejectWithValue(error.message);
|
||||
}
|
||||
});
|
||||
12
redux/thunks/database/updatePoiThunk.js
Normal file
12
redux/thunks/database/updatePoiThunk.js
Normal file
@@ -0,0 +1,12 @@
|
||||
// /redux/thunks/database/updatePoiThunk.js
|
||||
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { updatePoiService } from "../../../services/database/updatePoiService";
|
||||
|
||||
export const updatePoiThunk = createAsyncThunk("pois/update", async (poi, thunkAPI) => {
|
||||
try {
|
||||
await updatePoiService(poi);
|
||||
} catch (error) {
|
||||
return thunkAPI.rejectWithValue(error.message);
|
||||
}
|
||||
});
|
||||
10
services/database/getDeviceIdByNameService.js
Normal file
10
services/database/getDeviceIdByNameService.js
Normal file
@@ -0,0 +1,10 @@
|
||||
// /services/database/getDeviceIdByNameService.js
|
||||
|
||||
export const getDeviceIdByNameService = async (deviceName) => {
|
||||
const response = await fetch(`/api/talas_v5_DB/locationDevice/getDeviceId?deviceName=${encodeURIComponent(deviceName)}`);
|
||||
if (!response.ok) {
|
||||
throw new Error("Fehler beim Abrufen der Geräte-ID.");
|
||||
}
|
||||
const data = await response.json();
|
||||
return data.idLD;
|
||||
};
|
||||
16
services/database/updatePoiService.js
Normal file
16
services/database/updatePoiService.js
Normal file
@@ -0,0 +1,16 @@
|
||||
// /services/database/updatePoiService.js
|
||||
|
||||
export const updatePoiService = async (poi) => {
|
||||
const response = await fetch("/api/talas_v5_DB/pois/updatePoi", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(poi),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const error = await response.json();
|
||||
throw new Error(error.error || "Fehler beim Aktualisieren des POI.");
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user