mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
fix: credit & vendor reducer.
This commit is contained in:
@@ -25,12 +25,16 @@ import withVendorsCreditNotesActions from './withVendorsCreditNotesActions';
|
||||
import withSettings from '../../../Settings/withSettings';
|
||||
import withSettingsActions from '../../../Settings/withSettingsActions';
|
||||
|
||||
import withVendorActions from './withVendorActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Vendors Credit note table actions bar.
|
||||
*/
|
||||
function VendorsCreditNoteActionsBar({
|
||||
setVendorCreditsTableState,
|
||||
|
||||
// #withVendorsCreditNotes
|
||||
vendorCreditFilterRoles,
|
||||
|
||||
@@ -56,7 +60,7 @@ function VendorsCreditNoteActionsBar({
|
||||
|
||||
// Handle view tab change.
|
||||
const handleTabChange = (view) => {
|
||||
setVendorsCreditNoteTableState({ viewSlug: view ? view.slug : null });
|
||||
setVendorCreditsTableState({ viewSlug: view ? view.slug : null });
|
||||
};
|
||||
|
||||
// Handle click a refresh credit note.
|
||||
@@ -136,6 +140,7 @@ function VendorsCreditNoteActionsBar({
|
||||
|
||||
export default compose(
|
||||
withVendorsCreditNotesActions,
|
||||
withVendorActions,
|
||||
withSettingsActions,
|
||||
withVendorsCreditNotes(({ vendorsCreditNoteTableState }) => ({
|
||||
vendorCreditFilterRoles: vendorsCreditNoteTableState.filterRoles,
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
setVendorCreditTableState,
|
||||
resetVendorCreditTableState,
|
||||
} from '../../../../store/VendorCredit/vendorCredit.actions';
|
||||
|
||||
const mapDipatchToProps = (dispatch) => ({
|
||||
setVendorCreditsTableState: (queries) =>
|
||||
dispatch(setVendorCreditTableState(queries)),
|
||||
resetVendorCreditsTableState: () => dispatch(resetVendorCreditTableState()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDipatchToProps);
|
||||
@@ -1,14 +1,13 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
getVendorsCreditNoteTableStateFactory,
|
||||
isVendorsCreditNoteTableStateChangedFactory,
|
||||
} from '../../../../store/vendorsCreditNotes/vendorsCreditNotes.selector';
|
||||
getVendorCreditTableStateFactory,
|
||||
isVendorCreditTableStateChangedFactory,
|
||||
} from '../../../../store/VendorCredit/vendorCredit.selector';
|
||||
|
||||
export default (mapState) => {
|
||||
const getVendorsCreditNoteTableState =
|
||||
getVendorsCreditNoteTableStateFactory();
|
||||
const getVendorsCreditNoteTableState = getVendorCreditTableStateFactory();
|
||||
const isVendorsCreditNoteTableChanged =
|
||||
isVendorsCreditNoteTableStateChangedFactory();
|
||||
isVendorCreditTableStateChangedFactory();
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
setVendorsCreditNoteTableState,
|
||||
resetVendorsCreditNoteTableState,
|
||||
} from '../../../../store/vendorsCreditNotes/vendorsCreditNotes.actions';
|
||||
setVendorCreditTableState,
|
||||
resetVendorCreditTableState,
|
||||
} from '../../../../store/VendorCredit/vendorCredit.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setVendorsCreditNoteTableState: (state) =>
|
||||
dispatch(setVendorsCreditNoteTableState(state)),
|
||||
setVendorsCreditNoteTableState: (queries) =>
|
||||
dispatch(setVendorCreditTableState(queries)),
|
||||
resetVendorsCreditNoteTableState: () =>
|
||||
dispatch(resetVendorsCreditNoteTableState()),
|
||||
dispatch(resetVendorCreditTableState()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
getCreditNoteTableStateFactory,
|
||||
isCreditNoteTableStateChangedFactory,
|
||||
} from '../../../../store/CreditNotes/creditNotes.selector';
|
||||
getCreditNotesTableStateFactory,
|
||||
isCreditNotesTableStateChangedFactory,
|
||||
} from '../../../../store/CreditNote/creditNote.selector';
|
||||
|
||||
export default (mapState) => {
|
||||
const getCreditNoteTableState = getCreditNoteTableStateFactory();
|
||||
const isCreditNoteTableChanged = isCreditNoteTableStateChangedFactory();
|
||||
const getCreditNoteTableState = getCreditNotesTableStateFactory();
|
||||
const isCreditNoteTableChanged = isCreditNotesTableStateChangedFactory();
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
setCreditNotesTableState,
|
||||
resetCreditNotesTableState,
|
||||
} from '../../../../store/CreditNotes/creditNotes.actions';
|
||||
setCreditNoteTableState,
|
||||
resetCreditNoteTableState,
|
||||
} from '../../../../store/CreditNote/creditNote.actions';
|
||||
|
||||
const mapDipatchToProps = (dispatch) => ({
|
||||
setCreditNotesTableState: (queries) =>
|
||||
dispatch(setCreditNotesTableState(queries)),
|
||||
resetCreditNotesTableState: () => dispatch(resetCreditNotesTableState()),
|
||||
dispatch(setCreditNoteTableState(queries)),
|
||||
resetCreditNotesTableState: () => dispatch(resetCreditNoteTableState()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDipatchToProps);
|
||||
|
||||
@@ -88,7 +88,7 @@ export function useDeleteCreditNote(props) {
|
||||
});
|
||||
}
|
||||
|
||||
const transformInvoices = (res) => ({
|
||||
const transformCreditNotes = (res) => ({
|
||||
creditNotes: res.data.credit_notes,
|
||||
pagination: transformPagination(res.data.pagination),
|
||||
filterMeta: res.data.filter_meta,
|
||||
@@ -102,7 +102,7 @@ export function useCreditNotes(query, props) {
|
||||
[t.CREDIT_NOTES, query],
|
||||
{ method: 'get', url: 'sales/credit_notes', params: query },
|
||||
{
|
||||
select: transformInvoices,
|
||||
select: transformCreditNotes,
|
||||
defaultData: {
|
||||
creditNotes: [],
|
||||
pagination: {
|
||||
@@ -117,30 +117,6 @@ export function useCreditNotes(query, props) {
|
||||
);
|
||||
}
|
||||
|
||||
// export function useCreditNotes(query, props) {
|
||||
// return useRequestQuery(
|
||||
// [t.CREDIT_NOTES],
|
||||
// {
|
||||
// method: 'get',
|
||||
// url: 'sales/credit_notes',
|
||||
// params: query,
|
||||
// },
|
||||
// {
|
||||
// select: transformVendorCreditsResponse,
|
||||
// defaultData: {
|
||||
// credit_notes: {},
|
||||
// pagination: {
|
||||
// page: 1,
|
||||
// page_size: 12,
|
||||
// total: 0,
|
||||
// },
|
||||
// filterMeta: {},
|
||||
// },
|
||||
// ...props,
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
|
||||
/**
|
||||
* Retrieve credit note detail of the given id.
|
||||
* @param {number} id
|
||||
|
||||
@@ -102,7 +102,7 @@ const transformVendorCreditsResponse = (response) => ({
|
||||
*/
|
||||
export function useVendorCredits(query, props) {
|
||||
return useRequestQuery(
|
||||
[t.VENDOR_CREDITS],
|
||||
[t.VENDOR_CREDITS, query],
|
||||
{
|
||||
method: 'get',
|
||||
url: 'purchases/vendor-credit',
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import t from 'store/types';
|
||||
|
||||
export const setCreditNotesTableState = (queries) => {
|
||||
export const setCreditNoteTableState = (queries) => {
|
||||
return {
|
||||
type: t.CREDIT_NOTES_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetCreditNotesTableState = () => {
|
||||
export const resetCreditNoteTableState = () => {
|
||||
return {
|
||||
type: t.CREDIT_NOTES_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
export const setSelectedRowsItems = () => {};
|
||||
@@ -15,7 +15,7 @@ const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:creditNotes';
|
||||
const STORAGE_KEY = 'bigcapital:credit_notes';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
29
src/store/CreditNote/creditNote.selector.js
Normal file
29
src/store/CreditNote/creditNote.selector.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from 'store/selectors';
|
||||
import { createDeepEqualSelector } from 'utils';
|
||||
import { defaultTableQuery } from './creditNote.reducer';
|
||||
|
||||
const creditsTableStateSelector = (state) => state.creditNotes.tableState;
|
||||
|
||||
/**
|
||||
* Retrieve credit notes table state.
|
||||
*/
|
||||
export const getCreditNotesTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
creditsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve credit notes table state.
|
||||
*/
|
||||
export const isCreditNotesTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(creditsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
@@ -1,4 +1,4 @@
|
||||
export default {
|
||||
CREDIT_NOTES_TABLE_STATE_SET: 'CREDIT_NOTE/TABLE_STATE_SET',
|
||||
CREDIT_NOTES_TABLE_STATE_SET: 'CREDIT_NOTES/TABLE_STATE_SET',
|
||||
CREDIT_NOTES_TABLE_STATE_RESET: 'CREDIT_NOTE/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -1,29 +0,0 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from 'store/selectors';
|
||||
import { createDeepEqualSelector } from 'utils';
|
||||
import { defaultTableQuery } from './creditNotes.reducer';
|
||||
|
||||
const creditNotesTableStateSelector = (state) => state.creditNotes.tableState;
|
||||
|
||||
/**
|
||||
* Retrieve credit note table state.
|
||||
*/
|
||||
export const getCreditNoteTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
creditNotesTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve Credit note table state.
|
||||
*/
|
||||
export const isCreditNoteTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(creditNotesTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
@@ -15,7 +15,7 @@ const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:vendorsCreditNotes';
|
||||
const STORAGE_KEY = 'bigcapital:vendor_credits';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
@@ -24,7 +24,7 @@ const CONFIG = {
|
||||
};
|
||||
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('VENDORS_CREDIT_NOTES', defaultTableQuery),
|
||||
...createTableStateReducers('VENDOR_CREDITS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
16
src/store/VendorCredit/vendorCredit.actions.js
Normal file
16
src/store/VendorCredit/vendorCredit.actions.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import t from 'store/types';
|
||||
|
||||
export const setVendorCreditTableState = (queries) => {
|
||||
return {
|
||||
type: t.VENDOR_CREDITS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetVendorCreditTableState = () => {
|
||||
return {
|
||||
type: t.VENDOR_CREDITS_NOTES_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
|
||||
export const setSelectedRowsItems = () => {};
|
||||
31
src/store/VendorCredit/vendorCredit.selector.js
Normal file
31
src/store/VendorCredit/vendorCredit.selector.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from 'store/selectors';
|
||||
import { createDeepEqualSelector } from 'utils';
|
||||
import { defaultTableQuery } from './VendorCredit.reducer';
|
||||
|
||||
const vendorCreditsTableStateSelector = (state) => {
|
||||
return state.vendorCredit.tableState;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieve vendor credit table state.
|
||||
*/
|
||||
export const getVendorCreditTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
vendorCreditsTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve vendor credit table state.
|
||||
*/
|
||||
export const isVendorCreditTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(vendorCreditsTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
4
src/store/VendorCredit/vendorCredit.type.js
Normal file
4
src/store/VendorCredit/vendorCredit.type.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
VENDOR_CREDITS_TABLE_STATE_SET: 'VENDOR_CREDITS/TABLE_STATE_SET',
|
||||
VENDOR_CREDITS_NOTES_TABLE_STATE_RESET: 'VENDOR_CREDITS/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -31,9 +31,9 @@ import paymentMades from './PaymentMades/paymentMades.reducer';
|
||||
import organizations from './organizations/organizations.reducers';
|
||||
import subscriptions from './subscription/subscription.reducer';
|
||||
import inventoryAdjustments from './inventoryAdjustments/inventoryAdjustment.reducer';
|
||||
import creditNotes from './CreditNotes/creditNotes.reducer'
|
||||
import vendorsCreditNotes from './vendorsCreditNotes/vendorsCreditNotes.reducer'
|
||||
import plans from './plans/plans.reducer';
|
||||
import creditNotes from './CreditNote/creditNote.reducer';
|
||||
import vendorCredit from './VendorCredit/VendorCredit.reducer';
|
||||
|
||||
const appReducer = combineReducers({
|
||||
authentication,
|
||||
@@ -65,9 +65,9 @@ const appReducer = combineReducers({
|
||||
paymentReceives,
|
||||
paymentMades,
|
||||
inventoryAdjustments,
|
||||
plans,
|
||||
creditNotes,
|
||||
vendorsCreditNotes,
|
||||
plans
|
||||
vendorCredit,
|
||||
});
|
||||
|
||||
// Reset the state of a redux store
|
||||
@@ -75,7 +75,7 @@ const rootReducer = (state, action) => {
|
||||
if (action.type === types.RESET) {
|
||||
state = undefined;
|
||||
}
|
||||
return appReducer(state, action)
|
||||
}
|
||||
return appReducer(state, action);
|
||||
};
|
||||
|
||||
export default rootReducer;
|
||||
export default rootReducer;
|
||||
|
||||
@@ -28,8 +28,8 @@ import paymentMades from './PaymentMades/paymentMades.type';
|
||||
import organizations from './organizations/organizations.types';
|
||||
import subscription from './subscription/subscription.types';
|
||||
import inventoryAdjustments from './inventoryAdjustments/inventoryAdjustment.type';
|
||||
import creditNotes from './CreditNotes/creditNotes.type';
|
||||
import vendorsCreditNotes from './vendorsCreditNotes/vendorsCreditNotes.type';
|
||||
import creditNote from './CreditNote/creditNote.type';
|
||||
import vendorCredit from './VendorCredit/vendorCredit.type';
|
||||
import plans from './plans/plans.types';
|
||||
|
||||
export default {
|
||||
@@ -63,7 +63,7 @@ export default {
|
||||
...organizations,
|
||||
...subscription,
|
||||
...inventoryAdjustments,
|
||||
...creditNotes,
|
||||
...vendorsCreditNotes,
|
||||
...plans,
|
||||
...creditNote,
|
||||
...vendorCredit
|
||||
};
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
import t from 'store/types';
|
||||
|
||||
export const setVendorsCreditNoteTableState = (queries) => {
|
||||
return {
|
||||
type: t.VENDORS_CREDIT_NOTE_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetVendorsCreditNoteTableState = () => {
|
||||
return {
|
||||
type: t.VENDORS_CREDIT_NOTE_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { paginationLocationQuery } from 'store/selectors';
|
||||
import { createDeepEqualSelector } from 'utils';
|
||||
import { defaultTableQuery } from './vendorsCreditNotes.reducer';
|
||||
|
||||
const VendorsCreditNoteTableStateSelector = (state) =>
|
||||
state.vendorsCreditNotes.tableState;
|
||||
|
||||
export const getVendorsCreditNoteTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
VendorsCreditNoteTableStateSelector,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const isVendorsCreditNoteTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(VendorsCreditNoteTableStateSelector, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
export default {
|
||||
VENDORS_CREDIT_NOTE_TABLE_STATE_SET: 'VENDORS_CREDIT_NOTE/TABLES_STATE_SET',
|
||||
VENDORS_CREDIT_NOTE_TABLE_STATE_RESET:
|
||||
'VENDORS_CREDIT_NOTE/TABLE_STATE/RESET',
|
||||
};
|
||||
Reference in New Issue
Block a user