32 lines
912 B
JavaScript
32 lines
912 B
JavaScript
// /redux/slices/database/locationDevicesSlice.js
|
|
|
|
import { createSlice } from "@reduxjs/toolkit";
|
|
import { fetchLocationDevicesThunk } from "../../../thunks/fetchLocationDevicesThunk";
|
|
|
|
const slice = createSlice({
|
|
name: "locationDevices",
|
|
initialState: {
|
|
data: [],
|
|
status: "idle",
|
|
error: null,
|
|
},
|
|
reducers: {},
|
|
extraReducers: (builder) => {
|
|
builder
|
|
.addCase(fetchLocationDevicesThunk.pending, (state) => {
|
|
state.status = "loading";
|
|
})
|
|
.addCase(fetchLocationDevicesThunk.fulfilled, (state, action) => {
|
|
state.status = "succeeded";
|
|
state.data = action.payload;
|
|
})
|
|
.addCase(fetchLocationDevicesThunk.rejected, (state, action) => {
|
|
state.status = "failed";
|
|
state.error = action.error.message;
|
|
});
|
|
},
|
|
});
|
|
|
|
export default slice.reducer;
|
|
export const selectLocationDevices = (state) => state.locationDevices.data;
|