海口龙华志愿者后端管理页面
zhouxiantao
8 days ago 4def10e6567cf651ae333a2a65c497e717c06403
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;