Add createFilter function

This commit is contained in:
Alex Gleason 2020-04-25 19:04:47 -05:00
parent 7b02e1a823
commit 32a5a31591
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,10 @@ export const FILTERS_FETCH_REQUEST = 'FILTERS_FETCH_REQUEST';
export const FILTERS_FETCH_SUCCESS = 'FILTERS_FETCH_SUCCESS'; export const FILTERS_FETCH_SUCCESS = 'FILTERS_FETCH_SUCCESS';
export const FILTERS_FETCH_FAIL = 'FILTERS_FETCH_FAIL'; export const FILTERS_FETCH_FAIL = 'FILTERS_FETCH_FAIL';
export const FILTERS_CREATE_REQUEST = 'FILTERS_CREATE_REQUEST';
export const FILTERS_CREATE_SUCCESS = 'FILTERS_CREATE_SUCCESS';
export const FILTERS_CREATE_FAIL = 'FILTERS_CREATE_FAIL';
export const fetchFilters = () => (dispatch, getState) => { export const fetchFilters = () => (dispatch, getState) => {
if (!getState().get('me')) return; if (!getState().get('me')) return;
@ -26,3 +30,14 @@ export const fetchFilters = () => (dispatch, getState) => {
skipAlert: true, skipAlert: true,
})); }));
}; };
export function createFilter(params) {
return (dispatch, getState) => {
dispatch({ type: FILTERS_CREATE_REQUEST });
return api(getState).post('/api/v1/filters', params).then(response => {
dispatch({ type: FILTERS_CREATE_SUCCESS, filter: response.data });
}).catch(error => {
dispatch({ type: FILTERS_CREATE_FAIL, error });
});
};
}