Config With Seacrh

This commit is contained in:
elforjani3
2020-04-11 15:00:22 +02:00
parent e8079dbde3
commit 940418c4e0
12 changed files with 284 additions and 149 deletions

View File

@@ -2,7 +2,7 @@ import ApiService from 'services/ApiService';
import t from 'store/types';
export const submitItemCategory = ({ form }) => {
return dispatch => {
return (dispatch) => {
return ApiService.post('item_categories', { ...form });
};
};
@@ -11,53 +11,53 @@ export const fetchItemCategories = () => {
return (dispatch, getState) =>
new Promise((resolve, reject) => {
ApiService.get('item_categories')
.then(response => {
.then((response) => {
dispatch({
type: t.ITEMS_CATEGORY_LIST_SET,
categories: response.data.categories
categories: response.data.categories,
});
resolve(response);
})
.catch(error => {
.catch((error) => {
reject(error);
});
});
};
export const editItemCategory = (id, form) => {
return dispatch =>
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.post(`item_categories/${id}`, form)
.then(response => {
.then((response) => {
dispatch({ type: t.CLEAR_CATEGORY_FORM_ERRORS });
resolve(response);
})
.catch(error => {
.catch((error) => {
const { response } = error;
const { data } = response;
const { errors } = data;
dispatch({ type: t.CLEAR_CATEGORY_FORM_ERRORS });
if (errors) {
dispatch({ type: t.CATEGORY_FORM_ERRORS, errors });
dispatch({ type: t.CLEAR_CATEGORY_FORM_ERRORS, errors });
}
reject(error);
});
});
};
export const deleteItemCategory = id => {
return dispatch =>
export const deleteItemCategory = (id) => {
return (dispatch) =>
new Promise((resolve, reject) => {
ApiService.delete(`item_categories/${id}`)
.then(response => {
.then((response) => {
dispatch({
type: t.CATEGORY_DELETE,
id
id,
});
resolve(response);
})
.catch(error => {
.catch((error) => {
reject(error);
});
});

View File

@@ -14,6 +14,7 @@ import financialStatements from './financialStatement/financialStatements.reduce
import itemCategories from './itemCategories/itemsCategory.reducer';
import settings from './settings/settings.reducer';
import manualJournals from './manualJournals/manualJournals.reducers';
import search from './search/search.reducer';
export default combineReducers({
authentication,
@@ -30,4 +31,5 @@ export default combineReducers({
items,
itemCategories,
settings,
search,
});

View File

@@ -0,0 +1,8 @@
import t from 'store/types';
export function generalSearch(name, result) {
return {
type: t.SEARCH_SUCCESS,
result,
};
}

View File

@@ -0,0 +1,33 @@
import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
const initialState = {
searches: {},
searchTitle: 'Title',
isOpen: false,
};
export default createReducer(initialState, {
[t.SEARCH_SUCCESS]: (state, action) => {
const _result = {};
action.searches.forEach((search) => {
_result[search.id] = search;
});
state.searches = {
...state.searches,
..._result,
};
},
});
// return state = action.result;
// if (typeof state === 'undefined') {
// return initialState;
// }
// state.search[action.name] = {
// isOpen: true,
// payload: action.payload || {},
// };

View File

@@ -0,0 +1,5 @@
export default {
SEARCH_SUCCESS: 'SEARCH_SUCCESS',
SEARCH_FAILURE: 'SEARCH_FAILURE',
SEARCH_REQUEST: 'SEARCH_REQUEST',
};

View File

@@ -1,6 +1,6 @@
import authentication from './authentication/authentication.types';
import accounts from './accounts/accounts.types';
import accounting from './manualJournals/manualJournals.types'
import accounting from './manualJournals/manualJournals.types';
import currencies from './currencies/currencies.types';
import customFields from './customFields/customFields.types';
import customViews from './customViews/customViews.types';
@@ -13,7 +13,7 @@ import users from './users/users.types';
import financialStatements from './financialStatement/financialStatements.types';
import itemCategories from './itemCategories/itemsCategory.type';
import settings from './settings/settings.type';
import search from './search/search.type';
export default {
...authentication,
...accounts,
@@ -30,4 +30,5 @@ export default {
...itemCategories,
...settings,
...accounting,
...search,
};