- API-Response für GisSystemStatic in Redux Store gespeichert - Server-IP aus `.env.local` geladen (`NEXT_PUBLIC_API_BASE_URL`) - `idMap` und `idUser` aus URL-Parametern extrahiert - fetchGisSystemStatic angepasst für dynamische Werte - Redux Store aktualisiert und getestet
33 lines
1.3 KiB
JavaScript
33 lines
1.3 KiB
JavaScript
// /redux/slices/webService/gisSystemStaticSlice.js
|
|
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
|
import { fetchGisSystemStatic } from "../../api/fromWebService/fetchGisSystemStatic";
|
|
|
|
export const fetchGisSystemStaticFromWebService = createAsyncThunk("gisSystemStatic/fetchGisSystemStaticFromWebService", async () => {
|
|
const response = await fetchGisSystemStatic();
|
|
return response.Systems || []; // ✅ Hier sicherstellen, dass nur `Systems` gespeichert wird
|
|
});
|
|
|
|
const gisSystemStaticSlice = createSlice({
|
|
name: "gisSystemStatic",
|
|
initialState: {
|
|
data: [], // ✅ Immer ein Array setzen
|
|
status: "idle",
|
|
error: null,
|
|
},
|
|
reducers: {
|
|
setGisSystemStatic: (state, action) => {
|
|
state.data = action.payload.Systems || []; // ✅ Falls `Systems` fehlt, leeres Array setzen
|
|
},
|
|
},
|
|
extraReducers: (builder) => {
|
|
builder.addCase(fetchGisSystemStaticFromWebService.fulfilled, (state, action) => {
|
|
state.status = "succeeded";
|
|
state.data = action.payload; // ✅ Jetzt sollte `data` direkt das `Systems`-Array enthalten
|
|
});
|
|
},
|
|
});
|
|
|
|
export const { setGisSystemStatic } = gisSystemStaticSlice.actions;
|
|
export default gisSystemStaticSlice.reducer;
|
|
export const selectGisSystemStatic = (state) => state.gisSystemStatic.data || [];
|