import { createSlice } from '@reduxjs/toolkit'; const initialState = { pointTypes: [], pointProjects: [], declarationRules: [], loading: false, error: null, }; const pointsSlice = createSlice({ name: 'points', initialState, reducers: { setLoading: (state, action) => { state.loading = action.payload; }, setError: (state, action) => { state.error = action.payload; state.loading = false; }, setPointTypes: (state, action) => { state.pointTypes = action.payload; state.loading = false; }, setPointProjects: (state, action) => { state.pointProjects = action.payload; state.loading = false; }, setDeclarationRules: (state, action) => { state.declarationRules = action.payload; state.loading = false; }, addPointType: (state, action) => { state.pointTypes.push(action.payload); }, updatePointType: (state, action) => { const index = state.pointTypes.findIndex(type => type.id === action.payload.id); if (index !== -1) { state.pointTypes[index] = action.payload; } }, deletePointType: (state, action) => { state.pointTypes = state.pointTypes.filter(type => type.id !== action.payload); }, }, }); export const { setLoading, setError, setPointTypes, setPointProjects, setDeclarationRules, addPointType, updatePointType, deletePointType, } = pointsSlice.actions; export default pointsSlice.reducer;