refactor(poiTypes): fetch-Logik aus Slice entfernt, fetchPoiTypThunk korrekt eingebunden

- fetchPoiTypes aus poiTypesSlice entfernt
- fetchPoiTypThunk.js + Service verwendet
- dispatch-Aufrufe in Komponenten angepasst
- Fehler "is not a function" beseitigt
- Version auf 1.1.180 erhöht
This commit is contained in:
ISA
2025-05-26 14:54:39 +02:00
parent b93d474859
commit 5dea7f3e5d
5 changed files with 46 additions and 26 deletions

View File

@@ -1,37 +1,27 @@
// /redux/slices/database/pois/poiTypesSlice.js
import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
// API-Abruf für POI-Typen
export const fetchPoiTypes = createAsyncThunk("poiTypes/fetchPoiTypes", async () => {
let API_BASE_URL = "";
if (typeof window !== "undefined") {
// Browser
API_BASE_URL = `${window.location.protocol}//${window.location.hostname}:3000`;
} else {
// Server (z.B. SSR)
API_BASE_URL = "http://localhost:3000"; // oder env-Fallback z.B. process.env.API_BASE_URL
}
const response = await fetch(`${API_BASE_URL}/api/talas_v5_DB/poiTyp/readPoiTyp`);
return await response.json();
});
import { createSlice } from "@reduxjs/toolkit";
import { fetchPoiTypThunk } from "../../../thunks/database/pois/fetchPoiTypThunk";
const poiTypesSlice = createSlice({
name: "poiTypes",
initialState: { data: [], status: "idle" },
initialState: {
data: [],
status: "idle",
error: null,
},
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchPoiTypes.pending, (state) => {
.addCase(fetchPoiTypThunk.pending, (state) => {
state.status = "loading";
})
.addCase(fetchPoiTypes.fulfilled, (state, action) => {
.addCase(fetchPoiTypThunk.fulfilled, (state, action) => {
state.data = action.payload;
state.status = "succeeded";
})
.addCase(fetchPoiTypes.rejected, (state) => {
.addCase(fetchPoiTypThunk.rejected, (state, action) => {
state.status = "failed";
state.error = action.payload || "Unbekannter Fehler";
});
},
});