mirror of
https://github.com/pawelmalak/flame.git
synced 2026-02-28 09:23:12 +08:00
27 lines
766 B
TypeScript
27 lines
766 B
TypeScript
import axios from 'axios';
|
|
import { Dispatch } from 'redux';
|
|
import { ActionTypes } from './actionTypes';
|
|
import { Category, ApiResponse } from '../../interfaces';
|
|
|
|
export interface GetCategoriesAction<T> {
|
|
type: ActionTypes.getCategories | ActionTypes.getCategoriesSuccess | ActionTypes.getCategoriesError;
|
|
payload: T;
|
|
}
|
|
|
|
export const getCategories = () => async (dispatch: Dispatch) => {
|
|
dispatch<GetCategoriesAction<undefined>>({
|
|
type: ActionTypes.getCategories,
|
|
payload: undefined
|
|
})
|
|
|
|
try {
|
|
const res = await axios.get<ApiResponse<Category[]>>('/api/categories');
|
|
|
|
dispatch<GetCategoriesAction<Category[]>>({
|
|
type: ActionTypes.getCategoriesSuccess,
|
|
payload: res.data.data
|
|
})
|
|
} catch (err) {
|
|
console.log(err);
|
|
}
|
|
} |