github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/reducers/groupsReducer.ts (about)

     1  import {
     2    GroupsActionTypes,
     3    LIST_GROUPS_BEGIN,
     4    LIST_GROUPS_ERROR,
     5    LIST_GROUPS_SUCCESS,
     6  } from "../actions/groupsActions";
     7  import {
     8    LIST_AGGREGATING_TASKS_SUCCESS,
     9    TasksActionTypes,
    10  } from "../actions/tasksActions";
    11  import { GroupInfo } from "../api";
    12  
    13  interface GroupsState {
    14    loading: boolean;
    15    data: GroupInfo[];
    16    error: string;
    17  }
    18  
    19  const initialState: GroupsState = {
    20    data: [],
    21    loading: false,
    22    error: "",
    23  };
    24  
    25  function groupsReducer(
    26    state = initialState,
    27    action: GroupsActionTypes | TasksActionTypes
    28  ): GroupsState {
    29    switch (action.type) {
    30      case LIST_GROUPS_BEGIN:
    31        return { ...state, loading: true };
    32  
    33      case LIST_GROUPS_ERROR:
    34        return { ...state, loading: false, error: action.error };
    35  
    36      case LIST_GROUPS_SUCCESS:
    37        return {
    38          ...state,
    39          loading: false,
    40          error: "",
    41          data: action.payload.groups,
    42        };
    43  
    44      case LIST_AGGREGATING_TASKS_SUCCESS:
    45        return {
    46          ...state,
    47          data: action.payload.groups,
    48        };
    49  
    50      default:
    51        return state;
    52    }
    53  }
    54  
    55  export default groupsReducer;