Fetch DailyStats in Dashboard view

This commit is contained in:
Ken Hibino
2020-12-27 16:45:28 -08:00
parent 3d982d9a8b
commit d0b6dee896
6 changed files with 158 additions and 8 deletions

View File

@@ -0,0 +1,45 @@
import { Dispatch } from "redux";
import { listQueueStats, ListQueueStatsResponse } from "../api";
export const LIST_QUEUE_STATS_BEGIN = "LIST_QUEUE_STATS_BEGIN";
export const LIST_QUEUE_STATS_SUCCESS = "LIST_QUEUE_STATS_SUCCESS";
export const LIST_QUEUE_STATS_ERROR = "LIST_QUEUE_STATS_ERROR";
interface ListQueueStatsBeginAction {
type: typeof LIST_QUEUE_STATS_BEGIN;
}
interface ListQueueStatsSuccessAction {
type: typeof LIST_QUEUE_STATS_SUCCESS;
payload: ListQueueStatsResponse;
}
interface ListQueueStatsErrorAction {
type: typeof LIST_QUEUE_STATS_ERROR;
error: string;
}
// Union of all queue stats related action types.
export type QueueStatsActionTypes =
| ListQueueStatsBeginAction
| ListQueueStatsSuccessAction
| ListQueueStatsErrorAction;
export function listQueueStatsAsync() {
return async (dispatch: Dispatch<QueueStatsActionTypes>) => {
dispatch({ type: LIST_QUEUE_STATS_BEGIN });
try {
const response = await listQueueStats();
dispatch({
type: LIST_QUEUE_STATS_SUCCESS,
payload: response,
});
} catch (error) {
console.error("listQueueStatsAsync: ", error);
dispatch({
type: LIST_QUEUE_STATS_ERROR,
error: "Could not fetch queue stats",
});
}
};
}