1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-04 18:35:17 +02:00
flame/client/src/store/actions/app.ts

30 lines
778 B
TypeScript
Raw Normal View History

2021-05-10 19:02:16 +02:00
import axios from 'axios';
import { Dispatch } from 'redux';
import { ActionTypes } from './actionTypes';
import { App, AppResponse } from '../../interfaces/App';
export interface GetAppsAction<T> {
type: ActionTypes.getApps | ActionTypes.getAppsSuccess | ActionTypes.getAppsError,
payload: T
}
2021-05-10 19:02:16 +02:00
export const getApps = () => async (dispatch: Dispatch) => {
dispatch<GetAppsAction<undefined>>({
type: ActionTypes.getApps,
payload: undefined
});
2021-05-10 19:02:16 +02:00
try {
const res = await axios.get<AppResponse>('/api/apps');
2021-05-10 19:02:16 +02:00
dispatch<GetAppsAction<App[]>>({
type: ActionTypes.getAppsSuccess,
2021-05-10 19:02:16 +02:00
payload: res.data.data
})
} catch (err) {
dispatch<GetAppsAction<string>>({
type: ActionTypes.getAppsError,
2021-05-10 19:02:16 +02:00
payload: err.data.data
})
}
}