feat: GisSystemStatic in Redux integriert
- 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
This commit is contained in:
@@ -1,7 +1,32 @@
|
||||
// /redux/slices/webService/gisSystemStaticSlice.js
|
||||
import { atom } from "recoil";
|
||||
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchGisSystemStatic } from "../../api/fromWebService/fetchGisSystemStatic";
|
||||
|
||||
export const gisSystemStaticState = atom({
|
||||
key: "gisSystemStatic", // Eindeutiger Schlüssel (innerhalb des Projekts)
|
||||
default: [], // Standardwert (Anfangszustand)
|
||||
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 || [];
|
||||
|
||||
Reference in New Issue
Block a user