mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-08-24 14:48:42 +08:00
Fetch servers info and show in ServersTable
This commit is contained in:
44
ui/src/actions/serversActions.ts
Normal file
44
ui/src/actions/serversActions.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { Dispatch } from "redux";
|
||||
import { listServers, ListServersResponse } from "../api";
|
||||
|
||||
// List of server related action types.
|
||||
export const LIST_SERVERS_BEGIN = "LIST_SERVERS_BEGIN";
|
||||
export const LIST_SERVERS_SUCCESS = "LIST_SERVERS_SUCCESS";
|
||||
export const LIST_SERVERS_ERROR = "LIST_SERVERS_ERROR";
|
||||
|
||||
interface ListServersBeginAction {
|
||||
type: typeof LIST_SERVERS_BEGIN;
|
||||
}
|
||||
interface ListServersSuccessAction {
|
||||
type: typeof LIST_SERVERS_SUCCESS;
|
||||
payload: ListServersResponse;
|
||||
}
|
||||
interface ListServersErrorAction {
|
||||
type: typeof LIST_SERVERS_ERROR;
|
||||
error: string; // error description
|
||||
}
|
||||
|
||||
// Union of all server related actions.
|
||||
export type ServersActionTypes =
|
||||
| ListServersBeginAction
|
||||
| ListServersSuccessAction
|
||||
| ListServersErrorAction;
|
||||
|
||||
export function listServersAsync() {
|
||||
return async (dispatch: Dispatch<ServersActionTypes>) => {
|
||||
dispatch({ type: LIST_SERVERS_BEGIN });
|
||||
try {
|
||||
const response = await listServers();
|
||||
dispatch({
|
||||
type: LIST_SERVERS_SUCCESS,
|
||||
payload: response,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("listServersAsync: ", error);
|
||||
dispatch({
|
||||
type: LIST_SERVERS_ERROR,
|
||||
error: "Could not retrieve servers info",
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user