UNPKG

@omegabigdata/honoplay-redux-helper

Version:
185 lines (174 loc) 4.43 kB
import { CREATING_SESSION, CREATE_SESSION_SUCCESS, CREATE_SESSION_FAILED, FETCHING_SESSION_LIST, FETCH_SESSION_LIST_SUCCESS, FETCH_SESSION_LIST_FAILED, FETCHING_SESSION, FETCH_SESSION_SUCCESS, FETCH_SESSION_FAILED, UPDATING_SESSION, UPDATE_SESSION_SUCCESS, UPDATE_SESSION_FAILED, FETCHING_SESSION_BY_CLASSROOMID_LIST, FETCH_SESSION_BY_CLASSROOMID_LIST_FAILED, FETCH_SESSION_BY_CLASSROOMID_LIST_SUCCESS } from "../helpers/ActionTypes/Session"; const CREATE_SESSION_INITIAL_STATE = { isCreateSessionLoading: false, createSession: null, errorCreateSession: null }; const SESSION_LIST_INITIAL_STATE = { isSessionListLoading: false, sessionList: null, errorSessionList: null }; const SESSION_INITIAL_STATE = { isSessionLoading: false, session: null, errorSession: null }; const UPDATE_SESSION_INITIAL_STATE = { isUpdateSessionLoading: false, updateSession: null, errorUpdateSession: null }; const SESSION_LIST_BY_CLASSROOMID_INITIAL_STATE = { isSessionListByClassroomIdLoading: false, sessionListByClassroomId: null, errorSessionListByClassroomId: null }; export const sessionListByClassroomIdReducers = ( state = SESSION_LIST_BY_CLASSROOMID_INITIAL_STATE, action ) => { switch (action.type) { case FETCHING_SESSION_BY_CLASSROOMID_LIST: return { ...state, isSessionListByClassroomIdLoading: true, errorSessionListByClassroomId: null }; case FETCH_SESSION_BY_CLASSROOMID_LIST_SUCCESS: return { ...state, isSessionListByClassroomIdLoading: false, sessionListByClassroomId: action.data }; case FETCH_SESSION_BY_CLASSROOMID_LIST_FAILED: return { ...state, isSessionListByClassroomIdLoading: false, errorSessionListByClassroomId: action.data.error }; default: return state; } }; export const createSessionReducers = ( state = CREATE_SESSION_INITIAL_STATE, action ) => { switch (action.type) { case CREATING_SESSION: return { ...state, isCreateSessionLoading: true, errorCreateSession: null }; case CREATE_SESSION_SUCCESS: return { ...state, isCreateSessionLoading: false, createSession: action.data }; case CREATE_SESSION_FAILED: return { ...state, isCreateSessionLoading: false, errorCreateSession: action.data.error }; default: return state; } }; export const sessionListReducers = ( state = SESSION_LIST_INITIAL_STATE, action ) => { switch (action.type) { case FETCHING_SESSION_LIST: return { ...state, isSessionListLoading: true, errorSessionList: null }; case FETCH_SESSION_LIST_SUCCESS: return { ...state, isSessionListLoading: false, sessionList: action.data }; case FETCH_SESSION_LIST_FAILED: return { ...state, isSessionListLoading: false, errorSessionList: action.data.error }; default: return state; } }; export const sessionReducers = (state = SESSION_INITIAL_STATE, action) => { switch (action.type) { case FETCHING_SESSION: return { ...state, isSessionLoading: true, errorSession: null }; case FETCH_SESSION_SUCCESS: return { ...state, isSessionLoading: false, session: action.data }; case FETCH_SESSION_FAILED: return { ...state, isSessionLoading: false, errorSession: action.data.error }; default: return state; } }; export const updateSessionReducers = ( state = UPDATE_SESSION_INITIAL_STATE, action ) => { switch (action.type) { case UPDATING_SESSION: return { ...state, isUpdateSessionLoading: true, errorUpdateSession: null }; case UPDATE_SESSION_SUCCESS: return { ...state, isUpdateSessionLoading: false, updateSession: action.data }; case UPDATE_SESSION_FAILED: return { ...state, isUpdateSessionLoading: false, errorUpdateSession: action.data.error }; default: return state; } };