mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
Merge branch 'feature/itemCategore'
This commit is contained in:
47
client/src/store/itemCategories/itemsCategory.actions.js
Normal file
47
client/src/store/itemCategories/itemsCategory.actions.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const submitCategory = ({ form }) => {
|
||||
return dispatch =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post('item_categories', form)
|
||||
.then(response => {
|
||||
dispatch({ type: t.ITEMS_CATEGORY_LIST_SET });
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
const { errors } = data;
|
||||
|
||||
dispatch({ type: t.ITEMS_CATEGORY_LIST_SET });
|
||||
if (errors) {
|
||||
dispatch({ type: t.ITEMS_CATEGORY_LIST_SET, errors });
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const submitItemCategory = ({ form }) => {
|
||||
return dispatch => {
|
||||
return ApiService.post('item_categories', { ...form });
|
||||
};
|
||||
};
|
||||
|
||||
export const fetchCategory = () => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.get('item_categories')
|
||||
.then(response => {
|
||||
dispatch({
|
||||
type: t.ITEMS_CATEGORY_DATA_TABLE,
|
||||
data: response.data
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
6
client/src/store/itemCategories/itemsCategory.type.js
Normal file
6
client/src/store/itemCategories/itemsCategory.type.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
ITEMS_CATEGORY_LIST_SET: 'ITEMS_CATEGORY_LIST_SET',
|
||||
ITEMS_CATEGORY_DATA_TABLE: 'ITEMS_CATEGORY_DATA_TABLE',
|
||||
|
||||
};
|
||||
|
||||
27
client/src/store/itemCategories/itemsCateory.reducer.js
Normal file
27
client/src/store/itemCategories/itemsCateory.reducer.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
|
||||
const initialState = {
|
||||
categories: {},
|
||||
categoriesById: {}
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.ITEMS_CATEGORY_LIST_SET]: (state, action) => {
|
||||
const _categories = {};
|
||||
|
||||
action.categories.forEach(category => {
|
||||
_categories[category.id] = category;
|
||||
});
|
||||
state.categories = {
|
||||
...state.categories,
|
||||
..._categories
|
||||
};
|
||||
},
|
||||
[t.CATEGORY_SET]: (state, action) => {
|
||||
state.categoriesById[action.category.id] = action.category;
|
||||
}
|
||||
});
|
||||
export const getCategoryId = (state, id) => {
|
||||
return state.categories.categoriesById[id];
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import expenses from './expenses/expenses.reducer';
|
||||
import currencies from './currencies/currencies.reducer';
|
||||
import resources from './resources/resources.reducer';
|
||||
import financialStatements from './financialStatement/financialStatements.reducer';
|
||||
import itemCategories from './itemCategories/itemsCateory.reducer';
|
||||
|
||||
export default combineReducers({
|
||||
authentication,
|
||||
@@ -24,4 +25,5 @@ export default combineReducers({
|
||||
resources,
|
||||
financialStatements,
|
||||
items,
|
||||
});
|
||||
itemCategories
|
||||
});
|
||||
|
||||
@@ -10,7 +10,7 @@ import preferences from './preferences/preferences.types';
|
||||
import resources from './resources/resource.types';
|
||||
import users from './users/users.types';
|
||||
import financialStatements from './financialStatement/financialStatements.types';
|
||||
|
||||
import itemCategories from './itemCategories/itemsCategory.type';
|
||||
export default {
|
||||
...authentication,
|
||||
...accounts,
|
||||
@@ -24,4 +24,5 @@ export default {
|
||||
...resources,
|
||||
...users,
|
||||
...financialStatements,
|
||||
}
|
||||
...itemCategories
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user