WIP Version 0.0.1

This commit is contained in:
Ahmed Bouhuolia
2020-05-08 04:36:04 +02:00
parent bd7eb0eb76
commit 71cc561bb2
151 changed files with 1742 additions and 1081 deletions

View File

@@ -42,4 +42,22 @@ export const fetchResourceViews = ({ resourceSlug }) => {
})
.catch((error) => { reject(error); });
});
};
};
export const fetchViewResource = ({ id }) => {
return (dispatch) => new Promise((resolve, reject) => {
ApiService.get(`views/${id}/resource`).then((response) => {
dispatch({
type: t.RESOURCE_COLUMNS_SET,
columns: response.data.resource_columns,
resource_slug: response.data.resource_slug
});
dispatch({
type: t.RESOURCE_FIELDS_SET,
fields: response.data.resource_fields,
resource_slug: response.data.resource_slug,
});
resolve(response);
}).catch((error) => { reject(error); });
});
}

View File

@@ -1,5 +1,5 @@
import {pickItemsFromIds} from 'store/selectors';
import { getResourceField, getResourceColumn } from 'store/resources/resources.reducer';
export const getResourceViews = (state, resourceName) => {
const resourceViewsIds = state.views.resourceViews[resourceName] || [];
@@ -7,7 +7,16 @@ export const getResourceViews = (state, resourceName) => {
};
export const getViewMeta = (state, viewId) => {
return state.views.viewsMeta[viewId] || {};
const view = { ...state.views.viewsMeta[viewId] } || {};
if (view.columns) {
view.columns = view.columns.map((column) => {
return {
...getResourceColumn(state, column.field_id),
};
});
}
return view;
};
export const getViewItem = (state, viewId) => {

View File

@@ -6,7 +6,7 @@ const initialState = {
pageSubtitle: 'Hello World',
preferencesPageTitle: '',
dialogs: {},
topbarEditViewId: 1,
topbarEditViewId: null,
requestsLoading: 0,
};

View File

@@ -12,6 +12,12 @@ export const fetchItemCategories = () => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_LOADING,
});
dispatch({
type: t.ITEM_CATEGORIES_TABLE_LOADING,
payload: {
loading: true,
}
});
ApiService.get('item_categories')
.then((response) => {
dispatch({
@@ -21,6 +27,12 @@ export const fetchItemCategories = () => {
dispatch({
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
});
dispatch({
type: t.ITEM_CATEGORIES_TABLE_LOADING,
payload: {
loading: false,
}
});
resolve(response);
})
.catch((error) => {

View File

@@ -2,7 +2,8 @@ import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
const initialState = {
categories: {}
categories: {},
loading: false,
};
export default createReducer(initialState, {
@@ -18,11 +19,20 @@ export default createReducer(initialState, {
};
},
[t.ITEM_CATEGORIES_TABLE_SET]: (state, action) => {
},
[t.CATEGORY_DELETE]: (state, action) => {
if (typeof state.categories[action.id] !== 'undefined') {
delete state.categories[action.id];
}
}
},
[t.ITEM_CATEGORIES_TABLE_LOADING]: (state, action ) => {
const { loading } = action.payload;
state.loading = !!loading;
},
});
export const getCategoryId = (state, id) => {

View File

@@ -2,6 +2,5 @@ export default {
ITEMS_CATEGORY_LIST_SET: 'ITEMS_CATEGORY_LIST_SET',
ITEMS_CATEGORY_DATA_TABLE: 'ITEMS_CATEGORY_DATA_TABLE',
CATEGORY_DELETE: 'CATEGORY_DELETE',
CLEAR_CATEGORY_FORM_ERRORS: 'CLEAR_CATEGORY_FORM_ERRORS',
CATEGORY_COUNTER:'CATEGORY_COUNTER'
ITEM_CATEGORIES_TABLE_LOADING: 'ITEM_CATEGORIES_TABLE_LOADING'
};

View File

@@ -2,7 +2,8 @@ import t from 'store/types';
import { createReducer } from '@reduxjs/toolkit';
const initialState = {
categories: {}
categories: {},
loading: false,
};
export default createReducer(initialState, {

View File

@@ -92,6 +92,10 @@ const itemsReducer = createReducer(initialState, {
const { loading } = action.payload;
state.loading = !!loading;
},
[t.ITEMS_SET_CURRENT_VIEW]: (state, action) => {
state.currentViewId = action.currentViewId;
},
});
export default createTableQueryReducers('items', itemsReducer);

View File

@@ -11,4 +11,5 @@ export default {
ITEMS_TABLE_QUERIES_ADD: 'ITEMS_TABLE_QUERIES_ADD',
ITEMS_TABLE_LOADING: 'ITEMS_TABLE_LOADING',
}
ITEMS_SET_CURRENT_VIEW: 'ITEMS_SET_CURRENT_VIEW',
};

View File

@@ -5,7 +5,12 @@ export const makeJournalEntries = ({ form }) => {
return (dispatch) => new Promise((resolve, reject) => {
ApiService.post('accounting/make-journal-entries', form).then((response) => {
resolve(response);
}).catch((error) => { reject(error); });
}).catch((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
};
@@ -28,7 +33,12 @@ export const editManualJournal = ({ form, id }) => {
return (dispatch) => new Promise((resolve, reject) => {
ApiService.post(`accounting/manual-journals/${id}`, form).then((response) => {
resolve(response);
}).catch((error) => { reject(error); });
}).catch((error) => {
const { response } = error;
const { data } = response;
reject(data?.errors);
});
});
};

View File

@@ -7,6 +7,21 @@ const initialState = {
columns: {},
resourceFields: {},
resourceColumns: {},
metadata: {
'accounts': {
label: 'Accounts',
baseRoute: '/dashboard/accounts',
},
'items': {
label: 'Items',
baseRoute: '/dashboard/items',
},
'manual_journals': {
label: 'Journals',
baseRoute: '/dashboard/accounting/manual-journals',
}
}
};
export default createReducer(initialState, {
@@ -41,6 +56,7 @@ export default createReducer(initialState, {
* Retrieve resource fields of the given resource slug.
* @param {Object} state
* @param {String} resourceSlug
* @return {Array}
*/
export const getResourceFields = (state, resourceSlug) => {
const resourceIds = state.resources.resourceFields[resourceSlug];
@@ -52,6 +68,7 @@ export const getResourceFields = (state, resourceSlug) => {
* Retrieve resource columns of the given resource slug.
* @param {State} state
* @param {String} resourceSlug -
* @return {Array}
*/
export const getResourceColumns = (state, resourceSlug) => {
const resourceIds = state.resources.resourceColumns[resourceSlug];
@@ -75,4 +92,8 @@ export const getResourceField = (state, fieldId) => {
*/
export const getResourceColumn = (state, columnId) => {
return state.resources.columns[columnId];
};
export const getResourceMetadata = (state, resourceSlug) => {
return state.resources.metadata[resourceSlug];
};