UNPKG

@omegabigdata/honoplay-redux-helper

Version:
185 lines (174 loc) 4.42 kB
import { FETCHING_TRAINEE_LIST, FETCH_TRAINEE_LIST_SUCCESS, FETCH_TRAINEE_LIST_FAILED, FETCHING_TRAINEE, FETCH_TRAINEE_SUCCESS, FETCH_TRAINEE_FAILED, UPDATING_TRAINEE, UPDATE_TRAINEE_SUCCESS, UPDATE_TRAINEE_FAILED, CREATING_TRAINEE, CREATE_TRAINEE_SUCCESS, CREATE_TRAINEE_FAILED, FETCHING_TRAINEEUSER_BY_CLASSROOMID, FETCH_TRAINEEUSER_BY_CLASSROOMID_SUCCESS, FETCH_TRAINEEUSER_BY_CLASSROOMID_FAILED } from '../helpers/ActionTypes/Trainee'; const TRAINEE_LIST_INITIAL_STATE = { isTraineeListLoading: false, trainees: null, errorTraineeList: null }; const TRAINEE_INITIAL_STATE = { isTraineeLoading: false, trainee: null, errorTrainee: null }; const CREATE_TRAINEE_INITIAL_STATE = { isCreateTraineeLoading: false, newTrainee: null, errorCreateTrainee: null }; const UPDATE_TRAINEE_INITIAL_STATE = { isUpdateTraineeLoading: false, updatedTrainee: null, errorUpdateTrainee: null }; const TRAINEEUSER_BY_CLASSROOMID_INITIAL_STATE = { isTraineeUserByClassroomIdLoading: false, traineeUserByClassroomId: null, errorTraineeUserByClassroomId: null }; export const traineeUserByClassroomIdReducers = ( state = TRAINEEUSER_BY_CLASSROOMID_INITIAL_STATE, action ) => { switch (action.type) { case FETCHING_TRAINEEUSER_BY_CLASSROOMID: return { ...state, isTraineeUserByClassroomIdLoading: true, errorTraineeUserByClassroomId: null }; case FETCH_TRAINEEUSER_BY_CLASSROOMID_SUCCESS: return { ...state, isTraineeUserByClassroomIdLoading: false, traineeUserByClassroomId: action.data }; case FETCH_TRAINEEUSER_BY_CLASSROOMID_FAILED: return { ...state, isTraineeUserByClassroomIdLoading: false, errorTraineeUserByClassroomId: action.data.error }; default: return state; } }; export const traineeListReducers = ( state = TRAINEE_LIST_INITIAL_STATE, action ) => { switch (action.type) { case FETCHING_TRAINEE_LIST: return { ...state, isTraineeListLoading: true, errorTraineeList: null }; case FETCH_TRAINEE_LIST_SUCCESS: return { ...state, isTraineeListLoading: false, trainees: action.data }; case FETCH_TRAINEE_LIST_FAILED: return { ...state, isTraineeListLoading: false, errorTraineeList: action.data.error }; default: return state; } }; export const traineeReducers = (state = TRAINEE_INITIAL_STATE, action) => { switch (action.type) { case FETCHING_TRAINEE: return { ...state, isTraineeLoading: true, errorTrainee: null }; case FETCH_TRAINEE_SUCCESS: return { ...state, isTraineeLoading: false, trainee: action.data }; case FETCH_TRAINEE_FAILED: return { ...state, isTraineeLoading: false, errorTrainee: action.data.error }; default: return state; } }; export const createTraineeReducers = ( state = CREATE_TRAINEE_INITIAL_STATE, action ) => { switch (action.type) { case CREATING_TRAINEE: return { ...state, isCreateTraineeLoading: true, errorCreateTrainee: null }; case CREATE_TRAINEE_SUCCESS: return { ...state, isCreateTraineeLoading: false, newTrainee: action.data }; case CREATE_TRAINEE_FAILED: return { ...state, isCreateTraineeLoading: false, errorCreateTrainee: action.data.error }; default: return state; } }; export const updateTraineeReducers = ( state = UPDATE_TRAINEE_INITIAL_STATE, action ) => { switch (action.type) { case UPDATING_TRAINEE: return { ...state, isUpdateTraineeLoading: true, errorUpdateTrainee: null }; case UPDATE_TRAINEE_SUCCESS: return { ...state, isUpdateTraineeLoading: false, updatedTrainee: action.data }; case UPDATE_TRAINEE_FAILED: return { ...state, isUpdateTraineeLoading: false, errorUpdateTrainee: action.data.error }; default: return state; } };