Add redux actions and reducer for scheduler entries

This commit is contained in:
Ken Hibino
2020-12-02 19:44:50 -08:00
parent fbbc414bdf
commit 3e5b145883
4 changed files with 119 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import {
LIST_SCHEDULER_ENTRIES_BEGIN,
LIST_SCHEDULER_ENTRIES_ERROR,
LIST_SCHEDULER_ENTRIES_SUCCESS,
SchedulerEntriesActionTypes,
} from "../actions/schedulerEntriesActions";
import { SchedulerEntry } from "../api";
interface SchedulerEntriesState {
loading: boolean;
data: SchedulerEntry[];
error: string; // error description
}
const initialState: SchedulerEntriesState = {
loading: false,
data: [],
error: "",
};
function schedulerEntriesReducer(
state = initialState,
action: SchedulerEntriesActionTypes
): SchedulerEntriesState {
switch (action.type) {
case LIST_SCHEDULER_ENTRIES_BEGIN:
return {
...state,
loading: true,
};
case LIST_SCHEDULER_ENTRIES_SUCCESS:
return {
error: "",
loading: false,
data: action.payload.entries,
};
case LIST_SCHEDULER_ENTRIES_ERROR:
// TODO: set error state
return {
...state,
loading: false,
error: action.error,
};
default:
return state;
}
}
export default schedulerEntriesReducer;