mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
refactoring: expenses landing list.
refactoring: customers landing list. refactoring: vendors landing list. refactoring: manual journals landing list.
This commit is contained in:
@@ -1,173 +1,8 @@
|
||||
import { omit, flatten } from 'lodash';
|
||||
import ApiService from 'services/ApiService';
|
||||
import t from 'store/types';
|
||||
|
||||
export const makeJournalEntries = ({ form }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post('manual-journals', form)
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchManualJournal = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.get(`manual-journals/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_SET,
|
||||
payload: {
|
||||
id,
|
||||
manualJournal: response.data.manual_journal,
|
||||
},
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const editManualJournal = ({ form, id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post(`manual-journals/${id}`, form)
|
||||
.then((response) => {
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
const { response } = error;
|
||||
const { data } = response;
|
||||
|
||||
reject(data?.errors);
|
||||
});
|
||||
});
|
||||
};
|
||||
export const deleteManualJournal = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.delete(`manual-journals/${id}`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_REMOVE,
|
||||
payload: { id },
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteBulkManualJournals = ({ ids }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.delete('manual-journals', { params: { ids } })
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_BULK_DELETE,
|
||||
payload: { ids },
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error.response.data.errors || []);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const publishManualJournal = ({ id }) => {
|
||||
return (dispatch) =>
|
||||
new Promise((resolve, reject) => {
|
||||
ApiService.post(`manual-journals/${id}/publish`)
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNAL_PUBLISH,
|
||||
payload: { id },
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const fetchManualJournalsTable = ({ query } = {}) => {
|
||||
return (dispatch, getState) =>
|
||||
new Promise((resolve, reject) => {
|
||||
let pageQuery = getState().manualJournals.tableQuery;
|
||||
|
||||
if (pageQuery.filter_roles) {
|
||||
pageQuery = {
|
||||
...omit(pageQuery, ['filter_roles']),
|
||||
stringified_filter_roles:
|
||||
JSON.stringify(pageQuery.filter_roles) || '',
|
||||
};
|
||||
}
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_TABLE_LOADING,
|
||||
loading: true,
|
||||
});
|
||||
ApiService.get('manual-journals', {
|
||||
params: { ...pageQuery, ...query },
|
||||
})
|
||||
.then((response) => {
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_PAGE_SET,
|
||||
payload: {
|
||||
manualJournals: response.data.manual_journals,
|
||||
customViewId:
|
||||
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||
pagination: response.data.pagination,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_ITEMS_SET,
|
||||
manual_journals: [
|
||||
...response.data.manual_journals.map((manualJournal) => ({
|
||||
...manualJournal,
|
||||
entries: manualJournal.entries.map((entry) => ({
|
||||
...omit(entry, ['account']),
|
||||
})),
|
||||
})),
|
||||
],
|
||||
});
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_PAGINATION_SET,
|
||||
payload: {
|
||||
pagination: response.data.pagination,
|
||||
customViewId:
|
||||
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||
},
|
||||
});
|
||||
dispatch({
|
||||
type: t.ACCOUNTS_ITEMS_SET,
|
||||
accounts: flatten(
|
||||
response.data.manual_journals?.map((journal) =>
|
||||
journal?.entries.map((entry) => entry.account),
|
||||
),
|
||||
),
|
||||
});
|
||||
dispatch({
|
||||
type: t.MANUAL_JOURNALS_TABLE_LOADING,
|
||||
loading: false,
|
||||
});
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
export const setManualJournalsTableState = (queries) => {
|
||||
return {
|
||||
type: t.MANUAL_JOURNALS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,107 +1,15 @@
|
||||
import t from 'store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { omit } from 'lodash';
|
||||
import {
|
||||
journalNumberChangedReducer,
|
||||
viewPaginationSetReducer,
|
||||
createTableQueryReducers,
|
||||
} from 'store/journalNumber.reducer';
|
||||
createTableStateReducers,
|
||||
} from 'store/tableState.reducer';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
views: {},
|
||||
loading: false,
|
||||
currentViewId: -1,
|
||||
tableQuery: {
|
||||
page_size: 12,
|
||||
page: 1,
|
||||
tableState: {
|
||||
pageSize: 12,
|
||||
pageIndex: 0,
|
||||
},
|
||||
paginationMeta: {
|
||||
total: 0,
|
||||
},
|
||||
journalNumberChanged: false,
|
||||
};
|
||||
|
||||
const defaultJournal = {
|
||||
entries: [],
|
||||
};
|
||||
|
||||
export default createReducer(initialState, {
|
||||
[t.MANUAL_JOURNAL_SET]: (state, action) => {
|
||||
const { id, manualJournal } = action.payload;
|
||||
state.items[id] = { ...defaultJournal, ...manualJournal };
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNAL_PUBLISH]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
const item = state.items[id] || {};
|
||||
|
||||
state.items[id] = { ...item, status: 1 };
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_ITEMS_SET]: (state, action) => {
|
||||
const _manual_journals = {};
|
||||
|
||||
action.manual_journals.forEach((manual_journal) => {
|
||||
_manual_journals[manual_journal.id] = {
|
||||
...defaultJournal,
|
||||
...manual_journal,
|
||||
};
|
||||
});
|
||||
state.items = {
|
||||
...state.items,
|
||||
..._manual_journals,
|
||||
};
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_PAGE_SET]: (state, action) => {
|
||||
const { customViewId, manualJournals, pagination } = action.payload;
|
||||
|
||||
const viewId = customViewId || -1;
|
||||
const view = state.views[viewId] || {};
|
||||
|
||||
state.views[viewId] = {
|
||||
...view,
|
||||
pages: {
|
||||
...(state.views?.[viewId]?.pages || {}),
|
||||
[pagination.page]: {
|
||||
ids: manualJournals.map((i) => i.id),
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_TABLE_LOADING]: (state, action) => {
|
||||
state.loading = action.loading;
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_SET_CURRENT_VIEW]: (state, action) => {
|
||||
const { currentViewId } = action.payload;
|
||||
state.currentViewId = currentViewId;
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNAL_REMOVE]: (state, action) => {
|
||||
const { id } = action.payload;
|
||||
state.items = omit(state.items, [id]);
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNALS_BULK_DELETE]: (state, action) => {
|
||||
const { ids } = action.payload;
|
||||
const items = { ...state.items };
|
||||
|
||||
ids.forEach((id) => {
|
||||
if (typeof items[id] !== 'undefined') {
|
||||
delete items[id];
|
||||
}
|
||||
});
|
||||
state.items = items;
|
||||
},
|
||||
|
||||
...viewPaginationSetReducer(t.MANUAL_JOURNALS_PAGINATION_SET),
|
||||
...journalNumberChangedReducer(t.MANUAL_JOURNAL_NUMBER_CHANGED),
|
||||
...createTableQueryReducers('MANUAL_JOURNALS'),
|
||||
});
|
||||
|
||||
export const getManualJournal = (state, id) => {
|
||||
return state.manualJournals.items[id];
|
||||
};
|
||||
...createTableStateReducers('MANUAL_JOURNALS'),
|
||||
});
|
||||
@@ -1,71 +1,17 @@
|
||||
import { createSelector } from 'reselect';
|
||||
import {
|
||||
pickItemsFromIds,
|
||||
paginationLocationQuery,
|
||||
defaultPaginationMeta,
|
||||
} from 'store/selectors';
|
||||
import { paginationLocationQuery } from 'store/selectors';
|
||||
import { createDeepEqualSelector } from 'utils';
|
||||
|
||||
const manualJournalsCurrentViewIdSelector = (state) =>
|
||||
state.manualJournals.currentViewId;
|
||||
const manualJournalsTableState = (state) => state.manualJournals.tableState;
|
||||
|
||||
const manualJournalsPageSelector = (state) => {
|
||||
const viewId = state.manualJournals.currentViewId;
|
||||
const currentView = state.manualJournals.views?.[viewId];
|
||||
const currentPageId = currentView?.paginationMeta?.page;
|
||||
|
||||
return currentView?.pages?.[currentPageId];
|
||||
};
|
||||
|
||||
const manualJournalsPaginationSelector = (state, props) => {
|
||||
const viewId = state.manualJournals.currentViewId;
|
||||
return state.manualJournals.views?.[viewId];
|
||||
};
|
||||
|
||||
const manualJournalsTableQuery = (state) => state.manualJournals.tableQuery;
|
||||
const manualJournalsDataSelector = (state) => state.manualJournals.items;
|
||||
const manualJournalByIdSelector = (state, props) => state.manualJournals.items[props.manualJournalId];
|
||||
|
||||
// Retrieve manual jounral current page results.
|
||||
export const getManualJournalsItems = createSelector(
|
||||
manualJournalsPageSelector,
|
||||
manualJournalsDataSelector,
|
||||
(manualJournalsPage, manualJournalsItems) => {
|
||||
return typeof manualJournalsPage === 'object'
|
||||
? pickItemsFromIds(manualJournalsItems, manualJournalsPage.ids) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
// Retrieve manual journals pagination meta.
|
||||
export const getManualJournalsPagination = createSelector(
|
||||
manualJournalsPaginationSelector,
|
||||
(manualJournalsPage) => {
|
||||
return {
|
||||
...defaultPaginationMeta(),
|
||||
...(manualJournalsPage?.paginationMeta || {}),
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
// Retrieve manual jouranls table query.
|
||||
export const getManualJournalsTableQuery = createSelector(
|
||||
paginationLocationQuery,
|
||||
manualJournalsTableQuery,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
// Retrieve manual journals current view id.
|
||||
export const getManualJournalsCurrentViewIdFactory = () =>
|
||||
createSelector(manualJournalsCurrentViewIdSelector, (currentViewId) => {
|
||||
return currentViewId;
|
||||
});
|
||||
|
||||
export const getManualJournalByIdFactory = () =>
|
||||
createSelector(manualJournalByIdSelector, (manualJournal) => {
|
||||
return manualJournal;
|
||||
});
|
||||
// Retrieve manual jouranls table state.
|
||||
export const getManualJournalsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
manualJournalsTableState,
|
||||
(locationQuery, tableQuery) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableQuery,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
export default {
|
||||
MAKE_JOURNAL_ENTRIES: 'MAKE_JOURNAL_ENTRIES',
|
||||
MANUAL_JOURNAL_SET: 'MANUAL_JOURNAL_SET',
|
||||
|
||||
MANUAL_JOURNALS_TABLE_LOADING: 'MANUAL_JOURNALS_TABLE_LOADING',
|
||||
MANUAL_JOURNALS_PAGE_SET: 'MANUAL_JOURNALS_PAGE_SET',
|
||||
MANUAL_JOURNALS_ITEMS_SET: 'MANUAL_JOURNALS_ITEMS_SET',
|
||||
MANUAL_JOURNALS_SET_CURRENT_VIEW: 'MANUAL_JOURNALS_SET_CURRENT_VIEW',
|
||||
MANUAL_JOURNALS_TABLE_QUERIES_ADD: 'MANUAL_JOURNALS/TABLE_QUERIES_ADD',
|
||||
MANUAL_JOURNAL_REMOVE: 'MANUAL_JOURNAL_REMOVE',
|
||||
|
||||
MANUAL_JOURNAL_PUBLISH: 'MANUAL_JOURNAL_PUBLISH',
|
||||
MANUAL_JOURNALS_BULK_DELETE: 'MANUAL_JOURNALS_BULK_DELETE',
|
||||
MANUAL_JOURNALS_PAGINATION_SET: 'MANUAL_JOURNALS_PAGINATION_SET',
|
||||
|
||||
MANUAL_JOURNAL_NUMBER_CHANGED: 'MANUAL_JOURNAL_NUMBER_CHANGED'
|
||||
MANUAL_JOURNALS_TABLE_STATE_SET: 'MANUAL_JOURNALS/TABLE_STATE_SET',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user