mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
WIP
This commit is contained in:
45
client/src/store/customViews/customViews.actions.js
Normal file
45
client/src/store/customViews/customViews.actions.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import ApiService from "services/ApiService";
|
||||
import t from 'store/types';
|
||||
|
||||
export const submitView = ({ form }) => {
|
||||
return (dispatch) => ApiService.post('views', form);
|
||||
};
|
||||
|
||||
export const editView = ({ id, form }) => {
|
||||
return (dispatch) => ApiService.post(`views/${id}`);
|
||||
};
|
||||
|
||||
export const deleteView = ({ id }) => {
|
||||
return (dispatch) => ApiService.delete(`views/${id}`);
|
||||
};
|
||||
|
||||
export const fetchView = ({ id }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get(`views/${id}`).then((response) => {
|
||||
dispatch({
|
||||
type: t.VIEW_META_SET,
|
||||
view: response.data.view,
|
||||
});
|
||||
resolve(response);
|
||||
}).catch(error => { reject(error); });
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchResourceViews = ({ resourceSlug }) => {
|
||||
return (dispatch) => new Promise((resolve, reject) => {
|
||||
ApiService.get('views', { query: { resource_name: resourceSlug } })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.RESOURCE_VIEWS_SET,
|
||||
resource: resourceSlug,
|
||||
views: response.data.views,
|
||||
});
|
||||
dispatch({
|
||||
type: t.VIEW_ITEMS_SET,
|
||||
views: response.data.views,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => { reject(error); });
|
||||
});
|
||||
};
|
||||
30
client/src/store/customViews/customViews.reducer.js
Normal file
30
client/src/store/customViews/customViews.reducer.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { createReducer } from "@reduxjs/toolkit";
|
||||
import t from 'store/types';
|
||||
|
||||
const initialState = {
|
||||
views: {},
|
||||
resourceViews: {
|
||||
'accounts': [],
|
||||
'expenses': [],
|
||||
},
|
||||
viewsMeta: {},
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.VIEW_META_SET]: (state, action) => {
|
||||
state.viewsMeta[action.view.id] = action.view;
|
||||
},
|
||||
|
||||
[t.RESOURCE_VIEWS_SET]: (state, action) => {
|
||||
state.resourceViews[action.resource] = action.views.map(v => v.id);
|
||||
},
|
||||
|
||||
[t.VIEW_ITEMS_SET]: (state, action) => {
|
||||
const _views = {};
|
||||
|
||||
action.views.forEach((view) => {
|
||||
_views[view.id] = view;
|
||||
});
|
||||
state.views = { ...state.views, ..._views };
|
||||
},
|
||||
})
|
||||
15
client/src/store/customViews/customViews.selectors.js
Normal file
15
client/src/store/customViews/customViews.selectors.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import {pickItemsFromIds} from 'store/selectors';
|
||||
|
||||
|
||||
export const getResourceViews = (state, resourceName) => {
|
||||
const resourceViewsIds = state.views.resourceViews[resourceName] || [];
|
||||
return pickItemsFromIds(state.views.views, resourceViewsIds);
|
||||
};
|
||||
|
||||
export const getViewMeta = (state, viewId) => {
|
||||
return state.views.viewsMeta[viewId] || {};
|
||||
};
|
||||
|
||||
export const getViewItem = (state, viewId) => {
|
||||
return state.views.views[viewId] || {};
|
||||
};
|
||||
6
client/src/store/customViews/customViews.types.js
Normal file
6
client/src/store/customViews/customViews.types.js
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
export default {
|
||||
VIEW_META_SET: 'VIEW_META_SET',
|
||||
VIEW_ITEMS_SET: 'VIEW_ITEMS_SET',
|
||||
RESOURCE_VIEWS_SET: 'RESOURCE_VIEWS_SET',
|
||||
};
|
||||
Reference in New Issue
Block a user