github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/actions/serversActions.ts (about) 1 import { Dispatch } from "redux"; 2 import { listServers, ListServersResponse } from "../api"; 3 import { toErrorString, toErrorStringWithHttpStatus } from "../utils"; 4 5 // List of server related action types. 6 export const LIST_SERVERS_BEGIN = "LIST_SERVERS_BEGIN"; 7 export const LIST_SERVERS_SUCCESS = "LIST_SERVERS_SUCCESS"; 8 export const LIST_SERVERS_ERROR = "LIST_SERVERS_ERROR"; 9 10 interface ListServersBeginAction { 11 type: typeof LIST_SERVERS_BEGIN; 12 } 13 interface ListServersSuccessAction { 14 type: typeof LIST_SERVERS_SUCCESS; 15 payload: ListServersResponse; 16 } 17 interface ListServersErrorAction { 18 type: typeof LIST_SERVERS_ERROR; 19 error: string; // error description 20 } 21 22 // Union of all server related actions. 23 export type ServersActionTypes = 24 | ListServersBeginAction 25 | ListServersSuccessAction 26 | ListServersErrorAction; 27 28 export function listServersAsync() { 29 return async (dispatch: Dispatch<ServersActionTypes>) => { 30 dispatch({ type: LIST_SERVERS_BEGIN }); 31 try { 32 const response = await listServers(); 33 dispatch({ 34 type: LIST_SERVERS_SUCCESS, 35 payload: response, 36 }); 37 } catch (error) { 38 console.error(`listServersAsync: ${toErrorStringWithHttpStatus(error)}`); 39 dispatch({ 40 type: LIST_SERVERS_ERROR, 41 error: toErrorString(error), 42 }); 43 } 44 }; 45 }